Peakq: use generic query function (#82121)

Co-authored-by: Kyle Brandt <kyle@grafana.com>
This commit is contained in:
Ryan McKinley
2024-02-08 05:29:42 -08:00
committed by GitHub
parent 685ba7d287
commit 4884194879
7 changed files with 69 additions and 64 deletions

View File

@@ -75,6 +75,12 @@ type GenericDataQuery struct {
props map[string]any `json:"-"`
}
func NewGenericDataQuery(vals map[string]any) GenericDataQuery {
q := GenericDataQuery{}
_ = q.unmarshal(vals)
return q
}
// TimeRange represents a time range for a query and is a property of DataQuery.
type TimeRange struct {
// From is the start time of the query.
@@ -120,7 +126,7 @@ func (g GenericDataQuery) MarshalJSON() ([]byte, error) {
}
vals["refId"] = g.RefID
if g.Datasource.Type != "" || g.Datasource.UID != "" {
if g.Datasource != nil && (g.Datasource.Type != "" || g.Datasource.UID != "") {
vals["datasource"] = g.Datasource
}
if g.DatasourceId > 0 {
@@ -143,6 +149,15 @@ func (g *GenericDataQuery) UnmarshalJSON(b []byte) error {
if err != nil {
return err
}
return g.unmarshal(vals)
}
func (g *GenericDataQuery) unmarshal(vals map[string]any) error {
if vals == nil {
g.props = nil
return nil
}
key := "refId"
v, ok := vals[key]
if ok {