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

Support "*" wildcard in type_overrides configuration #7071

Merged
merged 1 commit into from
Jul 20, 2020

Conversation

ahmed-mez
Copy link
Contributor

@ahmed-mez ahmed-mez commented Jul 6, 2020

What does this PR do?

Make it possible to use the wildcard * to match metric names when configuring type_overrides

fixes #6091

Motivation

FR

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • PR title must be written as a CHANGELOG entry (see why)
  • Files changes must correspond to the primary purpose of the PR as described in the title (small unrelated changes should have their own PR)
  • PR must have changelog/ and integration/ labels attached

Copy link
Member

@L3n41c L3n41c left a 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.

@ahmed-mez ahmed-mez force-pushed the ahmed-mez/type-overrides-wildcard branch from 5df0def to 5836de6 Compare July 7, 2020 10:10
L3n41c
L3n41c previously approved these changes Jul 7, 2020
Copy link
Member

@L3n41c L3n41c left a comment

Choose a reason for hiding this comment

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

LGTM !

Copy link
Contributor

@ofek ofek left a 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)

@ahmed-mez ahmed-mez force-pushed the ahmed-mez/type-overrides-wildcard branch 3 times, most recently from fadcb80 to 190a2d1 Compare July 8, 2020 08:59
Comment on lines +254 to +257
for metric, type in iteritems(config['type_overrides']):
if '*' in metric:
config['_type_override_patterns'][compile(translate(metric))] = type
Copy link
Member

@L3n41c L3n41c Jul 8, 2020

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:

Suggested change
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

Copy link
Contributor Author

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?

Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ofek a friendly bump!

L3n41c
L3n41c previously approved these changes Jul 8, 2020
@ahmed-mez ahmed-mez force-pushed the ahmed-mez/type-overrides-wildcard branch from 190a2d1 to ec567c4 Compare July 8, 2020 15:29
L3n41c
L3n41c previously approved these changes Jul 8, 2020
Copy link
Member

@L3n41c L3n41c left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@ruthnaebeck ruthnaebeck left a comment

Choose a reason for hiding this comment

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

👍 for docs

@ahmed-mez ahmed-mez merged commit 82e0d60 into master Jul 20, 2020
@ahmed-mez ahmed-mez deleted the ahmed-mez/type-overrides-wildcard branch July 20, 2020 13:56
github-actions bot pushed a commit that referenced this pull request Jul 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Federated Prometheus URLs aren't working
4 participants