prometheus-engine icon indicating copy to clipboard operation
prometheus-engine copied to clipboard

feat: /api/v1/status/buildinfo endpoint (Grafana Compatibility)

Open yama6a opened this issue 1 year ago • 1 comments

Purpose

This PR will make the GMP frontend compatible with Grafana for alerting and recording rules. It will also enable the rule-evaluator to be used as a datasource, albeit only for alerting and recording rules.

Currently, Grafana won't attempt to import any rules without the /api/v1/status/buildinfo endpoint available. This PR adds it.

Adding the rule-evaluator as a Prometheus Datasource works as well with this feature. It produces an error when adding the datasource, due to it not implementing the /api/v1/query endpoint and its siblings. It does however succeed in importing the rules into Grafana. The GMP frontend will work without said error message.

Details

The /api/v1/status/buildinfo endpoint is used by Grafana in order to determine the "flavor" of a Prometheus Datasource (Mimir / Cortex / Vanilla Prometheus).

Under certain circumstances, Grafana also probes the endpoint /api/v1/rules/test/test and expects the content to contain the words "page not found", in order to determine whether the Prometheus Datasource implements the ruler-API, which would allow editing rules via the Grafana UI (which is not supported in vanilla Prometheus or GMP)

References

  • https://github.com/grafana/grafana/blob/65ce173d3fd4a98f7763200cdddb80009a23d59b/public/app/features/alerting/unified/api/buildInfo.ts#L150
  • https://github.com/grafana/grafana/blob/65ce173d3fd4a98f7763200cdddb80009a23d59b/public/app/features/alerting/unified/api/buildInfo.ts#L196
  • https://github.com/grafana/grafana/blob/65ce173d3fd4a98f7763200cdddb80009a23d59b/public/app/features/alerting/unified/api/ruler.ts#L142

yama6a avatar Oct 18 '24 12:10 yama6a

I don't have a strong opinion on the contents of the buildinfo endpoint. I just added what felt sensible for now. Feel free to suggest any changes. Leaving fields empty is fine as well, as it will still be Grafana Compatible.

The rules/test/test endpoint feels somewhat awkward to be implemented here, and tbh is more a failsafe than a necessity. If the buiidinfo endpoint is implemented properly, in theory Grafana shouldn't ping that endpoint. It just makes it less likely to break, if Grafana implements changes in future that would require it for non-Cortex non-Mimir setups. I'm fine removing it from here though.

yama6a avatar Oct 18 '24 13:10 yama6a

@bwplotka Can this be merged?

yama6a avatar Oct 31 '24 08:10 yama6a

@bwplotka

Thanks! I don't get how we got the 1.8 version as we depend on newer Prometheus/Prometheus code, but nevertheless what matters is what API the forwarded server supports. For now let's say what GMP supports and it's the latest Prometheus version, at least that's the aim (: at some point this could be a flag, but ok for now!

LGTM after that fix, sorry for lag!

No worries; I was referring to this: https://github.com/GoogleCloudPlatform/prometheus-engine/blob/main/go.mod#L27

But I might have misinterpreted the dependency. But what you say makes sense. We should reference the API version that's compatible, so looks good to me, I committed your suggested change. :)

yama6a avatar Nov 01 '24 10:11 yama6a

Yes, it confuses everyone, it's because Prometheus does not follow proper Go Module semver ... which is difficult to follow in retrospective due to https://www.reddit.com/r/golang/comments/ipwea6/go_modules_have_a_v2_problem/ 🙈

bwplotka avatar Nov 01 '24 18:11 bwplotka

LGTM we need to fix after my suggestion (and conform thingy) ):

image

I can push the commit to this PR, but likely not a -f (rewrite) to fix commit message. Suggestions gets quite annoying with conform.. 🤔

bwplotka avatar Nov 01 '24 19:11 bwplotka

@bwplotka yeah, my bad, I forgot about conform. I rewrote branch history, all checks seem to pass now.

yama6a avatar Nov 04 '24 09:11 yama6a

@bwplotka Do we have any idea when this feature will be released?

jullianow avatar Aug 11 '25 19:08 jullianow