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

mdatagen: add wildcard name matching for configs #10065

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

braydonk
Copy link
Contributor

@braydonk braydonk commented May 1, 2024

Description

This PR adds support for wildcard name matching.

Generated MetricsConfig and ResourceAttributesConfig will now support providing names not just as full names, but also using * wildcards and multimatching with {x,y,etc}. This allows you to apply configs to groups of metrics and resource attributes, simplifying configs.

Link to tracking issue

Fixes #10074

Testing

I go installed mdatagen from this PR and ran it on a receiver in opentelemetry-collector-contrib and was able to use wildcard matching to enable/disable groups of metrics as expected.

Documentation

I have written a specification in a gist: https://gist.github.com/braydonk/ccb6775331fdd5dca91a650330b9839f

I am not sure where this documentation should live.

@braydonk braydonk requested a review from a team as a code owner May 1, 2024 19:26
@braydonk braydonk requested a review from Aneurysm9 May 1, 2024 19:26
@braydonk braydonk force-pushed the wildcard_names branch 2 times, most recently from 026ad18 to 2ed7ec4 Compare May 1, 2024 20:07
Copy link

codecov bot commented May 1, 2024

Codecov Report

Attention: Patch coverage is 33.33333% with 8 lines in your changes are missing coverage. Please review.

Project coverage is 92.43%. Comparing base (c7c3401) to head (d82df38).
Report is 3 commits behind head on main.

Current head d82df38 differs from pull request most recent head 08cf72d

Please upload reports for the commit 08cf72d to get more accurate results.

Files Patch % Lines
cmd/mdatagen/main.go 33.33% 4 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10065      +/-   ##
==========================================
- Coverage   92.59%   92.43%   -0.16%     
==========================================
  Files         387      387              
  Lines       18198    18264      +66     
==========================================
+ Hits        16850    16883      +33     
- Misses       1007     1031      +24     
- Partials      341      350       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@braydonk
Copy link
Contributor Author

braydonk commented May 1, 2024

I think that code coverage change is fine here because none of the return err cases for template file generation are covered anyway.

@braydonk
Copy link
Contributor Author

braydonk commented May 2, 2024

The changelog issue can only be resolved once the issue is moved from contrib to here.

"strings"
)

var ErrNotMultimatch = errors.New("this index doesn't represent a valid multimatch pattern")
Copy link
Member

Choose a reason for hiding this comment

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

I don't see a reason to export any API in this file. We should only export config field types and Unmarshal methods

Copy link
Contributor Author

Choose a reason for hiding this comment

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

None of the API is exported in the rewrite 3f0a4e8

for _, name := range matchNames {
if pattern.Match(name) {
matched = append(matched, name)
}
Copy link
Member

Choose a reason for hiding this comment

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

We should fail unmarshalling if we run into a pattern that doesn't match any metric names. It'll be aligned with the strict matching behavior

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will add this in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in d82df38

patternScan.idx += 2
}

case '{':
Copy link
Member

Choose a reason for hiding this comment

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

Can you please point to some specifications for this sort of pattern matching? Does it usually go with wildcard matching?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in the description of the PR, but link here: https://gist.github.com/braydonk/ccb6775331fdd5dca91a650330b9839f

Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label May 19, 2024
@dmitryax dmitryax removed the Stale label May 21, 2024
@dmitryax
Copy link
Member

@braydonk, are you still working on this? Just checking. Let me know if you have any concerns with my comments

@braydonk
Copy link
Contributor Author

Hi @dmitryax yes I am. I realized that I forgot to mention that I am writing a full spec to explain how it works, and while I was doing that found a number of edge cases that prompted me to rewrite the parser. Taking longer than expected. I am still working on this though and will keep it unstale.

This PR adds support for wildcard name matching.

Generated MetricsConfig and ResourceAttributesConfig will now support
providing names not just as full names, but also using `*` wildcards and
multimatching with `{x,y,etc}`. This allows you to apply configs to
groups of metrics and resource attributes, simplifying configs.

Signed-off-by: braydonk <braydonk@google.com>
@braydonk
Copy link
Contributor Author

braydonk commented May 28, 2024

What the actual errors look like from collector output is not super obvious from the PR, so here are some examples. I used the hostmetrics process scraper in my example.

Not matching any names with the patterns

hostmetrics:
  collection_interval: 10s
  scrapers:
    process:
      metrics:
        "nothing.*":
          enabled: false
$ ./otelcontribcol --config config.yaml 
Error: failed to get config: cannot unmarshal the configuration: 1 error(s) decoding:

* error decoding 'receivers': error reading configuration for "hostmetrics": error reading settings for scraper type "process": 1 error(s) decoding:

* error decoding 'metrics': specified patterns don't match any names
2024/05/28 16:06:44 collector server run finished with error: failed to get config: cannot unmarshal the configuration: 1 error(s) decoding:

* error decoding 'receivers': error reading configuration for "hostmetrics": error reading settings for scraper type "process": 1 error(s) decoding:

* error decoding 'metrics': specified patterns don't match any names

Parsing errors in a pattern

hostmetrics:
  collection_interval: 10s
  scrapers:
    process:
      metrics:
        "a_.*":
          enabled: false
$ ./otelcontribcol --config config.yaml
Error: failed to get config: cannot unmarshal the configuration: 1 error(s) decoding:

* error decoding 'receivers': error reading configuration for "hostmetrics": error reading settings for scraper type "process": 1 error(s) decoding:

* error decoding 'metrics': pattern parsing error:
a_.*
  ^
invalid pattern: unexpected token
2024/05/28 16:06:52 collector server run finished with error: failed to get config: cannot unmarshal the configuration: 1 error(s) decoding:

* error decoding 'receivers': error reading configuration for "hostmetrics": error reading settings for scraper type "process": 1 error(s) decoding:

* error decoding 'metrics': pattern parsing error:
a_.*
  ^
invalid pattern: unexpected token

@braydonk
Copy link
Contributor Author

I'm gonna wait to address the conflicts, cause this is just going to keep coming up continuously throughout the review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[cmd/mdatagen] Ability to disable/enable all metrics
2 participants