Prometheus Relabel Config Not Working Fix
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
promtoolbefore deploying - Use
action: keepandaction: dropto filter targets - Use
action: labeldropandaction: labelkeepto manage labels - Check the Targets page in Prometheus UI for debugging
- Remember
__meta_labels are internal and never persisted
Common Mistakes with relabel
- Mixing let bindings with <- bindings in do notation, producing type errors
- Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
- 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
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro