Skip to content

Prometheus Relabel Config Not Working Fix

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about Prometheus Relabel Config Not Working Fix. We cover key concepts, practical examples, and best practices.

Your Prometheus labels are wrong — __meta_ labels aren't dropped, metric labels are missing, or relabeling doesn't produce the expected output. Prometheus relabel configs are powerful but easy to misconfigure.

The Problem

# WRONG — trying to drop a label with the wrong action
scrape_configs:
  - job_name: 'kubernetes-pods'
    kubernetes_sd_configs:
      - role: pod
    relabel_configs:
      - source_labels: [__meta_kubernetes_pod_phase]
        regex: Succeeded|Failed
        action: drop
      - target_label: __meta_kubernetes_pod_name
        action: labeldrop

The __meta_ labels are internal and not persisted to storage at all — Prometheus drops them automatically. The second relabel action is unnecessary.

Step-by-Step Fix

1. Understand the relabeling order

relabel_configs:
  # 1. First: drop targets based on meta labels
  - source_labels: [__meta_kubernetes_pod_phase]
    regex: Succeeded|Failed
    action: drop

  # 2. Then: set the instance label from meta
  - source_labels: [__meta_kubernetes_pod_name]
    target_label: instance

  # 3. Then: add a custom label
  - target_label: team
    replacement: platform

2. Use the correct action

# Drop targets (entire target is excluded)
relabel_configs:
  - source_labels: [__address__]
    regex: '.*\.internal\.example\.com'
    action: drop

# Keep only matching targets
  - source_labels: [__meta_kubernetes_namespace]
    regex: production
    action: keep

# Replace a label value
  - source_labels: [__meta_kubernetes_pod_label_app]
    target_label: application
    action: replace

# Drop a specific label from stored metrics
  - regex: 'temp_.*'
    action: labeldrop

# Keep only specific labels
  - regex: '(instance|job|team)'
    action: labelkeep

3. Debug with __meta_ labels

# Add all meta labels as a debug metric
relabel_configs:
  - source_labels: [__meta_kubernetes_pod_label_app]
    target_label: app

Check the Prometheus /targets page to see the Prometheus-scraped labels including __meta_.

4. Test relabeling with promtool

promtool test rules relabel-test.yml

Or use the Prometheus targets page to inspect the final labels after relabeling.

Expected output in Prometheus targets:

Labels before relabeling:
  __meta_kubernetes_pod_name: "web-abc123"
  __meta_kubernetes_pod_phase: "Running"
  __address__: "10.0.0.5:8080"

Labels after relabeling:
  instance: "web-abc123"
  application: "web-frontend"
  job: "kubernetes-pods"

Prevention Tips

  • Test relabel configs with promtool before deploying
  • Use action: keep and action: drop to filter targets
  • Use action: labeldrop and action: labelkeep to manage labels
  • Check the Targets page in Prometheus UI for debugging
  • Remember __meta_ labels are internal and never persisted

Common Mistakes with relabel

  1. Mixing let bindings with <- bindings in do notation, producing type errors
  2. Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
  3. Non-exhaustive pattern matches that compile with warnings then crash at runtime

These mistakes appear frequently in real-world PROMETHEUS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why are my __meta_ labels showing in stored metrics?

They shouldn't be. __meta_ labels are internal to service discovery and automatically dropped by Prometheus after relabeling. If you see them in stored data, you explicitly mapped them to a non-underscore-prefixed label with target_label.

What's the order of relabeling operations?

Relabel configs run in order: metric_relabel_configs (after scrape, before storage), relabel_configs (before scrape, on target discovery). Within each list, configs execute top to bottom. The replace action runs before labeldrop in the same list.

How do I preserve original metric names after relabeling?

Use action: replace with target_label: __name__ to rename metrics. Use replacement: 'prefix_${1}' in source_labels to add a prefix. For complex renaming, use multiple relabel rules with regex capturing groups.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro