grafana-openapi-client-go
grafana-openapi-client-go copied to clipboard
`client.Ds.QueryMetricsWithExpressions()` returns empty frames
I'm trying to use client.Ds.QueryMetricsWithExpressions() to see if my metrics data source can be queried with a custom query from Grafana.
type Datasource struct {
Uid string `json:"uid"`
}
type Query struct {
Datasource Datasource `json:"datasource"`
Expr string `json:"expr"`
RefId string `json:"refId"`
}
var queries []models.JSON
queries = append(queries, Query{
Datasource: Datasource{Uid: dataSource.Payload.UID},
Expr: "up",
RefId: "A",
})
nowTimestamp := "now"
priorTimestamp := "now-5m"
metricRequest := &models.MetricRequest{
From: &priorTimestamp,
Queries: queries,
To: &nowTimestamp,
}
queryResultOK, queryResultMultiStatus, err := client.Ds.QueryMetricsWithExpressions(metricRequest)
Now using queryResultOK.Payload.Results["A"].Frames[0] to access the frames results in *models.Frame(&models.Frame{Fields:[]*models.Field(nil), Meta:(*models.FrameMeta)(nil), Name:"", RefID:""}).
Running the same query in the browser or with postman yields valid results for me.
As described in https://github.com/grafana/grafana-openapi-client-go/pull/90#issuecomment-2014803007 this seems to be an issue with the go data model and JSON not corresponding.
For now I'm just relying on the health check for that metrics data source.
@dhftah Do you think we could take the Frame related changes from https://github.com/grafana/grafana/compare/main...dhftah:frk.grafana:fix-openapi-specification and already make PR out of them?
@troibe go for it; I couldn't PR grafana itself though as I am not a contributor. I will ask some people
(you'll also need to regenerate this client when it gets merged in)
hey it worked now :laughing: https://github.com/grafana/grafana/pull/86456 will submit it
+1