Prometheus: remove cue definition (#83808)

Co-authored-by: ismail simsek <ismailsimsek09@gmail.com>
This commit is contained in:
Ryan McKinley
2024-03-04 10:23:32 -08:00
committed by GitHub
co-authored by ismail simsek
parent 2e8c514cfd
commit 5aa965b9e9
19 changed files with 120 additions and 385 deletions
+73 -28
View File
@@ -14,9 +14,61 @@ import (
"github.com/prometheus/prometheus/promql/parser"
"github.com/grafana/grafana/pkg/tsdb/prometheus/intervalv2"
"github.com/grafana/grafana/pkg/tsdb/prometheus/kinds/dataquery"
)
// PromQueryFormat defines model for PromQueryFormat.
// +enum
type PromQueryFormat string
const (
PromQueryFormatTimeSeries PromQueryFormat = "time_series"
PromQueryFormatTable PromQueryFormat = "table"
PromQueryFormatHeatmap PromQueryFormat = "heatmap"
)
// QueryEditorMode defines model for QueryEditorMode.
// +enum
type QueryEditorMode string
const (
QueryEditorModeBuilder QueryEditorMode = "builder"
QueryEditorModeCode QueryEditorMode = "code"
)
// PrometheusQueryProperties defines the specific properties used for prometheus
type PrometheusQueryProperties struct {
// The response format
Format PromQueryFormat `json:"format,omitempty"`
// The actual expression/query that will be evaluated by Prometheus
Expr string `json:"expr"`
// Returns a Range vector, comprised of a set of time series containing a range of data points over time for each time series
Range bool `json:"range,omitempty"`
// Returns only the latest value that Prometheus has scraped for the requested time series
Instant bool `json:"instant,omitempty"`
// Execute an additional query to identify interesting raw samples relevant for the given expr
Exemplar bool `json:"exemplar,omitempty"`
// what we should show in the editor
EditorMode QueryEditorMode `json:"editorMode,omitempty"`
// Used to specify how many times to divide max data points by. We use max data points under query options
// See https://github.com/grafana/grafana/issues/48081
// Deprecated: use interval
IntervalFactor int64 `json:"intervalFactor,omitempty"`
// Series name override or template. Ex. {{hostname}} will be replaced with label value for hostname
LegendFormat string `json:"legendFormat,omitempty"`
// ???
Scope *struct {
Matchers string `json:"matchers"`
} `json:"scope,omitempty"`
}
// Internal interval and range variables
const (
varInterval = "$__interval"
@@ -51,15 +103,22 @@ const (
var safeResolution = 11000
// QueryModel includes both the common and specific values
type QueryModel struct {
dataquery.PrometheusDataQuery
PrometheusQueryProperties `json:",inline"`
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
UtcOffsetSec int64 `json:"utcOffsetSec,omitempty"`
LegendFormat string `json:"legendFormat,omitempty"`
Interval string `json:"interval,omitempty"`
IntervalMs int64 `json:"intervalMs,omitempty"`
IntervalFactor int64 `json:"intervalFactor,omitempty"`
UtcOffsetSec int64 `json:"utcOffsetSec,omitempty"`
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 {
@@ -68,6 +127,7 @@ type TimeRange struct {
Step time.Duration
}
// The internal query object
type Query struct {
Expr string
Step time.Duration
@@ -119,29 +179,14 @@ func Parse(query backend.DataQuery, dsScrapeInterval string, intervalCalculator
return nil, err
}
}
var rangeQuery, instantQuery bool
if model.Instant == nil {
instantQuery = false
} else {
instantQuery = *model.Instant
}
if model.Range == nil {
rangeQuery = false
} else {
rangeQuery = *model.Range
}
if !instantQuery && !rangeQuery {
if !model.Instant && !model.Range {
// In older dashboards, we were not setting range query param and !range && !instant was run as range query
rangeQuery = true
model.Range = true
}
// We never want to run exemplar query for alerting
exemplarQuery := false
if model.Exemplar != nil {
exemplarQuery = *model.Exemplar
}
if fromAlert {
exemplarQuery = false
model.Exemplar = false
}
return &Query{
@@ -151,9 +196,9 @@ func Parse(query backend.DataQuery, dsScrapeInterval string, intervalCalculator
Start: query.TimeRange.From,
End: query.TimeRange.To,
RefId: query.RefID,
InstantQuery: instantQuery,
RangeQuery: rangeQuery,
ExemplarQuery: exemplarQuery,
InstantQuery: model.Instant,
RangeQuery: model.Range,
ExemplarQuery: model.Exemplar,
UtcOffsetSec: model.UtcOffsetSec,
}, nil
}
+1
View File
@@ -6,6 +6,7 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/data"
)
// +enum
type ResultType string
const (