metrics-rs / metrics

A metrics ecosystem for Rust.
MIT License
1.08k stars 148 forks source link

Allow final push at exit when using prometheus-push-gateway #413

Open nstinus opened 9 months ago

nstinus commented 9 months ago

For short lived batch processes, a periodic push isn't sufficient and ideally we want to push the metrics right before exiting. AFAICT, one would need to call Prometheus.render() and push manually. Since everything is in place, perhaps a PrometheusHandle.push() could be exposed. Additionally, a flag in PrometheusBuilder::with_push_gateway(..., at_exit = true | false) to try a push during a drop?

tobz commented 9 months ago

Yeah, this is a little tricky because there's no existing mechanism for having asynchronous Drop logic, so it would definitely have to be a method on PrometheusHandle that allows for triggering a push if the push gateway mode is enabled.

Time is tight/precious for me at the moment, so no idea when I'd be able to get to this, but I'm willing to accept a PR and guide the design of it if that's something you're interested in.