-
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
Support "*" wildcard in type_overrides configuration #7071
Conversation
Codecov Report
|
d72d526
to
04e9175
Compare
04e9175
to
4492281
Compare
4492281
to
5df0def
Compare
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.
The goal of the config['_matched_type_overrides']
dictionary is to avoid to do an fnmatch
comparison against all type_overrides
for a given metric more than once.
In order to achieve that goal, we would also need a negative cache that would cache the metrics that are matching none of the type_overrides
.
With the current implementation, for all the metrics that are matching none of the type_overrides
, we’ll re-do the fnmatch
comparison with all type_overrides
at each execution.
I would suggest that we put an entry in config['_matched_type_overrides']
in all cases.
If there is a matching type_overrides
parameter, we put the type. If there is no matching type_overrides
parameter, we put None
.
5df0def
to
5836de6
Compare
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.
LGTM !
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.
Please do this instead: #5764 (comment)
fadcb80
to
190a2d1
Compare
for metric, type in iteritems(config['type_overrides']): | ||
if '*' in metric: | ||
config['_type_override_patterns'][compile(translate(metric))] = type |
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.
From a complexity and performance perspective, I think we can do even better.
Here, we have a map with one entry per “pattern” type_override
even if several entries have the same type.
It means that, in the loop below, we’ll do several regex matching where a single regex match could be enough.
The idea would be for config['_type_override_patterns']
to have a single entry per type.
That would be something like this:
for metric, type in iteritems(config['type_overrides']): | |
if '*' in metric: | |
config['_type_override_patterns'][compile(translate(metric))] = type | |
overrides_per_type = {} | |
for metric, type in iteritems(config['type_overrides']): | |
if '*' in metric: | |
if type not in overrides_per_type: | |
overrides_per_type[type] = [] | |
overrides_per_type[type].append(fnmatch.translate(metric)) | |
del(config['type_overrides'][metric]) | |
for type, metric_patterns in iteritems(overrides_per_type): | |
config['_type_override_patterns'][compile('|'.join(metrics_patterns))] = type |
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.
thanks @L3n41c for the suggestion!
I actually thought about this approach at first but I'm not sure if it's worth it, as this path is executed only once (at the class creation) and more importantly this makes the code less straight forward and more difficult to read/understand.
@ofek what do you think about the tradeoff perf/code-readability here? is it worth it?
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.
If only at class creation time, then yes might not be worth it
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.
thank you, mind approving the PR please if looks good then?
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.
@ofek a friendly bump!
190a2d1
to
ec567c4
Compare
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.
LGTM
ec567c4
to
081605b
Compare
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.
👍 for docs
What does this PR do?
Make it possible to use the wildcard
*
to match metric names when configuringtype_overrides
fixes #6091
Motivation
FR
Review checklist (to be filled by reviewers)
changelog/
andintegration/
labels attached