prometheus / prometheus

The Prometheus monitoring system and time series database.
https://prometheus.io/
Apache License 2.0
55.11k stars 9.07k forks source link

Support JSON marshalling interface #11816

Open jaronoff97 opened 1 year ago

jaronoff97 commented 1 year ago

Proposal

Right now, Prometheus only supports marshaling via YAML through the following interfaces:

This causes an issue for a user trying to serialize a scrape config to JSON as we try to do in the OpenTelemetry world here. Right now we have to serialize to YAML first, and then serialize that to JSON. Would it be welcome to add methods to prometheus scrape config fields (and their sub-fields) to adhere to the following interface

roidelapluie commented 1 year ago

Thank you for your suggestion to add support for marshaling via JSON in Prometheus. I understand the need for this feature, and I agree that it would be useful for you to have the option to serialize configs to JSON.

However, I have to consider the complexity and maintenance burden of adding this feature. Currently, we only support marshaling via YAML, and adding support for JSON marshaling would require significant changes to the codebase. In addition, we do not support full marshaling even in YAML - secrets are not marshallable. Furthermore, the basic JSON marshaling in the prometheus/common package has proven to be more complex than expected, as demonstrated in this pull request: https://github.com/prometheus/common/pull/394

Given these considerations, as well as our general preference to avoid adding dead code, I don't think we should support full marshaling to JSON at this time.