-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat(seer): Suppress re-triage of skipped issues in night shift #114915
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
Open
trevor-e
wants to merge
4
commits into
master
Choose a base branch
from
telkins/night-shift-skip-cache
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b2f2dcd
feat(seer): Suppress re-triage of skipped issues in night shift
trevor-e 0428e6d
ref(seer): Rename filter_recently_skipped to recently_skipped
trevor-e 3a40536
ref(seer): Replace magic 86400 with timedelta in skip_cache test
trevor-e 124b7c0
test(seer): Use real skip cache instead of patch in night shift test
trevor-e File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from collections.abc import Iterable | ||
| from datetime import timedelta | ||
|
|
||
| from redis.client import StrictRedis | ||
| from rediscluster import RedisCluster | ||
|
|
||
| from sentry.utils.redis import redis_clusters | ||
|
|
||
| # Padded past 3 days so nightly-run jitter can't expire a key right at the | ||
| # 3-day boundary; guarantees the next 3 nightly runs suppress the issue. | ||
| SKIP_TTL_SECONDS = int(timedelta(days=3, hours=12).total_seconds()) | ||
| KEY_PREFIX = "seer:night-shift:skip:" | ||
|
|
||
|
|
||
| def mark_skipped(group_id: int) -> None: | ||
| _client().set(key(group_id), "1", ex=SKIP_TTL_SECONDS) | ||
|
|
||
|
|
||
| def recently_skipped(group_ids: Iterable[int]) -> set[int]: | ||
| ids = list(group_ids) | ||
| if not ids: | ||
| return set() | ||
|
|
||
| pipeline = _client().pipeline() | ||
| for gid in ids: | ||
| pipeline.get(key(gid)) | ||
| values = pipeline.execute() | ||
| return {gid for gid, val in zip(ids, values) if val is not None} | ||
|
|
||
|
|
||
| def key(group_id: int) -> str: | ||
| return f"{KEY_PREFIX}{group_id}" | ||
|
|
||
|
|
||
| def _client() -> RedisCluster[str] | StrictRedis[str]: | ||
| return redis_clusters.get("default") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| from datetime import timedelta | ||
|
|
||
| from sentry.tasks.seer.night_shift.skip_cache import ( | ||
| SKIP_TTL_SECONDS, | ||
| key, | ||
| mark_skipped, | ||
| recently_skipped, | ||
| ) | ||
| from sentry.utils.redis import redis_clusters | ||
|
|
||
|
|
||
| def _delete(group_id: int) -> None: | ||
| redis_clusters.get("default").delete(key(group_id)) | ||
|
|
||
|
|
||
| def test_mark_then_recently_skipped_returns_id() -> None: | ||
| try: | ||
| mark_skipped(101) | ||
| assert recently_skipped([101]) == {101} | ||
| finally: | ||
| _delete(101) | ||
|
|
||
|
|
||
| def test_recently_skipped_returns_only_marked_ids() -> None: | ||
| try: | ||
| mark_skipped(202) | ||
| assert recently_skipped([202, 203, 204]) == {202} | ||
| finally: | ||
| _delete(202) | ||
|
|
||
|
|
||
| def test_recently_skipped_empty_input() -> None: | ||
| assert recently_skipped([]) == set() | ||
|
|
||
|
|
||
| def test_ttl_padded_past_three_days() -> None: | ||
| try: | ||
| mark_skipped(305) | ||
| ttl = redis_clusters.get("default").ttl(key(305)) | ||
| assert int(timedelta(days=3).total_seconds()) < ttl <= SKIP_TTL_SECONDS | ||
| finally: | ||
| _delete(305) | ||
|
|
||
|
|
||
| def test_deleted_key_no_longer_recently_skipped() -> None: | ||
| mark_skipped(406) | ||
| _delete(406) | ||
| assert recently_skipped([406]) == set() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: A Redis connection failure in
mark_skippedafter the main agent logic will cause an unhandled exception, discarding all previously computed triage results.Severity: MEDIUM
Suggested Fix
Wrap the
mark_skippedcall in its owntry/exceptblock to catch potential Redis connection errors. Log the error for observability but do not re-raise it, allowing the function to return the successfully computed triage results. This ensures that failures in the caching optimization do not cause the loss of primary results.Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.