Skip to content

feat(prometheus): support disabling labels and metrics to reduce cardinality#13202

Draft
janiussyafiq wants to merge 4 commits intoapache:masterfrom
janiussyafiq:feat/prom-disable-metrics
Draft

feat(prometheus): support disabling labels and metrics to reduce cardinality#13202
janiussyafiq wants to merge 4 commits intoapache:masterfrom
janiussyafiq:feat/prom-disable-metrics

Conversation

@janiussyafiq
Copy link
Copy Markdown
Contributor

Description

Add two new per-metric configuration options to the Prometheus plugin's plugin_attr:

  • disable_labels: A list of built-in label names to drop from a metric, reducing cardinality without changing the metric schema for other labels.
  • disable: A boolean flag to skip registering an entire metric, removing it from /metrics output entirely.

Both options are configured under plugin_attr.prometheus.metrics.<metric_name> alongside the existing expire and extra_labels fields.

Example config:

  plugin_attr:                                                                                                                           
    prometheus:   
      metrics:
        http_status:
          disable_labels:
            - node
            - consumer                                                                                                                   
        bandwidth:
          disable: true

This addresses high-cardinality issues in dynamic environments (e.g. Kubernetes autoscaling where pod IPs churn rapidly), which can cause prometheus shared dict overflow and excessive memory consumption.

Which issue(s) this PR fixes:

Fixes #12679

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

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.

feat: Apisix Prometheus metrics - Disable unneeded labels/metrics

1 participant