Lesson 8 of 9 · 25m
Building Observability Pipelines with Relabeling and OpenTelemetry
Route, transform, and govern metrics as they cross agents, collectors, and storage backends without silently mutating operational meaning.
The first observability pipeline in most organizations is accidental: application to Prometheus to Grafana. The second arrives when someone needs multi-cluster forwarding, vendor migration, tenant filtering, or OpenTelemetry interoperability. Once metrics cross intermediate systems, you own a data pipeline. Treat it like one: schema, backpressure, transformation discipline, and auditability.
Prometheus relabeling is powerful and opaque
Relabeling happens at several stages. Target relabeling decides which targets are scraped and what labels they carry. Metric relabeling acts on samples after scrape. Write relabeling acts before remote write.
write_relabel_configs:
- source_labels: [__name__]
regex: "go_goroutines|process_cpu_seconds_total"
action: keepThis example keeps only two metric names, which is almost certainly too aggressive for production. That is the point: a small rule can silently discard most of your observability. Always emit metrics about drops and review changes with the same care as database migrations.
OpenTelemetry changes the collection shape
OpenTelemetry collectors can receive OTLP metrics, transform attributes, batch data, and export to Prometheus remote write or other systems:
receivers:
otlp:
protocols:
grpc:
http:
processors:
batch:
timeout: 5s
send_batch_size: 2000
memory_limiter:
check_interval: 1s
limit_mib: 512
spike_limit_mib: 128
exporters:
prometheusremotewrite:
endpoint: https://mimir-gateway.internal/api/v1/push
tls:
insecure_skip_verify: false
service:
pipelines:
metrics:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [prometheusremotewrite]Batching improves efficiency and worsens loss granularity. A memory limiter protects the collector but creates explicit pressure. Those are design choices, not YAML decoration.
Attribute translation is semantic work
OpenTelemetry resource attributes and Prometheus labels do not map perfectly. Consider:
service.name -> job or service
k8s.namespace.name -> namespace
cloud.region -> region
deployment.environment -> environmentIf two systems disagree about whether service.name becomes job, dashboards split apart and alerts miss series. Write the mapping down. Version it. Test it with known fixtures.
Pipeline stages need ownership boundaries
A sane metrics pipeline often looks like:
application/exporter
-> scrape or OTLP receiver
-> local normalization and safety filtering
-> durable queue or remote write
-> tenant-aware ingestion
-> rule evaluation
-> storage tiers
-> query and alertingAt every arrow ask: what happens when the receiver is down, slow, or rejecting data? Is data buffered in memory, disk, or nowhere? Are retries idempotent? Which team owns the failure?
Backpressure is better than silent loss
Metrics are often treated as expendable, but silent loss destroys trust. Prefer explicit behavior:
memory queue fills -> reject with retryable error and increment dropped metric
remote write 5xx -> retry with backoff
remote write 4xx -> do not blindly retry malformed data forever
series limit exceeded -> reject offending tenant stream, keep platform alive
disk buffer fills -> page operator before data lossExport self-metrics for every collector and gateway: received samples, sent samples, failed batches, queue size, rejected series, latency.
Do not centralize all policy in one invisible layer
Pipelines are attractive places to 'fix' cardinality, naming, and tenancy. Some guardrails belong there, but transformations invisible to application teams create confusion. The best pattern is layered: instrumentation standards in libraries, safety limits in collectors, tenant isolation in gateways, and documented exceptions in version control.
Field notes
- A relabel
keepbehaves like a denylist for everything not matching. Most operators meandropfar more often than they meankeep. - Test collector memory under cardinality spikes, not merely under high sample throughput.
- Batched export can delay alert-visible data; batching deadlines are latency decisions.
- TLS configuration is part of pipeline correctness.
insecure_skip_verifyin production is a finding, not convenience. - Record pipeline version and configuration hash as metrics or metadata so incidents can correlate with deployments.
Was this lesson helpful?