metrics-rs / metrics

A metrics ecosystem for Rust.
MIT License
1.1k stars 151 forks source link

Add PrometheusHandle::compact #364

Closed elbaro closed 1 year ago

elbaro commented 1 year ago

245

Expose get_recent_metrics() so users don't have to call render() to save the memory.

tobz commented 1 year ago

I don't think this PR adequately solves the referenced issue. Forcing using to have to call PrometheusHandle::compact, and doing so on an interval, is just extra work that the exporter could be doing itself.

I'd be happy to accept this PR if it was changed such that the futures it generates for exposing/driving a scrape endpoint (i.e. the 2nd value in the return value tuple here) also drove metrics collection on an interval, perhaps by spawning a standalone Tokio task that used PrometheusHandle.

elbaro commented 1 year ago

Closing this PR as I would rather not implement more complex logic for sub-optimal solution. (We should use finite memory without the need for tuning the scrape interval) A built-in periodic scrape API can work for some cases, but I still have to adapt my scrape period when there are more external events out of my control.