mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
QueryService: Use types from sdk (#84029)
This commit is contained in:
@@ -5,10 +5,12 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/data/utils/jsoniter"
|
||||
data "github.com/grafana/grafana-plugin-sdk-go/experimental/apis/data/v0alpha1"
|
||||
|
||||
"github.com/grafana/grafana/pkg/expr/classic"
|
||||
"github.com/grafana/grafana/pkg/expr/mathexp"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/tsdb/legacydata"
|
||||
)
|
||||
|
||||
// Once we are comfortable with the parsing logic, this struct will
|
||||
@@ -16,7 +18,7 @@ import (
|
||||
type ExpressionQuery struct {
|
||||
GraphID int64 `json:"id,omitempty"`
|
||||
RefID string `json:"refId"`
|
||||
QueryType QueryType `json:"queryType"`
|
||||
QueryType QueryType `json:"type"`
|
||||
|
||||
// The typed query parameters
|
||||
Properties any `json:"properties"`
|
||||
@@ -43,16 +45,16 @@ func NewExpressionQueryReader(features featuremgmt.FeatureToggles) *ExpressionQu
|
||||
// nolint:gocyclo
|
||||
func (h *ExpressionQueryReader) ReadQuery(
|
||||
// Properties that have been parsed off the same node
|
||||
common *rawNode,
|
||||
common data.DataQuery,
|
||||
// An iterator with context for the full node (include common values)
|
||||
iter *jsoniter.Iterator,
|
||||
) (eq ExpressionQuery, err error) {
|
||||
referenceVar := ""
|
||||
eq.RefID = common.RefID
|
||||
if common.QueryType == "" {
|
||||
return eq, fmt.Errorf("missing queryType")
|
||||
eq.QueryType = QueryType(common.GetString("type"))
|
||||
if eq.QueryType == "" {
|
||||
return eq, fmt.Errorf("missing type")
|
||||
}
|
||||
eq.QueryType = QueryType(common.QueryType)
|
||||
switch eq.QueryType {
|
||||
case QueryTypeMath:
|
||||
q := &MathQuery{}
|
||||
@@ -99,13 +101,17 @@ func (h *ExpressionQueryReader) ReadQuery(
|
||||
referenceVar, err = getReferenceVar(q.Expression, common.RefID)
|
||||
}
|
||||
if err == nil {
|
||||
tr := legacydata.NewDataTimeRange(common.TimeRange.From, common.TimeRange.To)
|
||||
eq.Properties = q
|
||||
eq.Command, err = NewResampleCommand(common.RefID,
|
||||
q.Window,
|
||||
referenceVar,
|
||||
q.Downsampler,
|
||||
q.Upsampler,
|
||||
common.TimeRange,
|
||||
AbsoluteTimeRange{
|
||||
From: tr.GetFromAsTimeUTC(),
|
||||
To: tr.GetToAsTimeUTC(),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user