Future-proofing query and data source model in Dashboard Schema v2 (#104194)

---------

Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com>
Co-authored-by: alexandra vargas <alexa1866@gmail.com>
Co-authored-by: Haris Rozajac <haris.rozajac12@gmail.com>
Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com>
Co-authored-by: Igor Suleymanov <igor.suleymanov@grafana.com>
Co-authored-by: spinillos <selenepinillos@gmail.com>
This commit is contained in:
Ivan Ortega Alba
2025-07-07 15:31:25 +02:00
committed by GitHub
co-authored by alexandra vargas Haris Rozajac Dominik Prokop Igor Suleymanov spinillos
parent cfa05a63c5
commit 075770070e
65 changed files with 1916 additions and 714 deletions
@@ -13,6 +13,7 @@ package dataquery
import (
json "encoding/json"
fmt "fmt"
)
type AzureMonitorQuery struct {
@@ -835,3 +836,58 @@ type StringOrBoolOrFloat64OrSelectableValue struct {
func NewStringOrBoolOrFloat64OrSelectableValue() *StringOrBoolOrFloat64OrSelectableValue {
return &StringOrBoolOrFloat64OrSelectableValue{}
}
// MarshalJSON implements a custom JSON marshalling logic to encode `StringOrBoolOrFloat64OrSelectableValue` as JSON.
func (resource StringOrBoolOrFloat64OrSelectableValue) MarshalJSON() ([]byte, error) {
if resource.String != nil {
return json.Marshal(resource.String)
}
if resource.Bool != nil {
return json.Marshal(resource.Bool)
}
if resource.Float64 != nil {
return json.Marshal(resource.Float64)
}
if resource.SelectableValue != nil {
return json.Marshal(resource.SelectableValue)
}
return []byte("null"), nil
}
// UnmarshalJSON implements a custom JSON unmarshalling logic to decode StringOrBoolOrFloat64OrSelectableValue from JSON.
func (resource *StringOrBoolOrFloat64OrSelectableValue) UnmarshalJSON(raw []byte) error {
if raw == nil {
return nil
}
fields := make(map[string]json.RawMessage)
if err := json.Unmarshal(raw, &fields); err != nil {
return err
}
if fields["String"] != nil {
if err := json.Unmarshal(fields["String"], &resource.String); err != nil {
return fmt.Errorf("error decoding field 'String': %w", err)
}
}
if fields["Bool"] != nil {
if err := json.Unmarshal(fields["Bool"], &resource.Bool); err != nil {
return fmt.Errorf("error decoding field 'Bool': %w", err)
}
}
if fields["Float64"] != nil {
if err := json.Unmarshal(fields["Float64"], &resource.Float64); err != nil {
return fmt.Errorf("error decoding field 'Float64': %w", err)
}
}
if fields["SelectableValue"] != nil {
if err := json.Unmarshal(fields["SelectableValue"], &resource.SelectableValue); err != nil {
return fmt.Errorf("error decoding field 'SelectableValue': %w", err)
}
}
return nil
}
@@ -211,6 +211,12 @@ func NewQueryEditorProperty() *QueryEditorProperty {
}
}
type QueryEditorPropertyType string
const (
QueryEditorPropertyTypeString QueryEditorPropertyType = "string"
)
type QueryEditorArrayExpression struct {
Type QueryEditorArrayExpressionType `json:"type"`
Expressions ArrayOfQueryEditorExpressionOrArrayOfQueryEditorArrayExpression `json:"expressions"`
@@ -279,12 +285,6 @@ func NewQueryEditorOperatorValueType() *QueryEditorOperatorValueType {
return NewStringOrBoolOrInt64OrArrayOfQueryEditorOperatorType()
}
type QueryEditorPropertyType string
const (
QueryEditorPropertyTypeString QueryEditorPropertyType = "string"
)
type LogsQueryLanguage string
const (
@@ -13,6 +13,7 @@ package dataquery
import (
json "encoding/json"
fmt "fmt"
)
type BucketAggregation = DateHistogramOrHistogramOrTermsOrFiltersOrGeoHashGridOrNested
@@ -1549,6 +1550,43 @@ func NewStringOrDataqueryInlineScript() *StringOrDataqueryInlineScript {
return &StringOrDataqueryInlineScript{}
}
// MarshalJSON implements a custom JSON marshalling logic to encode `StringOrDataqueryInlineScript` as JSON.
func (resource StringOrDataqueryInlineScript) MarshalJSON() ([]byte, error) {
if resource.String != nil {
return json.Marshal(resource.String)
}
if resource.DataqueryInlineScript != nil {
return json.Marshal(resource.DataqueryInlineScript)
}
return []byte("null"), nil
}
// UnmarshalJSON implements a custom JSON unmarshalling logic to decode StringOrDataqueryInlineScript from JSON.
func (resource *StringOrDataqueryInlineScript) UnmarshalJSON(raw []byte) error {
if raw == nil {
return nil
}
fields := make(map[string]json.RawMessage)
if err := json.Unmarshal(raw, &fields); err != nil {
return err
}
if fields["String"] != nil {
if err := json.Unmarshal(fields["String"], &resource.String); err != nil {
return fmt.Errorf("error decoding field 'String': %w", err)
}
}
if fields["DataqueryInlineScript"] != nil {
if err := json.Unmarshal(fields["DataqueryInlineScript"], &resource.DataqueryInlineScript); err != nil {
return fmt.Errorf("error decoding field 'DataqueryInlineScript': %w", err)
}
}
return nil
}
type BucketScriptOrCumulativeSumOrDerivativeOrSerialDiffOrRawDataOrRawDocumentOrUniqueCountOrPercentilesOrExtendedStatsOrMinOrMaxOrSumOrAverageOrMovingAverageOrMovingFunctionOrLogsOrRateOrTopMetrics struct {
BucketScript *BucketScript `json:"BucketScript,omitempty"`
CumulativeSum *CumulativeSum `json:"CumulativeSum,omitempty"`