implement OpenMetrics support for real #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 pathon an interval, which is currently hardcoded to 1 minute.
No guarantees here. I'm not sure if the transformation is done correctly.