Prometheus: Avoid parsing unused legacy datasource property (#87224)
* query cleanup * parse query * more comments
This commit is contained in:
@@ -137,6 +137,8 @@ const (
|
||||
var safeResolution = 11000
|
||||
|
||||
// QueryModel includes both the common and specific values
|
||||
// NOTE: this struct may have issues when decoding JSON that requires the special handling
|
||||
// registered in https://github.com/grafana/grafana-plugin-sdk-go/blob/v0.228.0/experimental/apis/data/v0alpha1/query.go#L298
|
||||
type QueryModel struct {
|
||||
PrometheusQueryProperties `json:",inline"`
|
||||
sdkapi.CommonQueryProperties `json:",inline"`
|
||||
@@ -172,8 +174,22 @@ type Scope struct {
|
||||
Matchers []*labels.Matcher
|
||||
}
|
||||
|
||||
// This internal query struct is just like QueryModel, except it does not include:
|
||||
// sdkapi.CommonQueryProperties -- this avoids errors where the unused "datasource" property
|
||||
// may be either a string or DataSourceRef
|
||||
type internalQueryModel struct {
|
||||
PrometheusQueryProperties `json:",inline"`
|
||||
//sdkapi.CommonQueryProperties `json:",inline"`
|
||||
IntervalMS float64 `json:"intervalMs,omitempty"`
|
||||
|
||||
// The following properties may be part of the request payload, however they are not saved in panel JSON
|
||||
// Timezone offset to align start & end time on backend
|
||||
UtcOffsetSec int64 `json:"utcOffsetSec,omitempty"`
|
||||
Interval string `json:"interval,omitempty"`
|
||||
}
|
||||
|
||||
func Parse(span trace.Span, query backend.DataQuery, dsScrapeInterval string, intervalCalculator intervalv2.Calculator, fromAlert bool, enableScope bool) (*Query, error) {
|
||||
model := &QueryModel{}
|
||||
model := &internalQueryModel{}
|
||||
if err := json.Unmarshal(query.JSON, model); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user