Skip to content

[prometheus-json-exporter] Support full relabeling spec in additionalMetricsRelabels#6994

Open
alien2003 wants to merge 2 commits into
prometheus-community:mainfrom
alien2003:prometheus-json-exporter-relabel-spec
Open

[prometheus-json-exporter] Support full relabeling spec in additionalMetricsRelabels#6994
alien2003 wants to merge 2 commits into
prometheus-community:mainfrom
alien2003:prometheus-json-exporter-relabel-spec

Conversation

@alien2003

Copy link
Copy Markdown

What this PR does / why we need it

The serviceMonitor additionalMetricsRelabels value only accepts a map of
targetLabel: replacement pairs, each rendered as a replace metric
relabeling. That excludes the rest of the Prometheus relabeling spec (regex,
sourceLabels, drop/keep, labelmap, and so on).

This change lets additionalMetricsRelabels also accept a list of full
relabeling objects, rendered verbatim after the two built-in instance/target
relabelings. It mirrors how additionalRelabels already handles relabelings
in the same template. The value type is detected with kindIs "slice", which
is already used elsewhere in the repo (kube-state-metrics,
kube-prometheus-stack).

serviceMonitor:
  targets:
    - name: example
      url: http://example.com/healthz
      # map form (unchanged)
      additionalMetricsRelabels:
        team: backend
    - name: example2
      url: http://example.com/metrics
      # list form (new)
      additionalMetricsRelabels:
        - sourceLabels: [__name__]
          regex: 'go_.*'
          action: drop

Both per-target and serviceMonitor.defaults accept either form, with the
per-target value taking precedence as before. The map form renders identical
output to today, so this is backward compatible and bumped as a minor version.

A servicemonitor unittest suite is added (the chart had none) covering the map
form, the list form, defaults precedence, and empty map/list inputs.

Which issue this PR fixes

Special notes for your reviewer

Verified with the pinned CI tooling:

helm unittest --strict --file 'unittests/**/*.yaml' charts/prometheus-json-exporter
ct lint --charts charts/prometheus-json-exporter

Checklist

  • DCO signed
  • Chart Version bumped
  • Title of the PR starts with chart name (e.g. [prometheus-couchdb-exporter])

…MetricsRelabels

The serviceMonitor additionalMetricsRelabels value only accepted a map of
targetLabel/replacement pairs, each rendered as a `replace` metric relabeling.
This rules out regex, sourceLabels, drop/keep and the rest of the Prometheus
relabeling spec.

Accept a list of full relabeling objects in addition to the existing map, the
same way additionalRelabels already works in this template. The map form is
unchanged, so this is backward compatible. Add a servicemonitor unittest suite
covering both forms, their precedence via defaults, and empty inputs.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: alien2003 <alien2003@protonmail.ch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[prometheus-json-exporter] additionalMetricsRelabels: support full relabeling spec (regex, sourceLabels, actions)

2 participants