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

I encountered a problem when I wanted to filter out metrics about certain labels when applying spanmetrics. #34508

Open
Cairry opened this issue Aug 8, 2024 · 17 comments
Labels
connector/spanmetrics discussion needed Community discussion needed processor/filter Filter processor question Further information is requested Stale

Comments

@Cairry
Copy link

Cairry commented Aug 8, 2024

Component(s)

connector/spanmetrics, processor/filter

Describe the issue you're reporting

background:
PromQL: sum(duration_count{span_name="GET"}) by (span_name)
Sample: {span_name="GET"} 27972

Need:
I want to filter out the metric whose span_name is GET through filter, but the following configuration does not work.

    processors:
      batch:
      filter/ottl:
        error_mode: ignore
        metrics:
          metric:
            - 'resource.attributes["span_name"] == "GET"'

The above is to simply test the filtering ability. In fact, I want to filter out span_name that does not start with GET or POST. Please help me complete it. Thank you

@Cairry Cairry added the needs triage New item requiring triage label Aug 8, 2024
Copy link
Contributor

github-actions bot commented Aug 8, 2024

Pinging code owners:

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

@iblancasa
Copy link
Contributor

Is the filtering not working just with those metrics that are created with the spanmetrics connector or are you able to reproduce a similar behavior with other metrics?

Can you try this expression?

            - IsMatch(resource.attributes["span_name"], "GET")

@TylerHelmuth
Copy link
Member

@Cairry most of the time when a filter isn't working it is because the attribute name or location is wrong. Please enable service.telemetry.logs.level=debug or add a debugexporter with verbosity: detailed to view the data as the collector sees it.

@TylerHelmuth TylerHelmuth added waiting for author discussion needed Community discussion needed and removed needs triage New item requiring triage labels Aug 8, 2024
@Cairry
Copy link
Author

Cairry commented Aug 9, 2024

过滤是否不仅适用于使用这些创建的指标,spanmetrics connector或者您是否能够使用其他指标重现类似的行为?

你能尝试一下这个表达吗?

            - IsMatch(resource.attributes["span_name"], "GET")

I got the following error after using the method you provided, it seems that the IsMatch method is not allowed

    processors:
      batch:
      filter/duration_count_get:
        error_mode: ignore
        metrics:
          metric:
            - IsMatch(resource.attributes["span_name"], "GET")
 ···
    service:
      pipelines:
        traces:
          receivers: [otlp, opencensus]
          exporters: [jaeger]
        traces/spanmetrics:
          receivers: [otlp, opencensus]
          exporters: [spanmetrics]
        metrics:
          receivers: [otlp, opencensus]
          processors: [filter/metrics]
          exporters: [prometheus]
        metrics/spanmetrics:
          receivers: [spanmetrics]
          processors: [filter/metrics]
          exporters: [prometheusremotewrite]

error

Error: invalid configuration: processors::filter/duration_count_get: unable to parse OTTL statement: 1:62: unexpected token "<EOF>" (expected <opcomparison> Value)
2024/08/09 01:27:18 collector server run finished with error: invalid configuration: processors::filter/duration_count_get: unable to parse OTTL statement: 1:62: unexpected token "<EOF>" (expected <opcomparison> Value)

All methods in processors do not meet the requirement of filtering out span_name=GET, which is a headache.

    processors:
      batch:
      filter/exclude_duration_count:
        metrics:
          exclude:
            match_type: strict
            metric_names:
              - duration_count

      filter/duration_count_get:
        error_mode: ignore
        metrics:
          metric:
            - IsMatch(resource.attributes["span_name"], "GET")
      filter/metrics:
        metrics:
          exclude:
            match_type: strict
            metric_names:
              - duration_count
            resource_attributes:
              - key: span_name
                value: GET
      filter/ottl:
        error_mode: ignore
        traces:
          span:
            - 'attributes["http.url"] == "http://opentelemetry-collector.istio-system:4318/v1/traces"'
            - 'attributes["http.url"] == "http://opentelemetry-collector.istio-system:4318/v1/metrics"'
            - 'attributes["grpc.authority"] == "opentelemetry-collector.istio-system:4317"'
        metrics:
          metric:
            - 'name == "duration_count"'
          datapoint:
            - metric.name == "duration_count"

    service:
      pipelines:
        traces:
          receivers: [otlp, opencensus]
          exporters: [jaeger]
        traces/spanmetrics:
          receivers: [otlp, opencensus]
          exporters: [spanmetrics]
        metrics:
          receivers: [otlp, opencensus]
          processors: [filter/metrics]
          exporters: [prometheus]
        metrics/spanmetrics:
          receivers: [spanmetrics]
          processors: [filter/metrics]
          exporters: [prometheusremotewrite]

@Frapschen
Copy link
Contributor

Frapschen commented Aug 9, 2024

