Collector pattern
This is an implementation of a Collector trait for collecting all the Metric Families from one or more Registries to encode them all at once.
For example, this allows exporting metrics by combining a "long-running" Registry with a per-scrape Registry.
This is in response to #29, #49 and #73.
Implementation is rather crude, but the out-facing interface is basically unchaged.
I am sorry for the late reply. This is a neat solution. I did not think about abstracting a Registry.
Unfortunately a user can not use the Collector abstraction in combination with the Registry::sub_registry_with_xxx mechanism. I would expect this to be useful for users. Would you agree? This is similar to the suggestion in https://github.com/prometheus/client_rust/issues/29#issuecomment-1172877769.
I have to give this more thought. Have you had the chance to play with this approach instead?
Unfortunately a user can not use the Collector abstraction in combination with the Registry::sub_registry_with_xxx mechanism. I would expect this to be useful for users. Would you agree?
I'd have to get back to looking at this. Right now, it's not clear to me why that wouldn't work. The collector delegates the actual encoding to the Registry, so it's the Registry's business to deal with its subregistries, and I haven't touched that. There's a test checking for this, which passes.
https://github.com/prometheus/client_rust/blob/8b7ab5bff2b24ea75350ae5cd584ea341ba621f0/src/encoding/text.rs#L714
I'd have to check to make sure it doesn't somehow sidestep the issue.
This is similar to the suggestion in https://github.com/prometheus/client_rust/issues/29#issuecomment-1172877769.
That was actually my inspiration for this. The overall idea was to allow encode to take a bunch of Collectors instead of a Registry. But the user shouldn't have to deal with a Collector directly, just use the Registry as usual.
Cross referencing alternative proposal: https://github.com/prometheus/client_rust/pull/82
Implemented through https://github.com/prometheus/client_rust/pull/82. Let me know what you think. Closing here.