grafana-openapi-client-go icon indicating copy to clipboard operation
grafana-openapi-client-go copied to clipboard

`client.Ds.QueryMetricsWithExpressions()` returns empty frames

Open troibe opened this issue 1 year ago • 8 comments
trafficstars

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.

troibe avatar Apr 17 '24 09:04 troibe

@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 avatar Apr 17 '24 09:04 troibe

@troibe go for it; I couldn't PR grafana itself though as I am not a contributor. I will ask some people

dhftah avatar Apr 17 '24 17:04 dhftah

(you'll also need to regenerate this client when it gets merged in)

dhftah avatar Apr 17 '24 17:04 dhftah

hey it worked now :laughing: https://github.com/grafana/grafana/pull/86456 will submit it

dhftah avatar Apr 17 '24 17:04 dhftah

+1

tskdsb avatar Aug 28 '24 09:08 tskdsb