-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Make ignore_metrics
support *
wildcard for OpenMetrics
#5759
Conversation
config['_ignored_metrics'] = {} | ||
config['_ignored_patterns'] = {} | ||
|
||
# Separate ignored metric names and ignored patterns in different maps for faster lookup later | ||
for metric in config['ignore_metrics']: | ||
if '*' in metric: | ||
config['_ignored_patterns'][metric] = True | ||
else: | ||
config['_ignored_metrics'][metric] = True |
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.
Can’t we use sets
rather than dictionnary
?
It seems that the only value that we use is True
and we only check for element existence.
config['_ignored_metrics'] = {} | |
config['_ignored_patterns'] = {} | |
# Separate ignored metric names and ignored patterns in different maps for faster lookup later | |
for metric in config['ignore_metrics']: | |
if '*' in metric: | |
config['_ignored_patterns'][metric] = True | |
else: | |
config['_ignored_metrics'][metric] = True | |
config['_ignored_metrics'] = set() | |
config['_ignored_patterns'] = set() | |
# Separate ignored metric names and ignored patterns in different maps for faster lookup later | |
for metric in config['ignore_metrics']: | |
if '*' in metric: | |
config['_ignored_patterns'].add(metric) | |
else: | |
config['_ignored_metrics'].add(metric) |
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.
indeed thanks!
fea930c
to
005b04e
Compare
self._send_telemetry_counter( | ||
self.TELEMETRY_COUNTER_METRICS_IGNORE_COUNT, len(metric.samples), scraper_config | ||
) | ||
return # Ignore the metric | ||
|
||
for ignore_pattern in scraper_config['_ignored_patterns']: | ||
if fnmatchcase(metric.name, ignore_pattern): |
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.
This will cause a large slow down. No way around it I guess, just saying...
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.
is it worth adding a if config['ignore_metrics']
or the for
on the empty set if fast enough?
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.
here is a small benchmark - it's almost the same
>>> timeit('for x in s: print("found")', setup='s = set(); x = "randomstring"',number=100000)
0.004889011383056641
>>>
>>> timeit('if map: print("found")', setup='map = dict()', number=100000)
0.003404855728149414
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.
in absolute it's fast yes, but looks like we could use the 30% speedup 👍
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.
here is a follow-up PR #5764
ignore_metrics
support *
wildcard for OpenMetrics
What does this PR do?
fnmatchcase
patternignore_metrics
openmetrics check parameterMotivation
More flexible config to ignore metrics
Additional Notes
Review checklist (to be filled by reviewers)
changelog/
andintegration/
labels attached