Prometheus: Create jsonschema spec (#85077)
This commit is contained in:
+13
-10
@@ -1,6 +1,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"math"
|
||||
"strconv"
|
||||
@@ -9,6 +10,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/gtime"
|
||||
sdkapi "github.com/grafana/grafana-plugin-sdk-go/experimental/apis/data/v0alpha1"
|
||||
"github.com/prometheus/prometheus/model/labels"
|
||||
|
||||
"github.com/grafana/grafana/pkg/promlib/intervalv2"
|
||||
@@ -119,8 +121,8 @@ var safeResolution = 11000
|
||||
|
||||
// QueryModel includes both the common and specific values
|
||||
type QueryModel struct {
|
||||
PrometheusQueryProperties `json:",inline"`
|
||||
CommonQueryProperties `json:",inline"`
|
||||
PrometheusQueryProperties `json:",inline"`
|
||||
sdkapi.CommonQueryProperties `json:",inline"`
|
||||
|
||||
// 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
|
||||
@@ -128,13 +130,6 @@ type QueryModel struct {
|
||||
Interval string `json:"interval,omitempty"`
|
||||
}
|
||||
|
||||
// CommonQueryProperties is properties applied to all queries
|
||||
// NOTE: this will soon be replaced with a struct from the SDK
|
||||
type CommonQueryProperties struct {
|
||||
RefId string `json:"refId,omitempty"`
|
||||
IntervalMs int64 `json:"intervalMs,omitempty"`
|
||||
}
|
||||
|
||||
type TimeRange struct {
|
||||
Start time.Time
|
||||
End time.Time
|
||||
@@ -167,7 +162,7 @@ func Parse(query backend.DataQuery, dsScrapeInterval string, intervalCalculator
|
||||
}
|
||||
|
||||
// Final step value for prometheus
|
||||
calculatedStep, err := calculatePrometheusInterval(model.Interval, dsScrapeInterval, model.IntervalMs, model.IntervalFactor, query, intervalCalculator)
|
||||
calculatedStep, err := calculatePrometheusInterval(model.Interval, dsScrapeInterval, int64(model.IntervalMS), model.IntervalFactor, query, intervalCalculator)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -368,3 +363,11 @@ func AlignTimeRange(t time.Time, step time.Duration, offset int64) time.Time {
|
||||
stepNano := float64(step.Nanoseconds())
|
||||
return time.Unix(0, int64(math.Floor((float64(t.UnixNano())+offsetNano)/stepNano)*stepNano-offsetNano)).UTC()
|
||||
}
|
||||
|
||||
//go:embed query.types.json
|
||||
var f embed.FS
|
||||
|
||||
// QueryTypeDefinitionsJSON returns the query type definitions
|
||||
func QueryTypeDefinitionsJSON() (json.RawMessage, error) {
|
||||
return f.ReadFile("query.types.json")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user