mock-outcomes 1.9 KB

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