opentelemetry-collector
opentelemetry-collector copied to clipboard
mdatagen: add wildcard name matching for configs
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 https://github.com/open-telemetry/opentelemetry-collector/issues/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.
Codecov Report
Attention: Patch coverage is 33.33333% with 8 lines in your changes missing coverage. Please review.
Project coverage is 92.43%. Comparing base (
c7c3401) to head (d82df38). Report is 119 commits behind head on main.
:exclamation: Current head d82df38 differs from pull request most recent head a522523
Please upload reports for the commit a522523 to get more accurate results.
| Files | Patch % | Lines |
|---|---|---|
| cmd/mdatagen/main.go | 33.33% | 4 Missing and 4 partials :warning: |
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
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
I think that code coverage change is fine here because none of the return err cases for template file generation are covered anyway.
The changelog issue can only be resolved once the issue is moved from contrib to here.
This PR was marked stale due to lack of activity. It will be closed in 14 days.
@braydonk, are you still working on this? Just checking. Let me know if you have any concerns with my comments
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.
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
I'm gonna wait to address the conflicts, cause this is just going to keep coming up continuously throughout the review.
This PR was marked stale due to lack of activity. It will be closed in 14 days.
Not stale
This PR was marked stale due to lack of activity. It will be closed in 14 days.
Closed as inactive. Feel free to reopen if this PR is still being worked on.