[v11.0.x] Expressions+Testdata: Create json schema for query types (#86164)
Expressions: Create json schema for query types (#84032)
(cherry picked from commit 4cda34ff7d)
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
co-authored by
Ryan McKinley
parent
0a95bcb6bd
commit
9744f081fc
@@ -0,0 +1,102 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/expr/classic"
|
||||
"github.com/grafana/grafana/pkg/expr/mathexp"
|
||||
)
|
||||
|
||||
// Supported expression types
|
||||
// +enum
|
||||
type QueryType string
|
||||
|
||||
const (
|
||||
// Apply a mathematical expression to results
|
||||
QueryTypeMath QueryType = "math"
|
||||
|
||||
// Reduce query results
|
||||
QueryTypeReduce QueryType = "reduce"
|
||||
|
||||
// Resample query results
|
||||
QueryTypeResample QueryType = "resample"
|
||||
|
||||
// Classic query
|
||||
QueryTypeClassic QueryType = "classic_conditions"
|
||||
|
||||
// Threshold
|
||||
QueryTypeThreshold QueryType = "threshold"
|
||||
|
||||
// SQL query via DuckDB
|
||||
QueryTypeSQL QueryType = "sql"
|
||||
)
|
||||
|
||||
type MathQuery struct {
|
||||
// General math expression
|
||||
Expression string `json:"expression" jsonschema:"minLength=1,example=$A + 1,example=$A/$B"`
|
||||
}
|
||||
|
||||
type ReduceQuery struct {
|
||||
// Reference to single query result
|
||||
Expression string `json:"expression" jsonschema:"minLength=1,example=$A"`
|
||||
|
||||
// The reducer
|
||||
Reducer mathexp.ReducerID `json:"reducer"`
|
||||
|
||||
// Reducer Options
|
||||
Settings *ReduceSettings `json:"settings,omitempty"`
|
||||
}
|
||||
|
||||
// QueryType = resample
|
||||
type ResampleQuery struct {
|
||||
// The math expression
|
||||
Expression string `json:"expression" jsonschema:"minLength=1,example=$A + 1,example=$A"`
|
||||
|
||||
// The time duration
|
||||
Window string `json:"window" jsonschema:"minLength=1,example=1d,example=10m"`
|
||||
|
||||
// The downsample function
|
||||
Downsampler mathexp.ReducerID `json:"downsampler"`
|
||||
|
||||
// The upsample function
|
||||
Upsampler mathexp.Upsampler `json:"upsampler"`
|
||||
}
|
||||
|
||||
type ThresholdQuery struct {
|
||||
// Reference to single query result
|
||||
Expression string `json:"expression" jsonschema:"minLength=1,example=$A"`
|
||||
|
||||
// Threshold Conditions
|
||||
Conditions []ThresholdConditionJSON `json:"conditions"`
|
||||
}
|
||||
|
||||
type ClassicQuery struct {
|
||||
Conditions []classic.ConditionJSON `json:"conditions"`
|
||||
}
|
||||
|
||||
// SQLQuery requires the sqlExpression feature flag
|
||||
type SQLExpression struct {
|
||||
Expression string `json:"expression" jsonschema:"minLength=1,example=SELECT * FROM A LIMIT 1"`
|
||||
}
|
||||
|
||||
//-------------------------------
|
||||
// Non-query commands
|
||||
//-------------------------------
|
||||
|
||||
type ReduceSettings struct {
|
||||
// Non-number reduce behavior
|
||||
Mode ReduceMode `json:"mode"`
|
||||
|
||||
// Only valid when mode is replace
|
||||
ReplaceWithValue *float64 `json:"replaceWithValue,omitempty"`
|
||||
}
|
||||
|
||||
// Non-Number behavior mode
|
||||
// +enum
|
||||
type ReduceMode string
|
||||
|
||||
const (
|
||||
// Drop non-numbers
|
||||
ReduceModeDrop ReduceMode = "dropNN"
|
||||
|
||||
// Replace non-numbers
|
||||
ReduceModeReplace ReduceMode = "replaceNN"
|
||||
)
|
||||
Reference in New Issue
Block a user