mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Peakq: use generic query function (#82121)
Co-authored-by: Kyle Brandt <kyle@grafana.com>
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user