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

ref(seer grouping): Use new CircuitBreaker class for circuit breaking #74563

Merged

Conversation

lobsterkatie
Copy link
Member

The current implementation of circuit breaking for Seer similarity requests, using with_circuit_breaker, doesn't work because any errors the breaker might track are caught much farther down the call stack and never make it to the breaker. This fixes that by switching from using with_circuit_breaker to using an instance of the new CircuitBreaker class, which allows us to track the errors at a low level, before they're caught, while still using the breaker to decide whether to make the request at a much higher level.

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jul 19, 2024
Copy link

codecov bot commented Jul 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.16%. Comparing base (0d530a6) to head (8186b35).
Report is 6 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #74563      +/-   ##
==========================================
+ Coverage   78.14%   78.16%   +0.01%     
==========================================
  Files        6731     6731              
  Lines      300214   300257      +43     
  Branches    51642    51648       +6     
==========================================
+ Hits       234608   234684      +76     
+ Misses      59285    59250      -35     
- Partials     6321     6323       +2     
Files Coverage Δ
src/sentry/conf/server.py 87.78% <100.00%> (+0.02%) ⬆️
src/sentry/grouping/ingest/seer.py 100.00% <100.00%> (ø)
src/sentry/options/defaults.py 100.00% <ø> (ø)
src/sentry/seer/similarity/similar_issues.py 97.40% <100.00%> (+0.21%) ⬆️
src/sentry/utils/circuit_breaker2.py 97.61% <100.00%> (+30.60%) ⬆️

... and 5 files with indirect coverage changes

@lobsterkatie lobsterkatie force-pushed the kmclb-switch-seer-similarity-to-use-new-circuit-breaker branch from aa80763 to e88dfb9 Compare July 19, 2024 17:16
@lobsterkatie lobsterkatie marked this pull request as ready for review July 19, 2024 18:42
@lobsterkatie lobsterkatie requested a review from a team as a code owner July 19, 2024 18:42
src/sentry/event_manager.py Show resolved Hide resolved
src/sentry/grouping/ingest/seer.py Show resolved Hide resolved
src/sentry/grouping/ingest/seer.py Show resolved Hide resolved
src/sentry/grouping/ingest/seer.py Show resolved Hide resolved
metrics.incr(
"grouping.similarity.did_call_seer",
sample_rate=1.0,
tags={"call_made": False, "blocker": "circuit-breaker"},
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: You could use a centralized constant to keep track of all the reasons that could block

e.g.

class SEER_BLOCKING_REASONS(Enum):
  CIRCUIT_BREAKER = "circuit-breaker"
  ...

Copy link
Member Author

Choose a reason for hiding this comment

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

I could, it's true. It'd have to be imported from utils, since different versions of the metric are recorded there, too.

I'm not sure there's a huge advantage there if I'm only using each one once, though, is there?

src/sentry/grouping/ingest/seer.py Outdated Show resolved Hide resolved
@lobsterkatie lobsterkatie force-pushed the kmclb-add-core-CircuitBreaker-methods branch from 6bd2c86 to 526edc4 Compare July 23, 2024 00:48
@lobsterkatie lobsterkatie force-pushed the kmclb-switch-seer-similarity-to-use-new-circuit-breaker branch from e88dfb9 to 3762351 Compare July 23, 2024 00:50
@lobsterkatie lobsterkatie force-pushed the kmclb-switch-seer-similarity-to-use-new-circuit-breaker branch from 3762351 to c286d0c Compare July 23, 2024 06:00
@lobsterkatie lobsterkatie force-pushed the kmclb-add-core-CircuitBreaker-methods branch from e0d7108 to 347a4b1 Compare July 23, 2024 06:17
@lobsterkatie lobsterkatie force-pushed the kmclb-switch-seer-similarity-to-use-new-circuit-breaker branch from c286d0c to 46f8edb Compare July 23, 2024 06:20
@lobsterkatie lobsterkatie force-pushed the kmclb-add-core-CircuitBreaker-methods branch from 347a4b1 to a6d8786 Compare July 23, 2024 17:36
@lobsterkatie lobsterkatie force-pushed the kmclb-switch-seer-similarity-to-use-new-circuit-breaker branch from 46f8edb to 2328eb0 Compare July 23, 2024 17:40
@lobsterkatie lobsterkatie force-pushed the kmclb-add-core-CircuitBreaker-methods branch from a6d8786 to 1713e4b Compare July 23, 2024 18:13
@lobsterkatie lobsterkatie force-pushed the kmclb-switch-seer-similarity-to-use-new-circuit-breaker branch from 2328eb0 to 8186b35 Compare July 23, 2024 18:15
Base automatically changed from kmclb-add-core-CircuitBreaker-methods to master July 23, 2024 18:48
@lobsterkatie lobsterkatie force-pushed the kmclb-switch-seer-similarity-to-use-new-circuit-breaker branch from 8186b35 to f7ac804 Compare July 23, 2024 18:54
@lobsterkatie lobsterkatie merged commit e117cd0 into master Jul 23, 2024
49 checks passed
@lobsterkatie lobsterkatie deleted the kmclb-switch-seer-similarity-to-use-new-circuit-breaker branch July 23, 2024 19:36
@@ -30,6 +36,11 @@
timeout=settings.SEER_GROUPING_TIMEOUT,
)

seer_similarity_circuit_breaker = CircuitBreaker(
SEER_SIMILARITY_CIRCUIT_BREAKER_KEY,
options.get("seer.similarity.circuit-breaker-config"),
Copy link
Member

Choose a reason for hiding this comment

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

an options call at the module is only reflected at import time (and is always the default because the database connection isn't set up)

this is breaking mypy locally because the database isn't set up

Copy link
Member Author

Choose a reason for hiding this comment

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

and is always the default because the database connection isn't set up

Oh, very good to know. Thanks for catching that! I'll switch it to initializing on the fly.

Copy link
Member

Choose a reason for hiding this comment

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

ah yeah -- thought it would've stuck from the last time

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, missed that - thanks for pointing it out!

@asottile-sentry asottile-sentry added the Trigger: Revert add to a merged PR to revert it (skips CI) label Jul 24, 2024
getsentry-bot added a commit that referenced this pull request Jul 24, 2024
…t breaking (#74563)"

This reverts commit e117cd0.

Co-authored-by: asottile-sentry <103459774+asottile-sentry@users.noreply.github.com>
@getsentry-bot
Copy link
Contributor

PR reverted: 1bb6a50

lobsterkatie added a commit that referenced this pull request Jul 25, 2024
This is a redo of #74563 (which got reverted), with the difference that the circuit breaker is now reinstantiated before each use, rather than being instantiated once at the module level. (The problem with that setup was that the module turns out to initialize before our database connections are established, meaning we only get the hardcoded default config rather than the one provided by the options automator.)
Christinarlong pushed a commit that referenced this pull request Jul 26, 2024
…t breaking (#74563)"

This reverts commit e117cd0.

Co-authored-by: asottile-sentry <103459774+asottile-sentry@users.noreply.github.com>
Christinarlong pushed a commit that referenced this pull request Jul 26, 2024
This is a redo of #74563 (which got reverted), with the difference that the circuit breaker is now reinstantiated before each use, rather than being instantiated once at the module level. (The problem with that setup was that the module turns out to initialize before our database connections are established, meaning we only get the hardcoded default config rather than the one provided by the options automator.)
@github-actions github-actions bot locked and limited conversation to collaborators Aug 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Backend Automatically applied to PRs that change backend components Trigger: Revert add to a merged PR to revert it (skips CI)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants