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 click
  6. import requests
  7. from django.conf import settings
  8. from sentry.constants import DataCategory
  9. from sentry.utils import json
  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=json.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()