mock-outcomes 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env python
  2. from sentry.runner import configure
  3. configure()
  4. from datetime import datetime, timedelta
  5. import requests
  6. from django.conf import settings
  7. from sentry.constants import DataCategory
  8. from sentry.utils import json
  9. from sentry.utils.outcomes import Outcome
  10. # import random
  11. def store_outcomes(outcome, num_times=1):
  12. outcomes = []
  13. for _ in range(num_times):
  14. outcome_copy = outcome.copy()
  15. outcome_copy["timestamp"] = outcome_copy["timestamp"].strftime("%Y-%m-%dT%H:%M:%S.%fZ")
  16. outcomes.append(outcome_copy)
  17. assert (
  18. requests.post(
  19. settings.SENTRY_SNUBA + "/tests/outcomes/insert", data=json.dumps(outcomes)
  20. ).status_code
  21. == 200
  22. )
  23. def generate_outcomes():
  24. for i in range(0, 180):
  25. for outcome in [
  26. Outcome.RATE_LIMITED,
  27. Outcome.INVALID,
  28. Outcome.ACCEPTED,
  29. Outcome.FILTERED,
  30. ]:
  31. # print(datetime.now() - timedelta(hours=1840))
  32. print(i)
  33. for category in [
  34. DataCategory.ERROR,
  35. DataCategory.DEFAULT,
  36. DataCategory.TRANSACTION,
  37. DataCategory.ATTACHMENT,
  38. ]:
  39. attachments_multiplier = 1000 if category == DataCategory.ATTACHMENT else 1
  40. store_outcomes(
  41. {
  42. "org_id": 1,
  43. "timestamp": datetime.now() - timedelta(hours=i),
  44. "project_id": 1,
  45. "outcome": outcome,
  46. "reason": "none",
  47. "category": category,
  48. "quantity": 100 * attachments_multiplier * 500,
  49. },
  50. 1,
  51. )
  52. def drop_outcomes():
  53. assert requests.post(settings.SENTRY_SNUBA + "/tests/outcomes/drop").status_code == 200
  54. if __name__ == "__main__":
  55. generate_outcomes()