Skip to content

The PodMonitoring metricRelabeling do not work correctly #1753

Description

@almeida-silas

While migrating from OperatorConfig to PodMonitoring, I’m using metricRelabeling to keep a small allowlist of metric names. Most names are scraped as expected, but a few specific ones are not scraped when the same pattern works with OperatorConfig.

These two metric families are missing when configured via PodMonitoring:

workqueue_(queue_duration_seconds_bucket|work_duration_seconds_bucket)
controller_runtime_(duration_seconds_bucket)

Other names in the same alternation are scraped correctly (e.g., go_info, rest_client_requests_total, leader_election_master_status, controller_runtime_reconcile_total, controller_runtime_max_concurrent_reconciles, workqueue_depth, workqueue_adds_total, workqueue_retries_total).

What did I expect to happen?

The PodMonitoring metricRelabeling regex should keep the exact same set of metric names that are successfully kept by the OperatorConfig filter.matchOneOf configuration (shown below), including the two families above.

How to reproduce

Create a PodMonitoring with metricRelabeling that keeps the following set of metric names:

apiVersion: monitoring.googleapis.com/v1
kind: PodMonitoring
metadata:
  name: example
  namespace: default
spec:
  selector:
    matchLabels:
      app: my-app
  endpoints:
    - port: metrics
      interval: 30s
      metricRelabeling:
        - sourceLabels: [__name__]
          action: keep
          # also tried without anchors
          regex: ^(go_info| rest_client_requests_total|leader_election_master_status|workqueue_(queue_duration_seconds_bucket|work_duration_seconds_bucket|depth|adds_total|retries_total)|controller_runtime_(duration_seconds_bucket|reconcile_total|max_concurrent_reconciles))$

Observe that:
go_info, rest_client_requests_total, leader_election_master_status are present.

These are missing:
workqueue_queue_duration_seconds_bucket,
workqueue_work_duration_seconds_bucket,
controller_runtime_duration_seconds_bucket.

Try a simplified rule to isolate one family (still missing):

metricRelabeling:
  - sourceLabels: [__name__]
    action: keep
    regex: workqueue_(queue_duration_seconds_bucket|work_duration_seconds_bucket)

Compare with OperatorConfig, where the same allowlist works as expected:

apiVersion: monitoring.googleapis.com/v1
kind: OperatorConfig
# ...
collection:
  filter:
    matchOneOf:
      - '{__name__=~"controller_runtime_(duration_seconds_bucket|reconcile_total|max_concurrent_reconciles)"}'
      - '{__name__=~"go_info"}'
      - '{__name__=~"leader_election_master_status"}'
      - '{__name__=~"rest_client_requests_total"}'
      - '{__name__=~"workqueue_(queue_duration_seconds_bucket|work_duration_seconds_bucket|depth|adds_total|retries_total)"}'

What I’ve already tried

Removing ^/$ anchors.
Using a single-family regex (e.g., only workqueue_(queue_duration_seconds_bucket|work_duration_seconds_bucket)).
Matching the exact metric name directly, (e.g., workqueue_queue_duration_seconds_bucket or controller_runtime_duration_seconds_bucket)
Verifying the metrics do exist on the target endpoint via

curl -s http://localhost:8080/metrics | grep -E 'workqueue_work_duration_seconds_bucket'

Confirmed that other families in the exact same alternation are kept.

Environment

GKE / K8s version: v1.32.2-gke.1182003
prometheus-engine / GMP collector version: operator:v0.15.3-gke.0


The behavior difference is only between OperatorConfig.filter.matchOneOf and PodMonitoring.spec.endpoints[*].metricRelabeling.

It looks like metricRelabeling is evaluated, but certain names that should match the alternation aren’t being kept, while others are.

If there are known limitations or differences in regex dialect/evaluation order between OperatorConfig and PodMonitoring relabeling, guidance would be appreciated.

Thanks for taking a look!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions