diff --git a/pkg/apis/query/v0alpha1/query.go b/pkg/apis/query/v0alpha1/query.go index 6c32e8becee..bb11d9ae655 100644 --- a/pkg/apis/query/v0alpha1/query.go +++ b/pkg/apis/query/v0alpha1/query.go @@ -138,6 +138,9 @@ func (g GenericDataQuery) MarshalJSON() ([]byte, error) { if g.MaxDataPoints > 0 { vals["maxDataPoints"] = g.MaxDataPoints } + if g.QueryType != "" { + vals["queryType"] = g.QueryType + } return json.Marshal(vals) } @@ -221,6 +224,17 @@ func (g *GenericDataQuery) unmarshal(vals map[string]any) error { delete(vals, key) } + key = "queryType" + v, ok = vals[key] + if ok { + queryType, ok := v.(string) + if !ok { + return fmt.Errorf("expected queryType as string (got: %t)", v) + } + g.QueryType = queryType + delete(vals, key) + } + g.props = vals return nil } diff --git a/pkg/apis/query/v0alpha1/query_test.go b/pkg/apis/query/v0alpha1/query_test.go index e2ea3ce53c4..351593e5699 100644 --- a/pkg/apis/query/v0alpha1/query_test.go +++ b/pkg/apis/query/v0alpha1/query_test.go @@ -31,7 +31,8 @@ func TestParseQueriesIntoQueryDataRequest(t *testing.T) { "timeRange": { "from": "100", "to": "200" - } + }, + "queryType": "foo" } ], "from": "1692624667389", @@ -66,6 +67,7 @@ func TestParseQueriesIntoQueryDataRequest(t *testing.T) { "uid": "old" }, "maxDataPoints": 10, + "queryType": "foo", "refId": "Z", "timeRange": { "from": "100",