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(minimetrics): Fix broken recursion detection #56466

Merged
merged 1 commit into from
Sep 19, 2023

Conversation

mitsuhiko
Copy link
Member

add can call into metrics.incr which can go back into minimetrics. This fixes this recursion.

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Sep 19, 2023
if tags is not None:
casted_tags = {
tag_key: str(tag_value) for tag_key, tag_value in tags.items() if tag_value is not None
}

return cast(Optional[MetricTagsExternal], casted_tags)
return casted_tags
Copy link
Member Author

Choose a reason for hiding this comment

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

Apparently Optional[MetricsTagsExternal] causes something odd to happen in typing and this also raise a recursion error for me:

11:59:28 [ERROR] sentry.errors: Unable to record backend metric
Traceback (most recent call last):
  File "/Users/mitsuhiko/Development/sentry/src/sentry/utils/metrics.py", line 133, in incr
    backend.incr(key, instance, tags, amount, sample_rate)
  File "/Users/mitsuhiko/Development/sentry/src/sentry/metrics/middleware.py", line 133, in incr
    return self.inner.incr(key, instance, current_tags, amount, sample_rate)
  File "/Users/mitsuhiko/Development/sentry/src/sentry/metrics/minimetrics.py", line 86, in incr
    tags=_to_minimetrics_external_metric_tags(tags),
  File "/Users/mitsuhiko/Development/sentry/src/sentry/metrics/minimetrics.py", line 18, in _to_minimetrics_external_metric_tags
    return cast(Optional[MetricTagsExternal], casted_tags)
  File "/Users/mitsuhiko/.pyenv/versions/3.8.12/lib/python3.8/typing.py", line 258, in inner
    return cached(*args, **kwds)
  File "/Users/mitsuhiko/.pyenv/versions/3.8.12/lib/python3.8/typing.py", line 330, in __hash__
    return hash((self._name,))
RecursionError: maximum recursion depth exceeded while calling a Python object

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 think this is just that it finally failed recursion on that level, but given that cast() is just unnecessary runtime overhead, I removed it.

@mitsuhiko mitsuhiko enabled auto-merge (squash) September 19, 2023 12:32
@codecov
Copy link

codecov bot commented Sep 19, 2023

Codecov Report

Merging #56466 (92b98df) into master (2e6a678) will increase coverage by 0.00%.
Report is 1 commits behind head on master.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master   #56466   +/-   ##
=======================================
  Coverage   78.65%   78.65%           
=======================================
  Files        5078     5078           
  Lines      218270   218270           
  Branches    36951    36951           
=======================================
+ Hits       171676   171678    +2     
+ Misses      41052    41051    -1     
+ Partials     5542     5541    -1     
Files Changed Coverage
src/sentry/metrics/minimetrics.py 100.00%

@mitsuhiko mitsuhiko merged commit 36c4b54 into master Sep 19, 2023
51 checks passed
@mitsuhiko mitsuhiko deleted the fix/recursion-protection branch September 19, 2023 12:40
@github-actions github-actions bot locked and limited conversation to collaborators Oct 4, 2023
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants