fix: query errors with newer Grafana API#254
Conversation
|
Nice fix! One logic issue to flag: Redundant second condition in new path match
return strings.Contains(rest, "/apis/query.grafana.app/") && strings.Contains(rest, "/query")The second For example, this would incorrectly return Suggested fix — replace path := strings.SplitN(rest, "?", 2)[0]
return strings.Contains(rest, "/apis/query.grafana.app/") && strings.HasSuffix(path, "/query")Strip the query string first, then use Suggested test — add after Convey("When request is under query.grafana.app but not a /query endpoint", func() {
result := IsDataSourceQueryRequest(
"https://myorg.grafana.net/apis/query.grafana.app/v0alpha1/namespaces/stacks-123/something-else",
"https", "myorg.grafana.net",
)
So(result, ShouldBeFalse)
})This test exposes the bug — without the Tested locally — all 11 assertions pass with these changes. Low severity since false positives are unlikely in practice, but easy to tighten up. |
|
Nice catch. FIxed! |
Closes #253
Bug Fixes
Extend
IsDataSourceQueryRequestto match both the legacy/api/ds/query?path and the newer/apis/query.grafana.app/<version>/namespaces/<ns>/querypath used by Grafana CloudTests
Add test cases for query API path matching (correct host, with port, wrong host, non-query API path)
Details
When using
login-method=apikey, the kiosk intercepts browser requests via the Chrome DevTools Protocolfetchdomainto inject
AuthorizationandContent-Typeheaders. TheAuthorization: Bearerheader was added to all requestsmatching the target host, but the
Content-Type: application/jsonheader was only added when the request URL contained/api/ds/query?— the legacy Grafana datasource query path.Grafana Cloud now routes datasource queries through a Kubernetes-style API:
/apis/query.grafana.app/v0alpha1/namespaces/stacks-/query?ds_type=prometheus&requestId=...
Without the
Content-Typeheader, the server cannot parse the POST body and returns a400 Bad Request.