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

implement OpenMetrics support for real #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vroldanbet
Copy link

@vroldanbet vroldanbet commented Oct 4, 2024

I discovered that thanos-federate-proxy lies about its capabilities: it's not truly OpenMetrics compliant.

The prometheus metrics scrape endpoint representation differs from OpenMetrics in subtle ways. This makes consumers that only support OpenMetrics fail to scrape anything produced by thanos-federate-proxy.

I don't think this is a good idea but I wanted to see if it was technically possible. I also don't know if this is a stupid contortion or if there is a better way to achieve it.

thanos-federate-proxy retrieves from the upstream using Prometheus Query API. This API returns model.Value, which is a wire representation that does not have all the same information presented in a scrape endpoint (MetricsFamily). If we transformed to MetricsFamily somehow, we would be able to use the expfmt package from prometheus/common library that has the official bits for content negotiation and serialization into the scrape endpoint textual representation.

So the challenge here
was how to transform model.Value to MetricsFamily. I discovered Prometheus offers Metadata API, which gives us the missing bits. Unfortunately, Thanos does not expose this API, so this commit requires you to wire up the metadata API through the upstream prometheus. API Queries will hit Thanos, and metadata API calls will hit prometheus. The latter is done outside the critical path
on an interval, which is currently hardcoded to 1 minute.

No guarantees here. I'm not sure if the transformation is done correctly.

@vroldanbet vroldanbet self-assigned this Oct 4, 2024
I discovered that thanos-federate-proxy lies about its
capabilities: it's not truly OpenMetrics compliant.

The prometheus metrics scrape endpoint representation
differs from OpenMetrics in subtle ways. This makes consumers
that only support OpenMetrics fail to scrape anything produced
by thanos-federate-proxy.

I don't think this is a good idea, but I wanted to see if it was
technically possible. I also don't know if this is a dumb
contortion or if there is a better way to achieve it.

thanos-federate-proxy retrieves from the upstream using
Prometheus Query API. This API returns `model.Value`, which
is a wire representation that does not have all the same information
presented in a scrape endpoint (MetricsFamily). If we transformed
to MetricsFamily _somehow_, we would be able to use the `expfmt`
package from `prometheus/common` module that has the official bits
for content negotiation and serialization into the
scrape endpoint textual representation.

So the challenge here
was how to transform `model.Value` to MetricsFamily.
I discovered Prometheus offers Metadata API, which gives us the missing
bits. Unfortunately, Thanos does not expose this API, so this commit
requires you to wire up the metadata API through the upstream prometheus.
API Queries will hit Thanos, and metadata API calls will hit prometheus.
The latter is done outside the critical path on an interval, which is currently
hardcoded to 1 minute.

No guarantees here. I'm not sure if the transformation is done correctly.
@vroldanbet vroldanbet force-pushed the support-open-metrics-for-real branch from bc04d9a to 481efb5 Compare October 4, 2024 10:26
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 this pull request may close these issues.

1 participant