Skip to content

[CapMan self-serve] Don't emit Sentry warnings for throttled queries to Snuba #75879

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

Merged
merged 1 commit into from
Aug 15, 2024
Merged
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
25 changes: 10 additions & 15 deletions src/sentry/utils/snuba.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import functools
import logging
import os
import random
import re
import time
from collections import namedtuple
Expand Down Expand Up @@ -1043,6 +1042,15 @@ def _apply_cache_and_build_results(
return [result[1] for result in results]


def _is_rejected_query(body: Any) -> bool:
return (
"quota_allowance" in body
and "summary" in body["quota_allowance"]
and "rejected_by" in body["quota_allowance"]["summary"]
and body["quota_allowance"]["summary"]["rejected_by"] is not None
)


def _bulk_snuba_query(snuba_requests: Sequence[SnubaRequest]) -> ResultSet:
snuba_requests_list = list(snuba_requests)

Expand Down Expand Up @@ -1099,7 +1107,7 @@ def _bulk_snuba_query(snuba_requests: Sequence[SnubaRequest]) -> ResultSet:
raise UnexpectedResponseError(f"Could not decode JSON response: {response.data!r}")

allocation_policy_prefix = "allocation_policy."
if "quota_allowance" in body and "summary" in body["quota_allowance"]:
if _is_rejected_query(body):
quota_allowance_summary = body["quota_allowance"]["summary"]
span.set_tag(
f"{allocation_policy_prefix}threads_used",
Expand All @@ -1118,19 +1126,6 @@ def _bulk_snuba_query(snuba_requests: Sequence[SnubaRequest]) -> ResultSet:
span.set_tag(k, v)
sentry_sdk.set_tag(k, v)

if (
"throttled_by" in quota_allowance_summary
and quota_allowance_summary["throttled_by"]
):
metrics.incr("snuba.client.query.throttle", tags={"referrer": referrer})
if random.random() < 0.01:
logger.warning(
"Warning: Query is throttled", extra={"response.data": response.data}
)
sentry_sdk.capture_message(
f"Warning: Query from referrer {referrer} is throttled", level="warning"
)
Comment on lines -1121 to -1132
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if, instead of deleting this, we made it configurable-by-referrer and default off?

So if there is a product team interested in monitoring throttles we can quickly turn on warnings for their referrer, but we don't annoy certain people by filling the issue dashboard with throttle warnings that won't be dealt with.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good idea but knowing the scope (time and efforts) will be crucial. The configurability based on the referrer sounds good as it won't overpopulate the sentry dashboard. But my request is to take this suggestion as a follow-up in addition to the larger change @volokluev and @xurui-c were discussing. For now, I vote to merge the PR and begin scoping the improvements.


if response.status != 200:
_log_request_query(snuba_requests_list[index].request)
metrics.incr(
Expand Down
Loading