Interview Prep/Monitoring & Observability/Scaling Prometheus, Long-Term Storage & HA

How do you shard Prometheus scraping, and what do you lose?

AdvancedProductionScaling Prometheus, Long-Term Storage & HA
Answer

Use hashmod relabelling so each server keeps a subset of targets, or the Prometheus Operator shards field, which does the same automatically:

relabel_configs:
  - source_labels: [__address__]
    modulus: 4
    target_label: __tmp_hash
    action: hashmod
  - source_labels: [__tmp_hash]
    regex: "2"
    action: keep

You lose a single query view and cross-shard recording rules/alerts. You need a query layer (Thanos Query, Mimir, Promxy) on top, and alert rules that need the global view must move there.

All Monitoring & Observability questions Roadmap: Monitoring & alerting

More on Scaling Prometheus, Long-Term Storage & HA