grafana / cog

Code Generation with a human touch
Apache License 2.0
48 stars 2 forks source link

Cue/out of root references #432

Closed K-Phoen closed 5 months ago

K-Phoen commented 5 months ago

Contributes to #408

grafana-app-sdk's codegen pipeline supports cases where code is generated from a specific path within a cue file, while types relevant for the codegen are defined outside of that path:

schema: {
  spec: { // ← codegen runs on this
    title: string
    origin: #Origin // ← "out of root" reference
  }
  #Origin: { creator: string } 
}
github-actions[bot] commented 5 months ago

Note: in addition to the changes introduced by this PR, the diff includes unreleased changes living in main.

### 🔎 Changes to `grafana-foundation-sdk@next+cog-v0.0.x` ```patch diff --git a/go/alerting/timeinterval_builder_gen.go b/go/alerting/timeinterval_builder_gen.go index 3c5ef42..5cb84c4 100644 --- a/go/alerting/timeinterval_builder_gen.go +++ b/go/alerting/timeinterval_builder_gen.go @@ -45,8 +45,8 @@ func (builder *TimeIntervalBuilder) Name(name string) *TimeIntervalBuilder { return builder } -func (builder *TimeIntervalBuilder) TimeIntervals(timeIntervals []cog.Builder[TimeInterval]) *TimeIntervalBuilder { - timeIntervalsResources := make([]TimeInterval, 0, len(timeIntervals)) +func (builder *TimeIntervalBuilder) TimeIntervals(timeIntervals []cog.Builder[TimeIntervalItem]) *TimeIntervalBuilder { + timeIntervalsResources := make([]TimeIntervalItem, 0, len(timeIntervals)) for _, r1 := range timeIntervals { timeIntervalsDepth1, err := r1.Build() if err != nil { diff --git a/go/alerting/timeintervalitem_builder_gen.go b/go/alerting/timeintervalitem_builder_gen.go new file mode 100644 index 0000000..e5df78f --- /dev/null +++ b/go/alerting/timeintervalitem_builder_gen.go @@ -0,0 +1,88 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. + +package alerting + +import ( + cog "github.com/grafana/grafana-foundation-sdk/go/cog" +) + +var _ cog.Builder[TimeIntervalItem] = (*TimeIntervalItemBuilder)(nil) + +type TimeIntervalItemBuilder struct { + internal *TimeIntervalItem + errors map[string]cog.BuildErrors +} + +func NewTimeIntervalItemBuilder() *TimeIntervalItemBuilder { + resource := &TimeIntervalItem{} + builder := &TimeIntervalItemBuilder{ + internal: resource, + errors: make(map[string]cog.BuildErrors), + } + + builder.applyDefaults() + + return builder +} + +func (builder *TimeIntervalItemBuilder) Build() (TimeIntervalItem, error) { + var errs cog.BuildErrors + + for _, err := range builder.errors { + errs = append(errs, cog.MakeBuildErrors("TimeIntervalItem", err)...) + } + + if len(errs) != 0 { + return TimeIntervalItem{}, errs + } + + return *builder.internal, nil +} + +func (builder *TimeIntervalItemBuilder) DaysOfMonth(daysOfMonth []string) *TimeIntervalItemBuilder { + builder.internal.DaysOfMonth = daysOfMonth + + return builder +} + +func (builder *TimeIntervalItemBuilder) Location(location string) *TimeIntervalItemBuilder { + builder.internal.Location = &location + + return builder +} + +func (builder *TimeIntervalItemBuilder) Months(months []string) *TimeIntervalItemBuilder { + builder.internal.Months = months + + return builder +} + +func (builder *TimeIntervalItemBuilder) Times(times []cog.Builder[TimeIntervalTimeRange]) *TimeIntervalItemBuilder { + timesResources := make([]TimeIntervalTimeRange, 0, len(times)) + for _, r1 := range times { + timesDepth1, err := r1.Build() + if err != nil { + builder.errors["times"] = err.(cog.BuildErrors) + return builder + } + timesResources = append(timesResources, timesDepth1) + } + builder.internal.Times = timesResources + + return builder +} + +func (builder *TimeIntervalItemBuilder) Weekdays(weekdays []string) *TimeIntervalItemBuilder { + builder.internal.Weekdays = weekdays + + return builder +} + +func (builder *TimeIntervalItemBuilder) Years(years []string) *TimeIntervalItemBuilder { + builder.internal.Years = years + + return builder +} + +func (builder *TimeIntervalItemBuilder) applyDefaults() { +} diff --git a/go/alerting/timeintervaltimerange_builder_gen.go b/go/alerting/timeintervaltimerange_builder_gen.go new file mode 100644 index 0000000..6a03574 --- /dev/null +++ b/go/alerting/timeintervaltimerange_builder_gen.go @@ -0,0 +1,55 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. + +package alerting + +import ( + cog "github.com/grafana/grafana-foundation-sdk/go/cog" +) + +var _ cog.Builder[TimeIntervalTimeRange] = (*TimeIntervalTimeRangeBuilder)(nil) + +type TimeIntervalTimeRangeBuilder struct { + internal *TimeIntervalTimeRange + errors map[string]cog.BuildErrors +} + +func NewTimeIntervalTimeRangeBuilder() *TimeIntervalTimeRangeBuilder { + resource := &TimeIntervalTimeRange{} + builder := &TimeIntervalTimeRangeBuilder{ + internal: resource, + errors: make(map[string]cog.BuildErrors), + } + + builder.applyDefaults() + + return builder +} + +func (builder *TimeIntervalTimeRangeBuilder) Build() (TimeIntervalTimeRange, error) { + var errs cog.BuildErrors + + for _, err := range builder.errors { + errs = append(errs, cog.MakeBuildErrors("TimeIntervalTimeRange", err)...) + } + + if len(errs) != 0 { + return TimeIntervalTimeRange{}, errs + } + + return *builder.internal, nil +} + +func (builder *TimeIntervalTimeRangeBuilder) EndTime(endTime string) *TimeIntervalTimeRangeBuilder { + builder.internal.EndTime = &endTime + + return builder +} + +func (builder *TimeIntervalTimeRangeBuilder) StartTime(startTime string) *TimeIntervalTimeRangeBuilder { + builder.internal.StartTime = &startTime + + return builder +} + +func (builder *TimeIntervalTimeRangeBuilder) applyDefaults() { +} diff --git a/go/alerting/types_gen.go b/go/alerting/types_gen.go index 3f3142d..f81d0b1 100644 --- a/go/alerting/types_gen.go +++ b/go/alerting/types_gen.go @@ -10,94 +10,6 @@ import ( cogvariants "github.com/grafana/grafana-foundation-sdk/go/cog/variants" ) -// Duration in seconds. -type Duration int64 - -type Json any - -type MatchRegexps map[string]string - -type MatchType int64 - -type Matcher struct { - Name *string `json:"Name,omitempty"` - Type *MatchType `json:"Type,omitempty"` - Value *string `json:"Value,omitempty"` -} - -// Matchers is a slice of Matchers that is sortable, implements Stringer, and -// provides a Matches method to match a LabelSet against all Matchers in the -// slice. Note that some users of Matchers might require it to be sorted. -type Matchers []Matcher - -type NotificationTemplate struct { - Name *string `json:"name,omitempty"` - Provenance *Provenance `json:"provenance,omitempty"` - Template *string `json:"template,omitempty"` -} - -type ObjectMatcher []string - -type ObjectMatchers []ObjectMatcher - -type Provenance string - -// RelativeTimeRange is the per query start and end time -// for requests. -type RelativeTimeRange struct { - // RelativeTimeRange is the per query start and end time - // for requests. - From *Duration `json:"from,omitempty"` - // RelativeTimeRange is the per query start and end time - // for requests. - To *Duration `json:"to,omitempty"` -} - -type TimeInterval struct { - Name *string `json:"name,omitempty"` - TimeIntervals []TimeInterval `json:"time_intervals,omitempty"` -} - -type RuleGroup struct { - FolderUid *string `json:"folderUid,omitempty"` - // The interval, in seconds, at which all rules in the group are evaluated. - // If a group contains many rules, the rules are evaluated sequentially. - Interval *Duration `json:"interval,omitempty"` - Rules []Rule `json:"rules,omitempty"` - Title *string `json:"title,omitempty"` -} - -type Rule struct { - Annotations map[string]string `json:"annotations,omitempty"` - Condition string `json:"condition"` - Data []Query `json:"data"` - ExecErrState RuleExecErrState `json:"execErrState"` - FolderUID string `json:"folderUID"` - // The amount of time, in seconds, for which the rule must be breached for the rule to be considered to be Firing. - // Before this time has elapsed, the rule is only considered to be Pending. - For string `json:"for"` - Id *int64 `json:"id,omitempty"` - IsPaused *bool `json:"isPaused,omitempty"` - Labels map[string]string `json:"labels,omitempty"` - NoDataState RuleNoDataState `json:"noDataState"` - NotificationSettings *NotificationSettings `json:"notification_settings,omitempty"` - OrgID int64 `json:"orgID"` - Provenance *Provenance `json:"provenance,omitempty"` - RuleGroup string `json:"ruleGroup"` - Title string `json:"title"` - Uid *string `json:"uid,omitempty"` - Updated *time.Time `json:"updated,omitempty"` -} - -type NotificationSettings struct { - GroupBy []string `json:"group_by,omitempty"` - GroupInterval *string `json:"group_interval,omitempty"` - GroupWait *string `json:"group_wait,omitempty"` - MuteTimeIntervals []string `json:"mute_time_intervals,omitempty"` - Receiver string `json:"receiver"` - RepeatInterval *string `json:"repeat_interval,omitempty"` -} - type Query struct { DatasourceUid *string `json:"datasourceUid,omitempty"` Model cogvariants.Dataquery `json:"model,omitempty"` @@ -152,6 +64,27 @@ func (resource *Query) UnmarshalJSON(raw []byte) error { return nil } +type RuleGroup struct { + FolderUid *string `json:"folderUid,omitempty"` + // The interval, in seconds, at which all rules in the group are evaluated. + // If a group contains many rules, the rules are evaluated sequentially. + Interval *Duration `json:"interval,omitempty"` + Rules []Rule `json:"rules,omitempty"` + Title *string `json:"title,omitempty"` +} + +type NotificationSettings struct { + GroupBy []string `json:"group_by,omitempty"` + GroupInterval *string `json:"group_interval,omitempty"` + GroupWait *string `json:"group_wait,omitempty"` + MuteTimeIntervals []string `json:"mute_time_intervals,omitempty"` + Receiver string `json:"receiver"` + RepeatInterval *string `json:"repeat_interval,omitempty"` +} + +// Duration in seconds. +type Duration int64 + // EmbeddedContactPoint is the contact point type that is used // by grafanas embedded alertmanager implementation. type ContactPoint struct { @@ -175,6 +108,80 @@ type ContactPoint struct { Uid *string `json:"uid,omitempty"` } +type Json any + +type MatchRegexps map[string]string + +type MatchType string + +const ( + MatchTypeEqual MatchType = "=" + MatchTypeNotEqual MatchType = "!=" + MatchTypeEqualRegex MatchType = "=~" + MatchTypeNotEqualRegex MatchType = "!~" +) + +type Matcher struct { + Name *string `json:"Name,omitempty"` + Type *MatchType `json:"Type,omitempty"` + Value *string `json:"Value,omitempty"` +} + +// Matchers is a slice of Matchers that is sortable, implements Stringer, and +// provides a Matches method to match a LabelSet against all Matchers in the +// slice. Note that some users of Matchers might require it to be sorted. +type Matchers []Matcher + +type MuteTiming struct { + Name *string `json:"name,omitempty"` + TimeIntervals []TimeInterval `json:"time_intervals,omitempty"` +} + +type NotificationTemplate struct { + Name *string `json:"name,omitempty"` + Provenance *Provenance `json:"provenance,omitempty"` + Template *string `json:"template,omitempty"` +} + +type ObjectMatcher []string + +type ObjectMatchers []ObjectMatcher + +type Provenance string + +type Rule struct { + Annotations map[string]string `json:"annotations,omitempty"` + Condition string `json:"condition"` + Data []Query `json:"data"` + ExecErrState RuleExecErrState `json:"execErrState"` + FolderUID string `json:"folderUID"` + // The amount of time, in seconds, for which the rule must be breached for the rule to be considered to be Firing. + // Before this time has elapsed, the rule is only considered to be Pending. + For string `json:"for"` + Id *int64 `json:"id,omitempty"` + IsPaused *bool `json:"isPaused,omitempty"` + Labels map[string]string `json:"labels,omitempty"` + NoDataState RuleNoDataState `json:"noDataState"` + NotificationSettings *NotificationSettings `json:"notification_settings,omitempty"` + OrgID int64 `json:"orgID"` + Provenance *Provenance `json:"provenance,omitempty"` + RuleGroup string `json:"ruleGroup"` + Title string `json:"title"` + Uid *string `json:"uid,omitempty"` + Updated *time.Time `json:"updated,omitempty"` +} + +// RelativeTimeRange is the per query start and end time +// for requests. +type RelativeTimeRange struct { + // RelativeTimeRange is the per query start and end time + // for requests. + From *Duration `json:"from,omitempty"` + // RelativeTimeRange is the per query start and end time + // for requests. + To *Duration `json:"to,omitempty"` +} + // A Route is a node that contains definitions of how to handle alerts. This is modified // from the upstream alertmanager in that it adds the ObjectMatchers property. type NotificationPolicy struct { @@ -219,26 +226,24 @@ type NotificationPolicy struct { Routes []NotificationPolicy `json:"routes,omitempty"` } -type MuteTiming struct { - Name *string `json:"name,omitempty"` - TimeIntervals []TimeInterval `json:"time_intervals,omitempty"` +type TimeInterval struct { + Name *string `json:"name,omitempty"` + TimeIntervals []TimeIntervalItem `json:"time_intervals,omitempty"` } -type RuleExecErrState string - -const ( - RuleExecErrStateOK RuleExecErrState = "OK" - RuleExecErrStateAlerting RuleExecErrState = "Alerting" - RuleExecErrStateError RuleExecErrState = "Error" -) - -type RuleNoDataState string +type TimeIntervalItem struct { + DaysOfMonth []string `json:"days_of_month,omitempty"` + Location *string `json:"location,omitempty"` + Months []string `json:"months,omitempty"` + Times []TimeIntervalTimeRange `json:"times,omitempty"` + Weekdays []string `json:"weekdays,omitempty"` + Years []string `json:"years,omitempty"` +} -const ( - RuleNoDataStateAlerting RuleNoDataState = "Alerting" - RuleNoDataStateNoData RuleNoDataState = "NoData" - RuleNoDataStateOK RuleNoDataState = "OK" -) +type TimeIntervalTimeRange struct { + EndTime *string `json:"end_time,omitempty"` + StartTime *string `json:"start_time,omitempty"` +} type ContactPointType string @@ -262,3 +267,19 @@ const ( ContactPointTypeWebhook ContactPointType = " webhook" ContactPointTypeWecom ContactPointType = " wecom" ) + +type RuleExecErrState string + +const ( + RuleExecErrStateOK RuleExecErrState = "OK" + RuleExecErrStateAlerting RuleExecErrState = "Alerting" + RuleExecErrStateError RuleExecErrState = "Error" +) + +type RuleNoDataState string + +const ( + RuleNoDataStateAlerting RuleNoDataState = "Alerting" + RuleNoDataStateNoData RuleNoDataState = "NoData" + RuleNoDataStateOK RuleNoDataState = "OK" +) diff --git a/go/azuremonitor/azurelogsquery_builder_gen.go b/go/azuremonitor/azurelogsquery_builder_gen.go index 076f120..48a2d9a 100644 --- a/go/azuremonitor/azurelogsquery_builder_gen.go +++ b/go/azuremonitor/azurelogsquery_builder_gen.go @@ -75,6 +75,13 @@ func (builder *AzureLogsQueryBuilder) TimeColumn(timeColumn string) *AzureLogsQu return builder } +// If set to true the query will be run as a basic logs query +func (builder *AzureLogsQueryBuilder) BasicLogsQuery(basicLogsQuery bool) *AzureLogsQueryBuilder { + builder.internal.BasicLogsQuery = &basicLogsQuery + + return builder +} + // Workspace ID. This was removed in Grafana 8, but remains for backwards compat. func (builder *AzureLogsQueryBuilder) Workspace(workspace string) *AzureLogsQueryBuilder { builder.internal.Workspace = &workspace diff --git a/go/azuremonitor/types_gen.go b/go/azuremonitor/types_gen.go index 0e98f37..0e789fb 100644 --- a/go/azuremonitor/types_gen.go +++ b/go/azuremonitor/types_gen.go @@ -136,6 +136,8 @@ type AzureLogsQuery struct { DashboardTime *bool `json:"dashboardTime,omitempty"` // If dashboardTime is set to true this value dictates which column the time filter will be applied to. Defaults to the first tables timeSpan column, the first datetime column found, or TimeGenerated TimeColumn *string `json:"timeColumn,omitempty"` + // If set to true the query will be run as a basic logs query + BasicLogsQuery *bool `json:"basicLogsQuery,omitempty"` // Workspace ID. This was removed in Grafana 8, but remains for backwards compat. Workspace *string `json:"workspace,omitempty"` // @deprecated Use resources instead diff --git a/go/common/types_gen.go b/go/common/types_gen.go index 6389be0..515fd60 100644 --- a/go/common/types_gen.go +++ b/go/common/types_gen.go @@ -492,6 +492,15 @@ const ( BigValueTextModeNone BigValueTextMode = "none" ) +// TODO docs +type PercentChangeColorMode string + +const ( + PercentChangeColorModeStandard PercentChangeColorMode = "standard" + PercentChangeColorModeInverted PercentChangeColorMode = "inverted" + PercentChangeColorModeSameAsValue PercentChangeColorMode = "same_as_value" +) + // TODO -- should not be table specific! // TODO docs type FieldTextAlignment string diff --git a/go/stat/panel_builder_gen.go b/go/stat/panel_builder_gen.go index f3223dd..eaf3847 100644 --- a/go/stat/panel_builder_gen.go +++ b/go/stat/panel_builder_gen.go @@ -460,6 +460,15 @@ func (builder *PanelBuilder) WideLayout(wideLayout bool) *PanelBuilder { return builder } +func (builder *PanelBuilder) ShowPercentChange(showPercentChange bool) *PanelBuilder { + if builder.internal.Options == nil { + builder.internal.Options = &Options{} + } + builder.internal.Options.(*Options).ShowPercentChange = showPercentChange + + return builder +} + func (builder *PanelBuilder) ReduceOptions(reduceOptions cog.Builder[common.ReduceDataOptions]) *PanelBuilder { if builder.internal.Options == nil { builder.internal.Options = &Options{} @@ -488,11 +497,11 @@ func (builder *PanelBuilder) Text(text cog.Builder[common.VizTextDisplayOptions] return builder } -func (builder *PanelBuilder) ShowPercentChange(showPercentChange bool) *PanelBuilder { +func (builder *PanelBuilder) PercentChangeColorMode(percentChangeColorMode common.PercentChangeColorMode) *PanelBuilder { if builder.internal.Options == nil { builder.internal.Options = &Options{} } - builder.internal.Options.(*Options).ShowPercentChange = showPercentChange + builder.internal.Options.(*Options).PercentChangeColorMode = percentChangeColorMode return builder } @@ -516,4 +525,5 @@ func (builder *PanelBuilder) applyDefaults() { builder.TextMode("auto") builder.WideLayout(true) builder.ShowPercentChange(false) + builder.PercentChangeColorMode("standard") } diff --git a/go/stat/types_gen.go b/go/stat/types_gen.go index dacf902..5f75c28 100644 --- a/go/stat/types_gen.go +++ b/go/stat/types_gen.go @@ -10,15 +10,16 @@ import ( ) type Options struct { - GraphMode common.BigValueGraphMode `json:"graphMode"` - ColorMode common.BigValueColorMode `json:"colorMode"` - JustifyMode common.BigValueJustifyMode `json:"justifyMode"` - TextMode common.BigValueTextMode `json:"textMode"` - WideLayout bool `json:"wideLayout"` - ReduceOptions common.ReduceDataOptions `json:"reduceOptions"` - Text *common.VizTextDisplayOptions `json:"text,omitempty"` - ShowPercentChange bool `json:"showPercentChange"` - Orientation common.VizOrientation `json:"orientation"` + GraphMode common.BigValueGraphMode `json:"graphMode"` + ColorMode common.BigValueColorMode `json:"colorMode"` + JustifyMode common.BigValueJustifyMode `json:"justifyMode"` + TextMode common.BigValueTextMode `json:"textMode"` + WideLayout bool `json:"wideLayout"` + ShowPercentChange bool `json:"showPercentChange"` + ReduceOptions common.ReduceDataOptions `json:"reduceOptions"` + Text *common.VizTextDisplayOptions `json:"text,omitempty"` + PercentChangeColorMode common.PercentChangeColorMode `json:"percentChangeColorMode"` + Orientation common.VizOrientation `json:"orientation"` } func VariantConfig() cogvariants.PanelcfgConfig { diff --git a/go/testdata/types_gen.go b/go/testdata/types_gen.go index 1acbdf9..1762f09 100644 --- a/go/testdata/types_gen.go +++ b/go/testdata/types_gen.go @@ -8,6 +8,105 @@ import ( cogvariants "github.com/grafana/grafana-foundation-sdk/go/cog/variants" ) +type CSVWave struct { + Labels *string `json:"labels,omitempty"` + Name *string `json:"name,omitempty"` + TimeStep *int64 `json:"timeStep,omitempty"` + ValuesCSV *string `json:"valuesCSV,omitempty"` +} + +type Datasource struct { + // The apiserver version + ApiVersion *string `json:"apiVersion,omitempty"` + // The datasource plugin type + Type string `json:"type"` + // Datasource UID (NOTE: name in k8s) + Uid *string `json:"uid,omitempty"` +} + +type NodesQuery struct { + Count *int64 `json:"count,omitempty"` + Seed *int64 `json:"seed,omitempty"` + // Possible enum values: + // - `"random"` + // - `"random edges"` + // - `"response_medium"` + // - `"response_small"` + // - `"feature_showcase"` + Type *NodesQueryType `json:"type,omitempty"` +} + +type PulseWaveQuery struct { + OffCount *int64 `json:"offCount,omitempty"` + OffValue *float64 `json:"offValue,omitempty"` + OnCount *int64 `json:"onCount,omitempty"` + OnValue *float64 `json:"onValue,omitempty"` + TimeStep *int64 `json:"timeStep,omitempty"` +} + +type ResultAssertions struct { + // Maximum frame count + MaxFrames *int64 `json:"maxFrames,omitempty"` + // Type asserts that the frame matches a known type structure. + // Possible enum values: + // - `""` + // - `"timeseries-wide"` + // - `"timeseries-long"` + // - `"timeseries-many"` + // - `"timeseries-multi"` + // - `"directory-listing"` + // - `"table"` + // - `"numeric-wide"` + // - `"numeric-multi"` + // - `"numeric-long"` + // - `"log-lines"` + Type *ResultAssertionsType `json:"type,omitempty"` + // TypeVersion is the version of the Type property. Versions greater than 0.0 correspond to the dataplane + // contract documentation https://grafana.github.io/dataplane/contract/. + TypeVersion []int64 `json:"typeVersion"` +} + +type Key struct { + Tick float64 `json:"tick"` + Type string `json:"type"` + Uid *string `json:"uid,omitempty"` +} + +type SimulationQuery struct { + Config any `json:"config,omitempty"` + Key Key `json:"key"` + Last *bool `json:"last,omitempty"` + Stream *bool `json:"stream,omitempty"` +} + +type StreamingQuery struct { + Bands *int64 `json:"bands,omitempty"` + Noise float64 `json:"noise"` + Speed float64 `json:"speed"` + Spread float64 `json:"spread"` + // Possible enum values: + // - `"fetch"` + // - `"logs"` + // - `"signal"` + // - `"traces"` + Type StreamingQueryType `json:"type"` + Url *string `json:"url,omitempty"` +} + +type TimeRange struct { + // From is the start time of the query. + From string `json:"from"` + // To is the end time of the query. + To string `json:"to"` +} + +type USAQuery struct { + Fields []string `json:"fields,omitempty"` + Mode *string `json:"mode,omitempty"` + Period *string `json:"period,omitempty"` + States []string `json:"states,omitempty"` +} + type Dataquery struct { Alias *string `json:"alias,omitempty"` // Used for live query @@ -118,104 +217,40 @@ func VariantConfig() cogvariants.DataqueryConfig { } } -type CSVWave struct { - Labels *string `json:"labels,omitempty"` - Name *string `json:"name,omitempty"` - TimeStep *int64 `json:"timeStep,omitempty"` - ValuesCSV *string `json:"valuesCSV,omitempty"` -} - -type Datasource struct { - // The apiserver version - ApiVersion *string `json:"apiVersion,omitempty"` - // The datasource plugin type - Type string `json:"type"` - // Datasource UID (NOTE: name in k8s) - Uid *string `json:"uid,omitempty"` -} - -type NodesQuery struct { - Count *int64 `json:"count,omitempty"` - Seed *int64 `json:"seed,omitempty"` - // Possible enum values: - // - `"random"` - // - `"random edges"` - // - `"response_medium"` - // - `"response_small"` - // - `"feature_showcase"` - Type *NodesQueryType `json:"type,omitempty"` -} - -type PulseWaveQuery struct { - OffCount *int64 `json:"offCount,omitempty"` - OffValue *float64 `json:"offValue,omitempty"` - OnCount *int64 `json:"onCount,omitempty"` - OnValue *float64 `json:"onValue,omitempty"` - TimeStep *int64 `json:"timeStep,omitempty"` -} - -type ResultAssertions struct { - // Maximum frame count - MaxFrames *int64 `json:"maxFrames,omitempty"` - // Type asserts that the frame matches a known type structure. - // Possible enum values: - // - `""` - // - `"timeseries-wide"` - // - `"timeseries-long"` - // - `"timeseries-many"` - // - `"timeseries-multi"` - // - `"directory-listing"` - // - `"table"` - // - `"numeric-wide"` - // - `"numeric-multi"` - // - `"numeric-long"` - // - `"log-lines"` - Type *ResultAssertionsType `json:"type,omitempty"` - // TypeVersion is the version of the Type property. Versions greater than 0.0 correspond to the dataplane - // contract documentation https://grafana.github.io/dataplane/contract/. - TypeVersion []int64 `json:"typeVersion"` -} +type NodesQueryType string -type Key struct { - Tick float64 `json:"tick"` - Type string `json:"type"` - Uid *string `json:"uid,omitempty"` -} +const ( + NodesQueryTypeRandom NodesQueryType = "random" + NodesQueryTypeRandomEdges NodesQueryType = "random edges" + NodesQueryTypeResponseMedium NodesQueryType = "response_medium" + NodesQueryTypeResponseSmall NodesQueryType = "response_small" + NodesQueryTypeFeatureShowcase NodesQueryType = "feature_showcase" +) -type SimulationQuery struct { - Config any `json:"config,omitempty"` - Key Key `json:"key"` - Last *bool `json:"last,omitempty"` - Stream *bool `json:"stream,omitempty"` -} +type ResultAssertionsType string -type StreamingQuery struct { - Bands *int64 `json:"bands,omitempty"` - Noise float64 `json:"noise"` - Speed float64 `json:"speed"` - Spread float64 `json:"spread"` - // Possible enum values: - // - `"fetch"` - // - `"logs"` - // - `"signal"` - // - `"traces"` - Type StreamingQueryType `json:"type"` - Url *string `json:"url,omitempty"` -} +const ( + ResultAssertionsTypeNone ResultAssertionsType = "" + ResultAssertionsTypeTimeseriesWide ResultAssertionsType = "timeseries-wide" + ResultAssertionsTypeTimeseriesLong ResultAssertionsType = "timeseries-long" + ResultAssertionsTypeTimeseriesMany ResultAssertionsType = "timeseries-many" + ResultAssertionsTypeTimeseriesMulti ResultAssertionsType = "timeseries-multi" + ResultAssertionsTypeDirectoryListing ResultAssertionsType = "directory-listing" + ResultAssertionsTypeTable ResultAssertionsType = "table" + ResultAssertionsTypeNumericWide ResultAssertionsType = "numeric-wide" + ResultAssertionsTypeNumericMulti ResultAssertionsType = "numeric-multi" + ResultAssertionsTypeNumericLong ResultAssertionsType = "numeric-long" + ResultAssertionsTypeLogLines ResultAssertionsType = "log-lines" +) -type TimeRange struct { - // From is the start time of the query. - From string `json:"from"` - // To is the end time of the query. - To string `json:"to"` -} +type StreamingQueryType string -type USAQuery struct { - Fields []string `json:"fields,omitempty"` - Mode *string `json:"mode,omitempty"` - Period *string `json:"period,omitempty"` - States []string `json:"states,omitempty"` -} +const ( + StreamingQueryTypeFetch StreamingQueryType = "fetch" + StreamingQueryTypeLogs StreamingQueryType = "logs" + StreamingQueryTypeSignal StreamingQueryType = "signal" + StreamingQueryTypeTraces StreamingQueryType = "traces" +) type DataqueryErrorType string @@ -258,38 +293,3 @@ const ( DataqueryScenarioIdUsa DataqueryScenarioId = "usa" DataqueryScenarioIdVariablesQuery DataqueryScenarioId = "variables-query" ) - -type NodesQueryType string - -const ( - NodesQueryTypeRandom NodesQueryType = "random" - NodesQueryTypeRandomEdges NodesQueryType = "random edges" - NodesQueryTypeResponseMedium NodesQueryType = "response_medium" - NodesQueryTypeResponseSmall NodesQueryType = "response_small" - NodesQueryTypeFeatureShowcase NodesQueryType = "feature_showcase" -) - -type ResultAssertionsType string - -const ( - ResultAssertionsTypeNone ResultAssertionsType = "" - ResultAssertionsTypeTimeseriesWide ResultAssertionsType = "timeseries-wide" - ResultAssertionsTypeTimeseriesLong ResultAssertionsType = "timeseries-long" - ResultAssertionsTypeTimeseriesMany ResultAssertionsType = "timeseries-many" - ResultAssertionsTypeTimeseriesMulti ResultAssertionsType = "timeseries-multi" - ResultAssertionsTypeDirectoryListing ResultAssertionsType = "directory-listing" - ResultAssertionsTypeTable ResultAssertionsType = "table" - ResultAssertionsTypeNumericWide ResultAssertionsType = "numeric-wide" - ResultAssertionsTypeNumericMulti ResultAssertionsType = "numeric-multi" - ResultAssertionsTypeNumericLong ResultAssertionsType = "numeric-long" - ResultAssertionsTypeLogLines ResultAssertionsType = "log-lines" -) - -type StreamingQueryType string - -const ( - StreamingQueryTypeFetch StreamingQueryType = "fetch" - StreamingQueryTypeLogs StreamingQueryType = "logs" - StreamingQueryTypeSignal StreamingQueryType = "signal" - StreamingQueryTypeTraces StreamingQueryType = "traces" -) diff --git a/jsonschema/alerting.jsonschema.json b/jsonschema/alerting.jsonschema.json index 08c2bbc..f17d52d 100644 --- a/jsonschema/alerting.jsonschema.json +++ b/jsonschema/alerting.jsonschema.json @@ -1,10 +1,147 @@ { "$schema": "http://json-schema.org/draft-07/schema#", "definitions": { + "Query": { + "type": "object", + "additionalProperties": false, + "properties": { + "datasourceUid": { + "type": "string" + }, + "model": { + "type": "object", + "additionalProperties": {} + }, + "queryType": { + "type": "string" + }, + "refId": { + "type": "string" + }, + "relativeTimeRange": { + "$ref": "#/definitions/RelativeTimeRange" + } + } + }, + "RuleGroup": { + "type": "object", + "additionalProperties": false, + "properties": { + "folderUid": { + "type": "string" + }, + "interval": { + "$ref": "#/definitions/Duration", + "description": "The interval, in seconds, at which all rules in the group are evaluated.\nIf a group contains many rules, the rules are evaluated sequentially." + }, + "rules": { + "type": "array", + "items": { + "$ref": "#/definitions/Rule" + } + }, + "title": { + "type": "string" + } + } + }, + "NotificationSettings": { + "type": "object", + "additionalProperties": false, + "required": [ + "receiver" + ], + "properties": { + "group_by": { + "type": "array", + "items": { + "type": "string" + }, + "default": [ + "alertname", + "grafana_folder" + ] + }, + "group_interval": { + "type": "string" + }, + "group_wait": { + "type": "string" + }, + "mute_time_intervals": { + "type": "array", + "items": { + "type": "string" + } + }, + "receiver": { + "type": "string" + }, + "repeat_interval": { + "type": "string" + } + } + }, "Duration": { "type": "integer", "description": "Duration in seconds." }, + "ContactPoint": { + "type": "object", + "additionalProperties": false, + "required": [ + "settings", + "type" + ], + "properties": { + "disableResolveMessage": { + "type": "boolean", + "description": "EmbeddedContactPoint is the contact point type that is used\nby grafanas embedded alertmanager implementation." + }, + "name": { + "type": "string", + "description": "EmbeddedContactPoint is the contact point type that is used\nby grafanas embedded alertmanager implementation." + }, + "provenance": { + "type": "string", + "description": "EmbeddedContactPoint is the contact point type that is used\nby grafanas embedded alertmanager implementation." + }, + "settings": { + "$ref": "#/definitions/Json", + "description": "EmbeddedContactPoint is the contact point type that is used\nby grafanas embedded alertmanager implementation." + }, + "type": { + "enum": [ + "alertmanager", + " dingding", + " discord", + " email", + " googlechat", + " kafka", + " line", + " opsgenie", + " pagerduty", + " pushover", + " sensugo", + " slack", + " teams", + " telegram", + " threema", + " victorops", + " webhook", + " wecom" + ], + "description": "EmbeddedContactPoint is the contact point type that is used\nby grafanas embedded alertmanager implementation." + }, + "uid": { + "type": "string", + "minLength": 1, + "maxLength": 40, + "description": "EmbeddedContactPoint is the contact point type that is used\nby grafanas embedded alertmanager implementation." + } + }, + "description": "EmbeddedContactPoint is the contact point type that is used\nby grafanas embedded alertmanager implementation." + }, "Json": { "type": "object", "additionalProperties": {} @@ -16,7 +153,12 @@ } }, "MatchType": { - "type": "integer" + "enum": [ + "=", + "!=", + "=~", + "!~" + ] }, "Matcher": { "type": "object", @@ -40,6 +182,21 @@ }, "description": "Matchers is a slice of Matchers that is sortable, implements Stringer, and\nprovides a Matches method to match a LabelSet against all Matchers in the\nslice. Note that some users of Matchers might require it to be sorted." }, + "MuteTiming": { + "type": "object", + "additionalProperties": false, + "properties": { + "name": { + "type": "string" + }, + "time_intervals": { + "type": "array", + "items": { + "$ref": "#/definitions/TimeInterval" + } + } + } + }, "NotificationTemplate": { "type": "object", "additionalProperties": false, @@ -70,58 +227,6 @@ "Provenance": { "type": "string" }, - "RelativeTimeRange": { - "type": "object", - "additionalProperties": false, - "properties": { - "from": { - "$ref": "#/definitions/Duration", - "description": "RelativeTimeRange is the per query start and end time\nfor requests." - }, - "to": { - "$ref": "#/definitions/Duration", - "description": "RelativeTimeRange is the per query start and end time\nfor requests." - } - }, - "description": "RelativeTimeRange is the per query start and end time\nfor requests." - }, - "TimeInterval": { - "type": "object", - "additionalProperties": false, - "properties": { - "name": { - "type": "string" - }, - "time_intervals": { - "type": "array", - "items": { - "$ref": "#/definitions/TimeInterval" - } - } - } - }, - "RuleGroup": { - "type": "object", - "additionalProperties": false, - "properties": { - "folderUid": { - "type": "string" - }, - "interval": { - "$ref": "#/definitions/Duration", - "description": "The interval, in seconds, at which all rules in the group are evaluated.\nIf a group contains many rules, the rules are evaluated sequentially." - }, - "rules": { - "type": "array", - "items": { - "$ref": "#/definitions/Rule" - } - }, - "title": { - "type": "string" - } - } - }, "Rule": { "type": "object", "additionalProperties": false, @@ -215,120 +320,20 @@ } } }, - "NotificationSettings": { - "type": "object", - "additionalProperties": false, - "required": [ - "receiver" - ], - "properties": { - "group_by": { - "type": "array", - "items": { - "type": "string" - }, - "default": [ - "alertname", - "grafana_folder" - ] - }, - "group_interval": { - "type": "string" - }, - "group_wait": { - "type": "string" - }, - "mute_time_intervals": { - "type": "array", - "items": { - "type": "string" - } - }, - "receiver": { - "type": "string" - }, - "repeat_interval": { - "type": "string" - } - } - }, - "Query": { - "type": "object", - "additionalProperties": false, - "properties": { - "datasourceUid": { - "type": "string" - }, - "model": { - "type": "object", - "additionalProperties": {} - }, - "queryType": { - "type": "string" - }, - "refId": { - "type": "string" - }, - "relativeTimeRange": { - "$ref": "#/definitions/RelativeTimeRange" - } - } - }, - "ContactPoint": { + "RelativeTimeRange": { "type": "object", "additionalProperties": false, - "required": [ - "settings", - "type" - ], "properties": { - "disableResolveMessage": { - "type": "boolean", - "description": "EmbeddedContactPoint is the contact point type that is used\nby grafanas embedded alertmanager implementation." - }, - "name": { - "type": "string", - "description": "EmbeddedContactPoint is the contact point type that is used\nby grafanas embedded alertmanager implementation." - }, - "provenance": { - "type": "string", - "description": "EmbeddedContactPoint is the contact point type that is used\nby grafanas embedded alertmanager implementation." - }, - "settings": { - "$ref": "#/definitions/Json", - "description": "EmbeddedContactPoint is the contact point type that is used\nby grafanas embedded alertmanager implementation." - }, - "type": { - "enum": [ - "alertmanager", - " dingding", - " discord", - " email", - " googlechat", - " kafka", - " line", - " opsgenie", - " pagerduty", - " pushover", - " sensugo", - " slack", - " teams", - " telegram", - " threema", - " victorops", - " webhook", - " wecom" - ], - "description": "EmbeddedContactPoint is the contact point type that is used\nby grafanas embedded alertmanager implementation." + "from": { + "$ref": "#/definitions/Duration", + "description": "RelativeTimeRange is the per query start and end time\nfor requests." }, - "uid": { - "type": "string", - "minLength": 1, - "maxLength": 40, - "description": "EmbeddedContactPoint is the contact point type that is used\nby grafanas embedded alertmanager implementation." + "to": { + "$ref": "#/definitions/Duration", + "description": "RelativeTimeRange is the per query start and end time\nfor requests." } }, - "description": "EmbeddedContactPoint is the contact point type that is used\nby grafanas embedded alertmanager implementation." + "description": "RelativeTimeRange is the per query start and end time\nfor requests." }, "NotificationPolicy": { "type": "object", @@ -401,7 +406,7 @@ }, "description": "A Route is a node that contains definitions of how to handle alerts. This is modified\nfrom the upstream alertmanager in that it adds the ObjectMatchers property." }, - "MuteTiming": { + "TimeInterval": { "type": "object", "additionalProperties": false, "properties": { @@ -411,10 +416,61 @@ "time_intervals": { "type": "array", "items": { - "$ref": "#/definitions/TimeInterval" + "$ref": "#/definitions/TimeIntervalItem" } } } + }, + "TimeIntervalItem": { + "type": "object", + "additionalProperties": false, + "properties": { + "days_of_month": { + "type": "array", + "items": { + "type": "string" + } + }, + "location": { + "type": "string" + }, + "months": { + "type": "array", + "items": { + "type": "string" + } + }, + "times": { + "type": "array", + "items": { + "$ref": "#/definitions/TimeIntervalTimeRange" + } + }, + "weekdays": { + "type": "array", + "items": { + "type": "string" + } + }, + "years": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "TimeIntervalTimeRange": { + "type": "object", + "additionalProperties": false, + "properties": { + "end_time": { + "type": "string" + }, + "start_time": { + "type": "string" + } + } } } } \ No newline at end of file diff --git a/jsonschema/azuremonitor.jsonschema.json b/jsonschema/azuremonitor.jsonschema.json index d2d343e..3aa1d09 100644 --- a/jsonschema/azuremonitor.jsonschema.json +++ b/jsonschema/azuremonitor.jsonschema.json @@ -203,6 +203,10 @@ "type": "string", "description": "If dashboardTime is set to true this value dictates which column the time filter will be applied to. Defaults to the first tables timeSpan column, the first datetime column found, or TimeGenerated" }, + "basicLogsQuery": { + "type": "boolean", + "description": "If set to true the query will be run as a basic logs query" + }, "workspace": { "type": "string", "description": "Workspace ID. This was removed in Grafana 8, but remains for backwards compat." diff --git a/jsonschema/common.jsonschema.json b/jsonschema/common.jsonschema.json index bd71a75..9a0163c 100644 --- a/jsonschema/common.jsonschema.json +++ b/jsonschema/common.jsonschema.json @@ -757,6 +757,14 @@ ], "description": "TODO docs" }, + "PercentChangeColorMode": { + "enum": [ + "standard", + "inverted", + "same_as_value" + ], + "description": "TODO docs" + }, "FieldTextAlignment": { "enum": [ "auto", diff --git a/jsonschema/dashboard.jsonschema.json b/jsonschema/dashboard.jsonschema.json index 1e50241..28d29c3 100644 --- a/jsonschema/dashboard.jsonschema.json +++ b/jsonschema/dashboard.jsonschema.json @@ -101,7 +101,7 @@ "schemaVersion": { "type": "integer", "description": "Version of the JSON schema, incremented each time a Grafana update brings\nchanges to said schema.", - "default": 36 + "default": 39 }, "version": { "type": "integer", diff --git a/jsonschema/stat.jsonschema.json b/jsonschema/stat.jsonschema.json index 0fa8b86..eca0e1c 100644 --- a/jsonschema/stat.jsonschema.json +++ b/jsonschema/stat.jsonschema.json @@ -10,8 +10,9 @@ "justifyMode", "textMode", "wideLayout", - "reduceOptions", "showPercentChange", + "reduceOptions", + "percentChangeColorMode", "orientation" ], "properties": { @@ -35,15 +36,19 @@ "type": "boolean", "default": true }, + "showPercentChange": { + "type": "boolean", + "default": false + }, "reduceOptions": { "$ref": "#/definitions/ReduceDataOptions" }, "text": { "$ref": "#/definitions/VizTextDisplayOptions" }, - "showPercentChange": { - "type": "boolean", - "default": false + "percentChangeColorMode": { + "$ref": "#/definitions/PercentChangeColorMode", + "default": "standard" }, "orientation": { "$ref": "#/definitions/VizOrientation" @@ -128,6 +133,14 @@ }, "description": "TODO docs" }, + "PercentChangeColorMode": { + "enum": [ + "standard", + "inverted", + "same_as_value" + ], + "description": "TODO docs" + }, "VizOrientation": { "enum": [ "auto", diff --git a/jsonschema/testdata.jsonschema.json b/jsonschema/testdata.jsonschema.json index decaf42..b9cb127 100644 --- a/jsonschema/testdata.jsonschema.json +++ b/jsonschema/testdata.jsonschema.json @@ -1,177 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema#", "definitions": { - "dataquery": { - "type": "object", - "additionalProperties": false, - "properties": { - "alias": { - "type": "string" - }, - "channel": { - "type": "string", - "description": "Used for live query" - }, - "csvContent": { - "type": "string" - }, - "csvFileName": { - "type": "string" - }, - "csvWave": { - "type": "array", - "items": { - "$ref": "#/definitions/CSVWave" - } - }, - "datasource": { - "$ref": "#/definitions/datasource", - "description": "The datasource" - }, - "dropPercent": { - "type": "number", - "description": "Drop percentage (the chance we will lose a point 0-100)" - }, - "errorType": { - "enum": [ - "frontend_exception", - "frontend_observable", - "server_panic" - ], - "description": "Possible enum values:\n - `\"frontend_exception\"` \n - `\"frontend_observable\"` \n - `\"server_panic\"` " - }, - "flamegraphDiff": { - "type": "boolean" - }, - "hide": { - "type": "boolean", - "description": "true if query is disabled (ie should not be returned to the dashboard)\nNOTE: this does not always imply that the query should not be executed since\nthe results from a hidden query may be used as the input to other queries (SSE etc)" - }, - "intervalMs": { - "type": "number", - "description": "Interval is the suggested duration between time points in a time series query.\nNOTE: the values for intervalMs is not saved in the query model. It is typically calculated\nfrom the interval required to fill a pixels in the visualization" - }, - "labels": { - "type": "string" - }, - "levelColumn": { - "type": "boolean" - }, - "lines": { - "type": "integer" - }, - "max": { - "type": "number" - }, - "maxDataPoints": { - "type": "integer", - "description": "MaxDataPoints is the maximum number of data points that should be returned from a time series query.\nNOTE: the values for maxDataPoints is not saved in the query model. It is typically calculated\nfrom the number of pixels visible in a visualization" - }, - "min": { - "type": "number" - }, - "nodes": { - "$ref": "#/definitions/NodesQuery" - }, - "noise": { - "type": "number" - }, - "points": { - "type": "array", - "items": { - "type": "array", - "items": { - "type": "object", - "additionalProperties": {} - } - } - }, - "pulseWave": { - "$ref": "#/definitions/PulseWaveQuery" - }, - "queryType": { - "type": "string", - "description": "QueryType is an optional identifier for the type of query.\nIt can be used to distinguish different types of queries." - }, - "rawFrameContent": { - "type": "string" - }, - "refId": { - "type": "string", - "description": "RefID is the unique identifier of the query, set by the frontend call." - }, - "resultAssertions": { - "$ref": "#/definitions/ResultAssertions", - "description": "Optionally define expected query result behavior" - }, - "scenarioId": { - "enum": [ - "annotations", - "arrow", - "csv_content", - "csv_file", - "csv_metric_values", - "datapoints_outside_range", - "exponential_heatmap_bucket_data", - "flame_graph", - "grafana_api", - "linear_heatmap_bucket_data", - "live", - "logs", - "manual_entry", - "no_data_points", - "node_graph", - "predictable_csv_wave", - "predictable_pulse", - "random_walk", - "random_walk_table", - "random_walk_with_error", - "raw_frame", - "server_error_500", - "simulation", - "slow_query", - "streaming_client", - "table_static", - "trace", - "usa", - "variables-query" - ], - "description": "Possible enum values:\n - `\"annotations\"` \n - `\"arrow\"` \n - `\"csv_content\"` \n - `\"csv_file\"` \n - `\"csv_metric_values\"` \n - `\"datapoints_outside_range\"` \n - `\"exponential_heatmap_bucket_data\"` \n - `\"flame_graph\"` \n - `\"grafana_api\"` \n - `\"linear_heatmap_bucket_data\"` \n - `\"live\"` \n - `\"logs\"` \n - `\"manual_entry\"` \n - `\"no_data_points\"` \n - `\"node_graph\"` \n - `\"predictable_csv_wave\"` \n - `\"predictable_pulse\"` \n - `\"random_walk\"` \n - `\"random_walk_table\"` \n - `\"random_walk_with_error\"` \n - `\"raw_frame\"` \n - `\"server_error_500\"` \n - `\"simulation\"` \n - `\"slow_query\"` \n - `\"streaming_client\"` \n - `\"table_static\"` \n - `\"trace\"` \n - `\"usa\"` \n - `\"variables-query\"` " - }, - "seriesCount": { - "type": "integer" - }, - "sim": { - "$ref": "#/definitions/SimulationQuery" - }, - "spanCount": { - "type": "integer" - }, - "spread": { - "type": "number" - }, - "startValue": { - "type": "number" - }, - "stream": { - "$ref": "#/definitions/StreamingQuery" - }, - "stringInput": { - "type": "string", - "description": "common parameter used by many query types" - }, - "timeRange": { - "$ref": "#/definitions/TimeRange", - "description": "TimeRange represents the query range\nNOTE: unlike generic /ds/query, we can now send explicit time values in each query\nNOTE: the values for timeRange are not saved in a dashboard, they are constructed on the fly" - }, - "usa": { - "$ref": "#/definitions/USAQuery" - }, - "withNil": { - "type": "boolean" - } - } - }, "CSVWave": { "type": "object", "additionalProperties": false, @@ -410,6 +239,177 @@ } } } + }, + "dataquery": { + "type": "object", + "additionalProperties": false, + "properties": { + "alias": { + "type": "string" + }, + "channel": { + "type": "string", + "description": "Used for live query" + }, + "csvContent": { + "type": "string" + }, + "csvFileName": { + "type": "string" + }, + "csvWave": { + "type": "array", + "items": { + "$ref": "#/definitions/CSVWave" + } + }, + "datasource": { + "$ref": "#/definitions/datasource", + "description": "The datasource" + }, + "dropPercent": { + "type": "number", + "description": "Drop percentage (the chance we will lose a point 0-100)" + }, + "errorType": { + "enum": [ + "frontend_exception", + "frontend_observable", + "server_panic" + ], + "description": "Possible enum values:\n - `\"frontend_exception\"` \n - `\"frontend_observable\"` \n - `\"server_panic\"` " + }, + "flamegraphDiff": { + "type": "boolean" + }, + "hide": { + "type": "boolean", + "description": "true if query is disabled (ie should not be returned to the dashboard)\nNOTE: this does not always imply that the query should not be executed since\nthe results from a hidden query may be used as the input to other queries (SSE etc)" + }, + "intervalMs": { + "type": "number", + "description": "Interval is the suggested duration between time points in a time series query.\nNOTE: the values for intervalMs is not saved in the query model. It is typically calculated\nfrom the interval required to fill a pixels in the visualization" + }, + "labels": { + "type": "string" + }, + "levelColumn": { + "type": "boolean" + }, + "lines": { + "type": "integer" + }, + "max": { + "type": "number" + }, + "maxDataPoints": { + "type": "integer", + "description": "MaxDataPoints is the maximum number of data points that should be returned from a time series query.\nNOTE: the values for maxDataPoints is not saved in the query model. It is typically calculated\nfrom the number of pixels visible in a visualization" + }, + "min": { + "type": "number" + }, + "nodes": { + "$ref": "#/definitions/NodesQuery" + }, + "noise": { + "type": "number" + }, + "points": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "object", + "additionalProperties": {} + } + } + }, + "pulseWave": { + "$ref": "#/definitions/PulseWaveQuery" + }, + "queryType": { + "type": "string", + "description": "QueryType is an optional identifier for the type of query.\nIt can be used to distinguish different types of queries." + }, + "rawFrameContent": { + "type": "string" + }, + "refId": { + "type": "string", + "description": "RefID is the unique identifier of the query, set by the frontend call." + }, + "resultAssertions": { + "$ref": "#/definitions/ResultAssertions", + "description": "Optionally define expected query result behavior" + }, + "scenarioId": { + "enum": [ + "annotations", + "arrow", + "csv_content", + "csv_file", + "csv_metric_values", + "datapoints_outside_range", + "exponential_heatmap_bucket_data", + "flame_graph", + "grafana_api", + "linear_heatmap_bucket_data", + "live", + "logs", + "manual_entry", + "no_data_points", + "node_graph", + "predictable_csv_wave", + "predictable_pulse", + "random_walk", + "random_walk_table", + "random_walk_with_error", + "raw_frame", + "server_error_500", + "simulation", + "slow_query", + "streaming_client", + "table_static", + "trace", + "usa", + "variables-query" + ], + "description": "Possible enum values:\n - `\"annotations\"` \n - `\"arrow\"` \n - `\"csv_content\"` \n - `\"csv_file\"` \n - `\"csv_metric_values\"` \n - `\"datapoints_outside_range\"` \n - `\"exponential_heatmap_bucket_data\"` \n - `\"flame_graph\"` \n - `\"grafana_api\"` \n - `\"linear_heatmap_bucket_data\"` \n - `\"live\"` \n - `\"logs\"` \n - `\"manual_entry\"` \n - `\"no_data_points\"` \n - `\"node_graph\"` \n - `\"predictable_csv_wave\"` \n - `\"predictable_pulse\"` \n - `\"random_walk\"` \n - `\"random_walk_table\"` \n - `\"random_walk_with_error\"` \n - `\"raw_frame\"` \n - `\"server_error_500\"` \n - `\"simulation\"` \n - `\"slow_query\"` \n - `\"streaming_client\"` \n - `\"table_static\"` \n - `\"trace\"` \n - `\"usa\"` \n - `\"variables-query\"` " + }, + "seriesCount": { + "type": "integer" + }, + "sim": { + "$ref": "#/definitions/SimulationQuery" + }, + "spanCount": { + "type": "integer" + }, + "spread": { + "type": "number" + }, + "startValue": { + "type": "number" + }, + "stream": { + "$ref": "#/definitions/StreamingQuery" + }, + "stringInput": { + "type": "string", + "description": "common parameter used by many query types" + }, + "timeRange": { + "$ref": "#/definitions/TimeRange", + "description": "TimeRange represents the query range\nNOTE: unlike generic /ds/query, we can now send explicit time values in each query\nNOTE: the values for timeRange are not saved in a dashboard, they are constructed on the fly" + }, + "usa": { + "$ref": "#/definitions/USAQuery" + }, + "withNil": { + "type": "boolean" + } + } } } } \ No newline at end of file diff --git a/openapi/alerting.openapi.json b/openapi/alerting.openapi.json index 0b1a7bf..c47f39c 100644 --- a/openapi/alerting.openapi.json +++ b/openapi/alerting.openapi.json @@ -9,10 +9,147 @@ "paths": {}, "components": { "schemas": { + "Query": { + "type": "object", + "additionalProperties": false, + "properties": { + "datasourceUid": { + "type": "string" + }, + "model": { + "type": "object", + "additionalProperties": {} + }, + "queryType": { + "type": "string" + }, + "refId": { + "type": "string" + }, + "relativeTimeRange": { + "$ref": "#/components/schemas/RelativeTimeRange" + } + } + }, + "RuleGroup": { + "type": "object", + "additionalProperties": false, + "properties": { + "folderUid": { + "type": "string" + }, + "interval": { + "$ref": "#/components/schemas/Duration", + "description": "The interval, in seconds, at which all rules in the group are evaluated.\nIf a group contains many rules, the rules are evaluated sequentially." + }, + "rules": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Rule" + } + }, + "title": { + "type": "string" + } + } + }, + "NotificationSettings": { + "type": "object", + "additionalProperties": false, + "required": [ + "receiver" + ], + "properties": { + "group_by": { + "type": "array", + "items": { + "type": "string" + }, + "default": [ + "alertname", + "grafana_folder" + ] + }, + "group_interval": { + "type": "string" + }, + "group_wait": { + "type": "string" + }, + "mute_time_intervals": { + "type": "array", + "items": { + "type": "string" + } + }, + "receiver": { + "type": "string" + }, + "repeat_interval": { + "type": "string" + } + } + }, "Duration": { "type": "integer", "description": "Duration in seconds." }, + "ContactPoint": { + "type": "object", + "additionalProperties": false, + "required": [ + "settings", + "type" + ], + "properties": { + "disableResolveMessage": { + "type": "boolean", + "description": "EmbeddedContactPoint is the contact point type that is used\nby grafanas embedded alertmanager implementation." + }, + "name": { + "type": "string", + "description": "EmbeddedContactPoint is the contact point type that is used\nby grafanas embedded alertmanager implementation." + }, + "provenance": { + "type": "string", + "description": "EmbeddedContactPoint is the contact point type that is used\nby grafanas embedded alertmanager implementation." + }, + "settings": { + "$ref": "#/components/schemas/Json", + "description": "EmbeddedContactPoint is the contact point type that is used\nby grafanas embedded alertmanager implementation." + }, + "type": { + "enum": [ + "alertmanager", + " dingding", + " discord", + " email", + " googlechat", + " kafka", + " line", + " opsgenie", + " pagerduty", + " pushover", + " sensugo", + " slack", + " teams", + " telegram", + " threema", + " victorops", + " webhook", + " wecom" + ], + "description": "EmbeddedContactPoint is the contact point type that is used\nby grafanas embedded alertmanager implementation." + }, + "uid": { + "type": "string", + "minLength": 1, + "maxLength": 40, + "description": "EmbeddedContactPoint is the contact point type that is used\nby grafanas embedded alertmanager implementation." + } + }, + "description": "EmbeddedContactPoint is the contact point type that is used\nby grafanas embedded alertmanager implementation." + }, "Json": { "type": "object", "additionalProperties": {} @@ -24,7 +161,12 @@ } }, "MatchType": { - "type": "integer" + "enum": [ + "=", + "!=", + "=~", + "!~" + ] }, "Matcher": { "type": "object", @@ -48,6 +190,21 @@ }, "description": "Matchers is a slice of Matchers that is sortable, implements Stringer, and\nprovides a Matches method to match a LabelSet against all Matchers in the\nslice. Note that some users of Matchers might require it to be sorted." }, + "MuteTiming": { + "type": "object", + "additionalProperties": false, + "properties": { + "name": { + "type": "string" + }, + "time_intervals": { + "type": "array", + "items": { + "$ref": "#/components/schemas/TimeInterval" + } + } + } + }, "NotificationTemplate": { "type": "object", "additionalProperties": false, @@ -78,58 +235,6 @@ "Provenance": { "type": "string" }, - "RelativeTimeRange": { - "type": "object", - "additionalProperties": false, - "properties": { - "from": { - "$ref": "#/components/schemas/Duration", - "description": "RelativeTimeRange is the per query start and end time\nfor requests." - }, - "to": { - "$ref": "#/c...*[Comment body truncated]*