Skip to content

feat: add support for additional labels on metrics#536

Open
rajsameer wants to merge 7 commits into
openstack-exporter:mainfrom
rajsameer:feat/rajsameer/enable-addtional-metrics-ironic
Open

feat: add support for additional labels on metrics#536
rajsameer wants to merge 7 commits into
openstack-exporter:mainfrom
rajsameer:feat/rajsameer/enable-addtional-metrics-ironic

Conversation

@rajsameer
Copy link
Copy Markdown

@rajsameer rajsameer commented Mar 4, 2026

Add generic --extra-labels flag for customising metric labels

Summary

Introduces a new --extra-labels CLI flag that allows operators to attach additional labels to any metric across all OpenStack service exporters, without requiring code changes. This
replaces the narrower, Ironic-specific --ironic.additional-labels approach with a generic solution.

Motivation

Users often need to enrich metrics with environment-specific context (e.g. rack ID, datacenter, environment name) that is available in OpenStack API responses but not exposed as
Prometheus labels by default. Previously, adding such labels required service-specific code changes per exporter.

Changes

New --extra-labels flag (main.go, utils/kingping_extra_labels_parser.go)

  • Accepts one or more --extra-labels=.: arguments (cumulative flag)
  • Supports two label types per invocation:
    • Dynamic labels — resolved from API response fields via dot-path (e.g. conductor, extra.rack_id → label name extra_rack_id)
    • Static/const labels — fixed key=value pairs appended to every metric sample (e.g. env=production)
  • Full validation: Prometheus label name constraints enforced, duplicates rejected
  • Example: --extra-labels=ironic.node:conductor,extra.rack_id,datacenter=dc1

Generic reflect-based field resolver (exporters/fields_cahce.go)

  • resolveField(obj, "extra.rack_id") — resolves dot-paths against any struct using a JSON-tag-keyed index; supports nested map[string]interface{} access
  • getFieldIndex — lazily built, thread-safe cache (sync.RWMutex with double-checked locking) keyed by reflect.Type, shared globally across all exporters
  • computeMetricLabels / computeConstantLabels — helpers used by all exporter constructors to append extra variable/const labels to metric descriptors

All service exporters updated

Extra label support added to all 15 exporters: ironic, cinder, nova, neutron, glance, keystone, loadbalancer, heat, placement, manila, designate, trove, gnocchi, containerinfra,
objectstore

Testing

  • utils/kingpin_parser_test.go — 10 new tests covering parsing, dot-path conversion, static labels, cumulative behaviour, error cases, and Extract
  • exporters/fields_cache_test.go — 21 new tests covering resolveField, computeMetricLabels, computeConstantLabels, and resolveExtraLabelValues
  • exporters/ironic_test.go — End-to-end integration test: creates an Ironic exporter with ironic.node:conductor,env=test and validates that all 5 fixture nodes carry both the dynamic
    conductor label and the static env="test" const label in the collected output

Usage

Add the conductor field and a static datacenter label to all ironic node metrics

openstack-exporter --extra-labels=ironic.node:conductor,datacenter=dc1 mycloud

Add a nested extra field and a static env label to ironic node metrics

openstack-exporter --extra-labels=ironic.node:extra.rack_id,env=production mycloud

Multiple services in one invocation (cumulative flag)

openstack-exporter
--extra-labels=ironic.node:conductor
--extra-labels=nova.server:hypervisor_hostname,region=eu-west
mycloud

@Sharpz7
Copy link
Copy Markdown
Collaborator

Sharpz7 commented Mar 4, 2026

This is really cool! I had envisioned this in #386.

I wonder if this can be extended more widely

@rajsameer
Copy link
Copy Markdown
Author

@Sharpz7 instead of additional labels how about overriding labels. Let me take some time and implement it for all metrics.
exporter users will then have a way to add or remove labels customizing their metrics

@Sharpz7 Sharpz7 added the priority Priority PR or Issue to help with tracking. label Mar 6, 2026
@rajsameer
Copy link
Copy Markdown
Author

@Sharpz7 can you review the PR

@Sharpz7
Copy link
Copy Markdown
Collaborator

Sharpz7 commented Mar 25, 2026

Hey @rajsameer. I will try to get to it ASAP

@Sharpz7 Sharpz7 changed the title feat: add support for additional labels on ironic node metrics feat: add support for additional labels on metrics Apr 6, 2026
@Sharpz7
Copy link
Copy Markdown
Collaborator

Sharpz7 commented Apr 6, 2026

@rajsameer are you able to provide some results from a devstack with this working?

@rajsameer
Copy link
Copy Markdown
Author

@rajsameer are you able to provide some results from a devstack with this working?

I am using the exporter for ironic metrics, I do not have all components of openstack. Do you need the metrics output?

@Sharpz7
Copy link
Copy Markdown
Collaborator

Sharpz7 commented Apr 13, 2026

Its more that I would like this tested before we merge it. In a devstack, or potentially integration tests when #481 lands.

I appreciate you have already put a lot of work in, so I'll try my best to help out getting this merged.

@rajsameer
Copy link
Copy Markdown
Author

Its more that I would like this tested before we merge it. In a devstack, or potentially integration tests when #481 lands.

I appreciate you have already put a lot of work in, so I'll try my best to help out getting this merged.

hey sorry for the late reply did not get time from work. I will try to get the verification done in few days.

@Sharpz7 Sharpz7 removed the priority Priority PR or Issue to help with tracking. label May 8, 2026
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.

2 participants