tikv / rust-prometheus

Prometheus instrumentation library for Rust applications
Apache License 2.0
1.07k stars 182 forks source link

Support time stamps when exporting metrics #423

Closed Mikadore closed 2 years ago

Mikadore commented 2 years ago

Is your feature request related to a problem? Please describe. In order to backfill metrics into prometheus, time stamps are needed. Currently, this crate doesn't provide a way to add time stamps when exporting using either ProtobufEncoder or TextEncoder

Describe the solution you'd like Add a method to ProtobufEncoder and TextEncoder, perhaps something like encode_with_timestamp.

Describe alternatives you've considered Hacking around manually with exported metrics. This is error prone, but also a feature that falls within the use case of this crate.

Mikadore commented 2 years ago

This can be done using:

        metric_families
            .into_iter()
            .map(|mut fam| {
                for metric in fam.mut_metric() {
                    metric.set_timestamp_ms(timestamp)
                }
                fam
            })
            .collect()
lucab commented 2 years ago

Welcome and thanks for the report. Are you maybe chasing the same feature request as https://github.com/tikv/rust-prometheus/issues/382?

Mikadore commented 2 years ago

Welcome and thanks for the report. Are you maybe chasing the same feature request as #382?

Hello, yes, it seems I didn't search carefully enough. Thanks :D