Skip to content

[metrics] No scrape-output integration test — exporter Prometheus format compliance unverified #224

@obchain

Description

@obchain

Refs #50

File: crates/charon-metrics/tests/ (new)

Problem

Existing tests verify exporter binds an HTTP listener and that typed helpers don't panic. No test:

  1. Records a counter/histogram observation
  2. Scrapes /metrics
  3. Asserts response contains expected # HELP, # TYPE, and metric lines per Prometheus text format

Without this, breakages in metrics crate version upgrade, label key changes, or histogram bucket ordering will only surface in production.

Fix

Add integration test in crates/charon-metrics/tests/scrape.rs:

#[tokio::test]
async fn scrape_returns_valid_prometheus_text() {
    let cfg = MetricsConfig { enabled: true, bind: "127.0.0.1:0".to_string(), .. };
    init(&cfg).await.unwrap();
    record_block_observed("bnb");
    let body = reqwest::get("http://127.0.0.1:<port>/metrics").await.unwrap().text().await.unwrap();
    assert!(body.contains("# HELP charon_scanner_blocks_total"));
    assert!(body.contains("charon_scanner_blocks_total{chain=\"bnb\"} 1"));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    layer:rustRust crates (core / scanner / protocols / executor / cli)pr-reviewFindings from PR review processpriority:p2-polishNice-to-have / polishstatus:readyScoped and ready to pick uptype:testTests, fuzz, fork, integration

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions