1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- #!/usr/bin/env python
- from sentry.runner import configure
- configure()
- from datetime import datetime, timedelta
- import requests
- from django.conf import settings
- from sentry.constants import DataCategory
- from sentry.utils import json
- from sentry.utils.outcomes import Outcome
- # import random
- def store_outcomes(outcome, num_times=1):
- outcomes = []
- for _ in range(num_times):
- outcome_copy = outcome.copy()
- outcome_copy["timestamp"] = outcome_copy["timestamp"].strftime("%Y-%m-%dT%H:%M:%S.%fZ")
- outcomes.append(outcome_copy)
- assert (
- requests.post(
- settings.SENTRY_SNUBA + "/tests/outcomes/insert", data=json.dumps(outcomes)
- ).status_code
- == 200
- )
- def generate_outcomes():
- for i in range(0, 180):
- for outcome in [
- Outcome.RATE_LIMITED,
- Outcome.INVALID,
- Outcome.ACCEPTED,
- Outcome.FILTERED,
- ]:
- # print(datetime.now() - timedelta(hours=1840))
- print(i)
- for category in [
- DataCategory.ERROR,
- DataCategory.DEFAULT,
- DataCategory.TRANSACTION,
- DataCategory.ATTACHMENT,
- ]:
- attachments_multiplier = 1000 if category == DataCategory.ATTACHMENT else 1
- store_outcomes(
- {
- "org_id": 1,
- "timestamp": datetime.now() - timedelta(hours=i),
- "project_id": 1,
- "outcome": outcome,
- "reason": "none",
- "category": category,
- "quantity": 100 * attachments_multiplier * 500,
- },
- 1,
- )
- def drop_outcomes():
- assert requests.post(settings.SENTRY_SNUBA + "/tests/outcomes/drop").status_code == 200
- if __name__ == "__main__":
- generate_outcomes()
|