Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom encoder? #46

Closed
ackintosh opened this issue Feb 8, 2022 · 7 comments · Fixed by #83
Closed

Custom encoder? #46

ackintosh opened this issue Feb 8, 2022 · 7 comments · Fixed by #83

Comments

@ackintosh
Copy link
Contributor

I would like to send (partial) metrics stored the Registry in original JSON format differ from OpenMetrics, into an endpoint different from Prometheus server.

Here is a pseudo code, shows what I want to do:

        let mut registry = <Registry>::default();

        // (omitted)

        // Using the OpenMetrics format.
        let mut buffer = vec![];
        encode(&mut buffer, &registry).unwrap();

        // On the other hand, send (partial) metrics in JSON, into an endpoint different from Prometheus server.
        let mut data = vec![];
        for (descriptor, metric) in registry.iter() {
            if descriptor.name() == "__test__" {
                data.push(
                    translate_to_json(metric), // original JSON format
                );
            }
        }
        send(data); // send to an endpoint different from Prometheus server

I think I need to implement custom encoder, translate metrics to JSON format.

Please let me know if there is any good way. 🙏

@mxinden
Copy link
Member

mxinden commented Feb 9, 2022

👋 Hi @ackintosh,

I think I need to implement custom encoder, translate metrics to JSON format.

Yes, you would need to implement something along the lines of https://github.com/prometheus/client_rust/blob/master/src/encoding/text.rs.

Though lots of the internals you would need are not exposed to the outside. Is this a well known format you are referring to? Would it make sense to contribute it to the library? Or would it maybe make sense to add the OpenMetrics protobuf format to this library which you could then consume and convert to your JSON output?

@ackintosh
Copy link
Contributor Author

Hi @mxinden !

Is this a well known format you are referring to?

As a background of I've file this issue, I'm working on this issue.

The metrics I would like to send to somewhere in JSON is defined as Ethereum consensus client metrics and Beacon chain metrics.

Would it make sense to contribute it to the library? Or would it maybe make sense to add the OpenMetrics protobuf format to this library which you could then consume and convert to your JSON output?

I think the latter would be good as we can convert the metrics to JSON. though I'm not familiar with the OpenMetrics protobuf format for now. 💦

@mxinden
Copy link
Member

mxinden commented Feb 16, 2022

I think the latter would be good as we can convert the metrics to JSON. though I'm not familiar with the OpenMetrics protobuf format for now. sweat_drops

I would guess that most prometheus-client users don't need to expose their metrics in the Ethereum format. With that in mind, using the OpenMetrics protobuf format as an adapter sounds good to me.

https://github.com/OpenObservability/OpenMetrics should be a good first starting point.

@peterbourgon
Copy link

The metrics I would like to send to somewhere in JSON is defined as Ethereum consensus client metrics and Beacon chain metrics.

This is out of scope for this crate.

@ackintosh
Copy link
Contributor Author

I believe too that it make sense to add the OpenMetrics protobuf format to prometheus-client. ✨

https://github.com/OpenObservability/OpenMetrics should be a good first starting point.

Thank you for the pointer! That helped a lot.

And I have noticed that prometheus-client doesn't support the OpenMetrics protobuf format due to the issue. 👀

https://github.com/prometheus/client_rust#specification-compliance

Specification Compliance

@mxinden
Copy link
Member

mxinden commented Feb 19, 2022

And I have noticed that prometheus-client doesn't support the OpenMetrics protobuf format due to the issue. eyes

That was the thing that stopped me from working on Protobuf support in prometheus-client back then. With the latest comments on the issue in mind, I am not sure this is still a blocker. Would you mind giving it a try, i.e. add support for Protobuf to prometheus-client?

@ackintosh
Copy link
Contributor Author

Yes, I will try to add support for Protobuf. Will file a PR later. 🚀

@ackintosh ackintosh mentioned this issue Feb 24, 2022
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants