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

Metrics: Support for updating/adding the metrics label names/values from metric name regex groups #24366

Closed
dirrao opened this issue Jul 18, 2023 · 11 comments
Labels
processor/metricstransform Metrics Transform processor processor/transform Transform processor question Further information is requested

Comments

@dirrao
Copy link

dirrao commented Jul 18, 2023

Component(s)

No response

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

Unable to use metrics regex groups in label names or values in metrics transform processor. It will be great to add this to avoid blowing the metrics namespace. We are looking something similar to statsd telegraf templates.
https://github.com/influxdata/telegraf/blob/master/plugins/inputs/statsd/README.md

Describe the solution you'd like

No response

Describe alternatives you've considered

No response

Additional context

No response

@github-actions
Copy link
Contributor

Pinging code owners for processor/metricstransform: @dmitryax. See Adding Labels via Comments if you do not have permissions to add labels yourself.

@crobert-1
Copy link
Member

Hello @dirrao, sorry for the delay in response! Can you provide some more information for your goal here? A specific example of what you're trying to match and do with the processor would be a lot of help in directing your concern here.

@charz
Copy link

charz commented Nov 9, 2023

@dirrao Thanks for raising this request. I have a similar reqeust, but I'm not sure if this is your case.

@crobert-1 This is my case.

I tried to use statsdreciever + metricstransform to cover some statad metrics that don't have label and value.

stats metrics

http.GET.404.timing
http.GET.200.timing

The configuration that I have for metricstransform. I can add regex group to metric name, but I'm not able to make it work in new label.

This works in metric name

processors:
  metricstransform:
    transforms:
      - include: ^http.([A-Z_]*).([0-9]{3}).timing
        match_type: regexp
        action: update
        new_name: http_timing_$${1}_$${2}

This doesn't work. The regex group won't able to add in label value.

processors:
  metricstransform:
    transforms:
      - include: ^http.([A-Z_]*).([0-9]{3}).timing
        match_type: regexp
        action: update
        new_name: http_timing
        operations:
          - action: add_label
            new_label: method
            new_value: $${1}
          - action: add_label
            new_label: status_code
            new_value: $${2}    

@charz
Copy link

charz commented Nov 13, 2023

Or we have to user another processor module to achieve this goal?

@crobert-1
Copy link
Member

crobert-1 commented Nov 15, 2023

I believe you may be able to use the transform processor here to add an attribute with the proper value from the metric name. The transform processor uses the OpenTelemetry Transformation Language (OTTL) to transform telemetry.

I believe if you set the context to be DataPoint, you'd have access to both the datapoint attributes, and the metric name. The ExtractPatterns OTTL function could be used to extract the status code into a map from the metric name, and then you could use the set function with the proper status (from ExtractPatterns) to set the new attribute to the status code.

If you want to also rename metric names to remove the status code, you could also include the metric transform in your pipeline to rename metrics and remove the status from their names after the attribute is added.

Terminology note:
I'm not super well-versed in terminology here, but from some searching it shows that labels have been renamed to attributes, and the metric transform processor now shows explicitly it's adding key:value pairs to the datapoint attributes. So even though I'm giving guidance regarding datapoint attributes, this is the same thing as labels, just different terminology.

@crobert-1 crobert-1 added question Further information is requested and removed enhancement New feature or request processor/metricstransform Metrics Transform processor labels Nov 15, 2023
@crobert-1 crobert-1 added processor/transform Transform processor processor/metricstransform Metrics Transform processor labels Nov 15, 2023
Copy link
Contributor

Pinging code owners for processor/transform: @TylerHelmuth @kentquirk @bogdandrutu @evan-bradley. See Adding Labels via Comments if you do not have permissions to add labels yourself.

Copy link
Contributor

Pinging code owners for processor/metricstransform: @dmitryax. See Adding Labels via Comments if you do not have permissions to add labels yourself.

@charz
Copy link

charz commented Nov 16, 2023

I believe you may be able to use the transform processor here to add an attribute with the proper value from the metric name. The transform processor uses the OpenTelemetry Transformation Language (OTTL) to transform telemetry.

@crobert-1 That's really good information! I'll give a try.

@charz
Copy link

charz commented Nov 16, 2023

I believe if you set the context to be DataPoint, you'd have access to both the datapoint attributes, and the metric name. The ExtractPatterns OTTL function could be used to extract the status code into a map from the metric name, and then you could use the set function with the proper status (from ExtractPatterns) to set the new attribute to the status code.

@crobert-1 Thanks for your suggestion! This works perfectly!

@crobert-1 crobert-1 removed the needs triage New item requiring triage label Nov 20, 2023
@crobert-1
Copy link
Member

Perfect! I'm going to close this issue, but feel free to let us know if there's anything else we can do to help!

@zdelagrange
Copy link

zdelagrange commented Feb 15, 2024

I wanted to include a solution to this issue using the transform processor. this example extracts a UUID from the metric name, adds it to the attributes with a named group, and then removes the uuid from the metric name:

transform/uuid_to_attribute:
        error_mode: ignore
        metric_statements:
        - context: datapoint
          statements:
          - merge_maps(attributes, ExtractPatterns(metric.name, "^.*(?P<uuid>[a-fA-F0-9]{8}_[a-fA-F0-9]{4}_[a-fA-F0-9]{4}_[a-fA-F0-9]{4}_[a-fA-F0-9]{12}).*$"), "insert")
          - replace_pattern(metric.name, "(?P<uuid>[a-fA-F0-9]{8}_[a-fA-F0-9]{4}_[a-fA-F0-9]{4}_[a-fA-F0-9]{4}_[a-fA-F0-9]{12})", "")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
processor/metricstransform Metrics Transform processor processor/transform Transform processor question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants