Query: Add query type to json marshal/unmarshal (#83821)

add query type to json marshal/unmarshal
This commit is contained in:
Will Browne 2024-03-04 16:06:57 +01:00 committed by GitHub
parent 57935250fd
commit c644826f50
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 1 deletions

View File

@ -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
}

View File

@ -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",