open-telemetry / opentelemetry-collector-contrib

Contrib repository for the OpenTelemetry Collector
https://opentelemetry.io
Apache License 2.0
2.87k stars 2.24k forks source link

Metric Filter using include/exclude syntax not filtering properly using metric labels/attributes #34072

Open maximillianus opened 1 month ago

maximillianus commented 1 month ago

Component(s)

No response

What happened?

Description

Metric Filter using include/exclude syntax not filtering properly using metric labels/attributes

Steps to Reproduce

My config.yml

receivers:
  hostmetrics:
    collection_interval: 10s
    scrapers:
      cpu:
        metrics:
          system.cpu.time:
            enabled: true

processors:
  filter/metric_attr:
    error_mode: ignore
    metrics:
      include:
        match_type: expr
        expressions:
          - Label("cpu") == "^cpu0$"

exporters:
  prometheus:
    endpoint: localhost:8889
    namespace: otel-host-metrics

service:
  telemetry:
    logs:
      level: debug
  pipelines:
    metrics:
      receivers: [hostmetrics]
      processors: [filter/metric_attr]
      exporters: [prometheus]

Expected Result

# HELP otel_host_metrics_system_cpu_time_seconds_total Total seconds each logical CPU spent on each mode.
# TYPE otel_host_metrics_system_cpu_time_seconds_total counter
otel_host_metrics_system_cpu_time_seconds_total{cpu="cpu0",state="idle"} 135036.14
otel_host_metrics_system_cpu_time_seconds_total{cpu="cpu0",state="interrupt"} 0
.
.
.

Actual Result

# HELP otel_host_metrics_system_cpu_time_seconds_total Total seconds each logical CPU spent on each mode.
# TYPE otel_host_metrics_system_cpu_time_seconds_total counter
otel_host_metrics_system_cpu_time_seconds_total{cpu="cpu0",state="idle"} 135036.14
otel_host_metrics_system_cpu_time_seconds_total{cpu="cpu0",state="interrupt"} 0
.
.
.
otel_host_metrics_system_cpu_time_seconds_total{cpu="cpu1",state="idle"} 135040.18
otel_host_metrics_system_cpu_time_seconds_total{cpu="cpu1",state="interrupt"} 0
.
.
.

Collector version

0.104.0

Environment information

Environment

OS: Amazon Linux 2023 Compiler(if manually compiled): (e.g., "go 14.2")

OpenTelemetry Collector configuration

receivers:
  hostmetrics:
    collection_interval: 10s
    scrapers:
      cpu:
        metrics:
          system.cpu.time:
            enabled: true

processors:
  filter/metric_attr:
    error_mode: ignore
    metrics:
      include:
        match_type: expr
        expressions:
          - Label("cpu") matches "^cpu0$"

exporters:
  prometheus:
    endpoint: localhost:8889
    namespace: otel-host-metrics

service:
  telemetry:
    logs:
      level: debug
  pipelines:
    metrics:
      receivers: [hostmetrics]
      processors: [filter/metric_attr]
      exporters: [prometheus]

Log output

debug        processor@v0.104.0/processor.go:306        Alpha component. May change in the future.        {"kind": "processor", "name": "filter/metric_attr", "pipeline": "metrics"}

info        filterprocessor@v0.104.0/metrics.go:98        Metric filter configured        {"kind": "processor", "name": "filter/metric_attr", "pipeline": "metrics", "include match_type": "expr", "include expressions": [Label(\"cpu\") == \"cpu0\""], "include metric names": [], "include metrics with resource attributes": null, "exclude match_type": "", "exclude expressions": [], "exclude metric names": [], "exclude metrics with resource attributes": null}

Additional context

No response

github-actions[bot] commented 1 month ago

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