Skip to content

examples/prometheus-metrics: missing call to run_upkeep()? #3426

@eest

Description

@eest
  • I have looked for existing issues (including closed) about this

Bug Report

I am looking at the example code for setting up prometheus metrics in https://github.com/tokio-rs/axum/blob/main/examples/prometheus-metrics/src/main.rs. It creates a handle like so:

PrometheusBuilder::new()
.set_buckets_for_metric(
Matcher::Full("http_requests_duration_seconds".to_string()),
EXPONENTIAL_SECONDS,
)
.unwrap()
.install_recorder()
.unwrap()
}

Reading the docs for https://docs.rs/metrics-exporter-prometheus/latest/metrics_exporter_prometheus/#upkeep-and-maintenance it states

However, when using lower-level builder methods PrometheusBuilder::build_recorder or PrometheusBuilder::install_recorder, this upkeep task is not spawned automatically. Users are responsible for keeping a handle to the recorder (PrometheusHandle) and calling the run_upkeep method at a regular interval.

I see no calls to run_upkeep() in the example code, is this something that should be added? From looking at upstream code it seems this is done like so:
https://docs.rs/metrics-exporter-prometheus/latest/src/metrics_exporter_prometheus/exporter/builder.rs.html#472-478:

let recorder_handle = handle.clone();
        tokio::spawn(async move {
            loop {
                tokio::time::sleep(upkeep_timeout).await;
                recorder_handle.run_upkeep();
            }
        });

Version

main

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions