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

replace_pattern() OTTL function should allow referencing capturing groups #18610

Closed
sirianni opened this issue Feb 13, 2023 · 6 comments
Closed
Labels
enhancement New feature or request pkg/ottl

Comments

@sirianni
Copy link
Contributor

sirianni commented Feb 13, 2023

Component(s)

pkg/ottl

Is your feature request related to a problem? Please describe.

I'd like to rename metrics scraped from certain destinations to better align to naming conventions (for example, replacing dashes with dots, etc.)

My attempt was to use the transform processor with OTTL for this capability

  transform/kube_state_rename:
    metric_statements:
    - context: metric
      statements:
      - replace_pattern(name, "kube_([0-9A-Za-z]+_)", "k8s.$$1")

However, the replace_pattern() OTTL function does not support expanding references to capturing groups.

Describe the solution you'd like

I would like replace_pattern() OTTL to not support expanding references to capturing groups (using replace_pattern() OTTL function does not support expanding references to capturing groups.).

Describe alternatives you've considered

No response

Additional context

Seems tangentially related to #18084

@sirianni sirianni added enhancement New feature or request needs triage New item requiring triage labels Feb 13, 2023
@sirianni sirianni changed the title replace_pattern OTTL function should allow referencing capturing groups replace_pattern() OTTL function should allow referencing capturing groups Feb 13, 2023
@github-actions
Copy link
Contributor

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@TylerHelmuth
Copy link
Member

This is an interesting use case and doesn't add too much complexity. Using ReplaceAllString instead of ReplaceAllLiteralString still preserves all the existing use cases except for literal uses of $, which is probably a low percentage. Although a breaking change, those use cases can use $$ instead.

@sirianni
Copy link
Contributor Author

Although a breaking change, those use cases can use $$ instead.

Actually it looks like the env var interpolation already eats a single $, so you would need $$1 to refer to a capturing group and $$$ to get a literal $.

@TylerHelmuth
Copy link
Member

hmmmm. Thats pretty annoying and confusing. Did you test this out to confirm?

@sirianni
Copy link
Contributor Author

hmmmm. Thats pretty annoying and confusing. Did you test this out to confirm?

Yes, it took me a while debugging it to realize that the single $ was not even making it through to the OTTL parser.

@TylerHelmuth
Copy link
Member

I guess we just have to document that behavior in the function's README entry.

sirianni added a commit to sirianni/opentelemetry-collector-contrib that referenced this issue Feb 13, 2023
sirianni added a commit to sirianni/opentelemetry-collector-contrib that referenced this issue Feb 13, 2023
@evan-bradley evan-bradley removed the needs triage New item requiring triage label Feb 14, 2023
codeboten pushed a commit that referenced this issue Feb 23, 2023
…ern (#18614)

Use ReplaceAllString() instead of ReplaceAllLiteralString() to allow referencing matched capture groups in replacement

Link to tracking Issue:
#18610

Co-authored-by: Evan Bradley <11745660+evan-bradley@users.noreply.github.com>
newly12 pushed a commit to newly12/opentelemetry-collector-contrib that referenced this issue Feb 28, 2023
…ern (open-telemetry#18614)

Use ReplaceAllString() instead of ReplaceAllLiteralString() to allow referencing matched capture groups in replacement

Link to tracking Issue:
open-telemetry#18610

Co-authored-by: Evan Bradley <11745660+evan-bradley@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pkg/ottl
Projects
None yet
Development

No branches or pull requests

3 participants