Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(quota): Count span only once when quota is defined for two categories #4258

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions tests/integration/test_spans.py
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,62 @@ def summarize_outcomes():
outcomes_consumer.assert_empty()


def test_span_counts_once(
mini_sentry,
relay_with_processing,
spans_consumer,
metrics_consumer,
outcomes_consumer,
redis_client,
):
"""A single span only counts towards a quota once, even if it is defined for two categories"""
relay = relay_with_processing(options=TEST_CONFIG)
project_id = 42
project_config = mini_sentry.add_full_project_config(project_id)
# Span metrics won't be extracted without a supported transactionMetrics config.
# Without extraction, the span is treated as `Span`, not `SpanIndexed`.
project_config["config"]["transactionMetrics"] = {
"version": TRANSACTION_EXTRACT_MIN_SUPPORTED_VERSION
}
project_config["config"]["features"] = [
"projects:span-metrics-extraction",
"organizations:indexed-spans-extraction",
]
quota_id = uuid.uuid4()
project_config["config"]["quotas"] = [
{
"categories": ["span_indexed", "span"],
"limit": 1000,
"window": int(datetime.now(UTC).timestamp()),
"id": quota_id,
"reasonCode": "my_rate_limit",
},
]

redis_key = f"quota:{quota_id}{{1}}:1"

spans_consumer = spans_consumer()
metrics_consumer = metrics_consumer()
outcomes_consumer = outcomes_consumer()

start = datetime.now(timezone.utc)
end = start + timedelta(seconds=1)

event = make_transaction({"event_id": "cbf6960622e14a45abc1f03b2055b186"})
end = datetime.now(timezone.utc) - timedelta(seconds=1)
duration = timedelta(milliseconds=500)
start = end - duration

assert redis_client.get(redis_key) is None

# We should be able to send one event:
relay.send_event(project_id, event)
spans = spans_consumer.get_spans(n=1, timeout=2)

assert redis_client.get(redis_key) == b"1"
assert len(spans) == 1


def test_rate_limit_spans_in_envelope(
mini_sentry,
relay_with_processing,
Expand Down
Loading