Skip to content
Novus Examples
yaml1.4 KB

Prometheus Scrape Config — Relabelling and Federation (yaml)

Three scrape jobs with the parts that actually matter: relabel_configs rewriting a target label with a capture group, metric_relabel_configs dropping the two unbounded labels from the cardinality fixture, honor_timestamps for the textfile collector and a federation job with a match[] selector.

Preview — first 50 linesyaml
# Prometheus scrape configuration for the shop namespace.
global:
  scrape_interval: 15s
  scrape_timeout: 10s
  evaluation_interval: 30s
  external_labels:
    cluster: shop-staging
    region: eu-west-1

rule_files:
  - /etc/prometheus/rules/*.yaml

scrape_configs:
  - job_name: shop-services
    metrics_path: /metrics
    scheme: http
    static_configs:
      - targets:
          - 192.0.2.11:9090
          - 192.0.2.12:9090
          - 192.0.2.21:9090
          - 192.0.2.22:9090
          - 192.0.2.31:9090
        labels:
          env: staging
    relabel_configs:
      - source_labels: [__address__]
        regex: '192\.0\.2\.(\d+):\d+'
        target_label: host_octet
        replacement: node-${1}
    metric_relabel_configs:
      # Drop the two unbounded labels that produced the cardinality fixture.
      - source_labels: [__name__]
        regex: api_request_duration_seconds_count
        action: labeldrop
      - regex: '(customer_id|session_id)'
        action: labeldrop
      - source_labels: [__name__]
        regex: 'go_memstats_.*'
        action: drop

  - job_name: node-exporter-textfile
    metrics_path: /metrics
    honor_timestamps: true
    static_configs:
      - targets: [192.0.2.11:9100]

  - job_name: federated
    honor_labels: true
    metrics_path: /federate
56 lines total — download for the full file.

Specifications

Jobs
3
Targets
7
Relabel Rules
1
Metric Relabel Rules
3
Has Federation
true
Honor Timestamps
true
Drops Cardinality Labels
true

Testing contract

Expected to pass
Scenario
Load the configuration and apply its relabelling rules to the cardinality fixture.
Expected result
Three jobs and seven targets load, and applying the labeldrop rules to the 2,000-series fixture collapses it to the bounded label set of service, route and region.

What is a .yaml file?

YAML (YAML Ain't Markup Language) is a human-readable data-serialization format using indentation, key-value pairs, and lists, and is a superset of JSON. It supports comments, anchors, and multiple documents per file, favoring readability for configuration. Its indentation sensitivity makes it error-prone to hand-edit.

How to use this file

Use an example YAML file to test config parsers, indentation and anchor handling, multi-document streams, and safe-loading to avoid arbitrary object construction.

How to use this file for testing

“Prometheus Scrape Config — Relabelling and Federation (yaml)” is a deterministic Novus Examples fixture for Observability, Config parsing, Config testing. Structured and plain-text telemetry with known timestamps, levels, request identifiers, and error states for testing log ingestion, correlation, dashboards, and alert pipelines.

Documented properties for this file: YAML · 1,430 bytes. Compare results against paired or grouped companions on this page when present (clean↔damaged, searchable↔scanned, or format twins) so scores stay reproducible across runs.

Download the file once, keep the path stable in CI or local scripts, and treat the spec table as the contract: dimensions, seeds, field lists, and roles are intentional. Corrupt or invalid samples are labelled as such — expect parsers to fail loudly rather than silently accept them.

Telemetry fixtures use fixed trace IDs, span IDs, and timestamps so ingestion is reproducible run to run. Point your collector, parser, or query layer at the file and assert the documented span tree, metric families, or severity mix; service and host names are invented.

Code examples

import yaml  # pip install pyyaml

with open("prometheus-scrape-config.yaml") as f:
    data = yaml.safe_load(f)
print(data)

Generated by generation/observability.py. Free for any use, no attribution required — license.