@Cairry please try

      filter/duration_count_get:
        error_mode: ignore
        metrics:
          datapoint:
            - 'attributes["span.name"] == "GET"'

@Frapschen Frapschen added question Further information is requested and removed waiting for author labels Aug 9, 2024
@Cairry
Copy link
Author

Cairry commented Aug 9, 2024

@Cairry请尝试

      filter/duration_count_get:
        error_mode: ignore
        metrics:
          datapoint:
            - 'attributes["span.name"] == "GET"'

wow Thank you very much, your configuration is useful. Does it support regular expression? I hope to filter out span_name that is not GET and POST

@Frapschen
Copy link
Contributor

@iblancasa
Copy link
Contributor

过滤是否不仅适用于使用这些创建的指标,spanmetrics connector或者您是否能够使用其他指标重现类似的行为?
你能尝试一下这个表达吗?

            - IsMatch(resource.attributes["span_name"], "GET")

I got the following error after using the method you provided, it seems that the IsMatch method is not allowed

Maybe the syntax was not correct... https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/filterprocessor#examples

@TylerHelmuth
Copy link
Member

When using the datapoint context, assuming the value is a datapoint attribute, you'd do

      filter/duration_count_get:
        error_mode: ignore
        metrics:
          datapoint:
            - not IsMatch(attributes["span_name"], "GET|POST")

or

      filter/duration_count_get:
        error_mode: ignore
        metrics:
          datapoint:
            - attributes["span.name"] != "GET" and attributes["span.name"] != "POST"

@Cairry
Copy link
Author

Cairry commented Aug 12, 2024

Sorry experts, I have a new problem, which is that I can't filter out the two indicators of duration_count and duration_bucket. Below are my various attempts to filter. Where do I need to correct it?

    processors:
      batch:
      filter/duration_span_kind:
        error_mode: ignore
        metrics:
          metric:
            - 'name == "duration.count"'
            - 'name == "duration.bucket"'
          datapoint:
            - 'attributes["span.kind"] != "SPAN_KIND_SERVER"'
            - metric.name == "duration.count"
            - metric.name == "duration.bucket"

      filter/duration_bucket_count:
        error_mode: ignore
        metrics:
          exclude:
            match_type: strict
            metric_names:
              - duration.count
              - duration.bucket
...
    connectors:
      spanmetrics:
        dimensions:
          - name: http.method
          - name: http.status_code 
          - name: http.route

    service:
      pipelines:
        traces:
          receivers: [otlp, opencensus]
          exporters: [jaeger]
        traces/spanmetrics:
          receivers: [otlp, opencensus]
          processors: [filter/duration_span_kind, filter/duration_bucket_count]
          exporters: [spanmetrics]
        metrics:
          receivers: [otlp, opencensus]
          exporters: [prometheus]
        metrics/spanmetrics:
          receivers: [spanmetrics]
          processors: [filter/duration_span_kind, filter/duration_bucket_count]
          exporters: [prometheusremotewrite]

@Cairry
Copy link
Author

Cairry commented Aug 13, 2024

@Frapschen Hello, do you have time to help me look at this problem? It cannot filter out the two indicators of duration_bucket and duration_count. I have tried many ways but failed. I don't know where the problem is. It's so strange. Please help. Thank you~

@Frapschen
Copy link
Contributor

@Cairry The original latency metrics name of spanmetrics is duration. You only need to:

    processors:
      filter/duration_span_kind:
        error_mode: ignore
        metrics:
          metric:
            - 'name == "duration"'

@Cairry
Copy link
Author

Cairry commented Aug 13, 2024

@Cairry The original latency metrics name of spanmetrics is duration. You only need to:

    processors:
      filter/duration_span_kind:
        error_mode: ignore
        metrics:
          metric:
            - 'name == "duration"'

Ok thanks, will it filter out the duration_sum? Because I only need the duration_sum.

@Frapschen
Copy link
Contributor

In my experience, I will add a debug exporter:

exporters:
  debug:
    verbosity: detailed

it will log any detailed data in the console.

@Frapschen
Copy link
Contributor

duration_sum

I think the filter processor can't do that.

@Cairry
Copy link
Author

Cairry commented Aug 13, 2024

duration_sum

I think the filter processor can't do that.

I understand that these are the basic key indicators that cannot be filtered? Is there any other way? I thought of, for example, adding different labels to different indicators, and then filtering out the metric by label? Because I really don't want duration_bucket and duration_count to exist, because it consumes a lot of resources.

Copy link
Contributor

This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping @open-telemetry/collector-contrib-triagers. If this issue is still relevant, please ping the code owners or leave a comment explaining why it is still relevant. Otherwise, please close it.

Pinging code owners:

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

@github-actions github-actions bot added the Stale label Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
connector/spanmetrics discussion needed Community discussion needed processor/filter Filter processor question Further information is requested Stale
Projects
None yet
Development

No branches or pull requests

4 participants