grafana / cog

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

Make working with instant/range prometheus queries more intuitive #424

Closed K-Phoen closed 4 months ago

K-Phoen commented 4 months ago

This PR makes it more intuitive to define range/instant queries in prometheus. The API now exposed for this follows what the UI does.

github-actions[bot] commented 4 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/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/dashboard/constantvariable_builder_gen.go b/go/dashboard/constantvariable_builder_gen.go index a8148d8..62fd208 100644 --- a/go/dashboard/constantvariable_builder_gen.go +++ b/go/dashboard/constantvariable_builder_gen.go @@ -64,7 +64,7 @@ func (builder *ConstantVariableBuilder) Description(description string) *Constan } // Query used to fetch values for a variable -func (builder *ConstantVariableBuilder) Value(query StringOrAny) *ConstantVariableBuilder { +func (builder *ConstantVariableBuilder) Value(query StringOrMap) *ConstantVariableBuilder { builder.internal.Query = &query return builder diff --git a/go/dashboard/customvariable_builder_gen.go b/go/dashboard/customvariable_builder_gen.go index 2bc9bde..f6db129 100644 --- a/go/dashboard/customvariable_builder_gen.go +++ b/go/dashboard/customvariable_builder_gen.go @@ -71,7 +71,7 @@ func (builder *CustomVariableBuilder) Description(description string) *CustomVar } // Query used to fetch values for a variable -func (builder *CustomVariableBuilder) Values(query StringOrAny) *CustomVariableBuilder { +func (builder *CustomVariableBuilder) Values(query StringOrMap) *CustomVariableBuilder { builder.internal.Query = &query return builder diff --git a/go/dashboard/dashboard_builder_gen.go b/go/dashboard/dashboard_builder_gen.go index 2436bc7..cebab62 100644 --- a/go/dashboard/dashboard_builder_gen.go +++ b/go/dashboard/dashboard_builder_gen.go @@ -243,12 +243,14 @@ func (builder *DashboardBuilder) WithRow(rowPanel cog.Builder[RowPanel]) *Dashbo } // Position the row on the grid - rowPanelResource.GridPos = &GridPos{ - X: 0, // beginning of the line - Y: builder.currentY + builder.lastPanelHeight, + if rowPanelResource.GridPos == nil || (rowPanelResource.GridPos.X == 0 && rowPanelResource.GridPos.Y == 0) { + rowPanelResource.GridPos = &GridPos{ + X: 0, // beginning of the line + Y: builder.currentY + builder.lastPanelHeight, - H: 1, - W: 24, // full width + H: 1, + W: 24, // full width + } } builder.internal.Panels = append(builder.internal.Panels, PanelOrRowPanel{ RowPanel: &rowPanelResource, diff --git a/go/dashboard/datasourcevariable_builder_gen.go b/go/dashboard/datasourcevariable_builder_gen.go index 20a7bd9..77cdec6 100644 --- a/go/dashboard/datasourcevariable_builder_gen.go +++ b/go/dashboard/datasourcevariable_builder_gen.go @@ -73,7 +73,7 @@ func (builder *DatasourceVariableBuilder) Description(description string) *Datas // Query used to fetch values for a variable func (builder *DatasourceVariableBuilder) Type(string string) *DatasourceVariableBuilder { if builder.internal.Query == nil { - builder.internal.Query = &StringOrAny{} + builder.internal.Query = &StringOrMap{} } builder.internal.Query.String = &string diff --git a/go/dashboard/intervalvariable_builder_gen.go b/go/dashboard/intervalvariable_builder_gen.go index e36586d..d2e618c 100644 --- a/go/dashboard/intervalvariable_builder_gen.go +++ b/go/dashboard/intervalvariable_builder_gen.go @@ -71,7 +71,7 @@ func (builder *IntervalVariableBuilder) Description(description string) *Interva } // Query used to fetch values for a variable -func (builder *IntervalVariableBuilder) Values(query StringOrAny) *IntervalVariableBuilder { +func (builder *IntervalVariableBuilder) Values(query StringOrMap) *IntervalVariableBuilder { builder.internal.Query = &query return builder diff --git a/go/dashboard/queryvariable_builder_gen.go b/go/dashboard/queryvariable_builder_gen.go index 38f0e13..9f2846b 100644 --- a/go/dashboard/queryvariable_builder_gen.go +++ b/go/dashboard/queryvariable_builder_gen.go @@ -71,7 +71,7 @@ func (builder *QueryVariableBuilder) Description(description string) *QueryVaria } // Query used to fetch values for a variable -func (builder *QueryVariableBuilder) Query(query StringOrAny) *QueryVariableBuilder { +func (builder *QueryVariableBuilder) Query(query StringOrMap) *QueryVariableBuilder { builder.internal.Query = &query return builder diff --git a/go/dashboard/row_builder_gen.go b/go/dashboard/row_builder_gen.go index 64f54c5..0be42d2 100644 --- a/go/dashboard/row_builder_gen.go +++ b/go/dashboard/row_builder_gen.go @@ -63,6 +63,13 @@ func (builder *RowBuilder) Datasource(datasource DataSourceRef) *RowBuilder { return builder } +// Row grid position +func (builder *RowBuilder) GridPos(gridPos GridPos) *RowBuilder { + builder.internal.GridPos = &gridPos + + return builder +} + // Unique identifier of the panel. Generated by Grafana when creating a new panel. It must be unique within a dashboard, but not globally. func (builder *RowBuilder) Id(id uint32) *RowBuilder { builder.internal.Id = id diff --git a/go/dashboard/snapshot_builder_gen.go b/go/dashboard/snapshot_builder_gen.go index 3bcc084..e0528c9 100644 --- a/go/dashboard/snapshot_builder_gen.go +++ b/go/dashboard/snapshot_builder_gen.go @@ -3,8 +3,6 @@ package dashboard import ( - "time" - cog "github.com/grafana/grafana-foundation-sdk/go/cog" ) @@ -46,13 +44,6 @@ func (builder *SnapshotBuilder) Build() (Snapshot, error) { return *builder.internal, nil } -// Time when the snapshot was created -func (builder *SnapshotBuilder) Created(created time.Time) *SnapshotBuilder { - builder.internal.Created = created - - return builder -} - // Time when the snapshot expires, default is never to expire func (builder *SnapshotBuilder) Expires(expires string) *SnapshotBuilder { builder.internal.Expires = expires @@ -109,13 +100,6 @@ func (builder *SnapshotBuilder) OrgId(orgId uint32) *SnapshotBuilder { return builder } -// last time when the snapshot was updated -func (builder *SnapshotBuilder) Updated(updated time.Time) *SnapshotBuilder { - builder.internal.Updated = updated - - return builder -} - // url of the snapshot, if snapshot was shared internally func (builder *SnapshotBuilder) Url(url string) *SnapshotBuilder { builder.internal.Url = &url @@ -123,9 +107,13 @@ func (builder *SnapshotBuilder) Url(url string) *SnapshotBuilder { return builder } -// user id of the snapshot creator -func (builder *SnapshotBuilder) UserId(userId uint32) *SnapshotBuilder { - builder.internal.UserId = userId +func (builder *SnapshotBuilder) Dashboard(dashboard cog.Builder[Dashboard]) *SnapshotBuilder { + dashboardResource, err := dashboard.Build() + if err != nil { + builder.errors["dashboard"] = err.(cog.BuildErrors) + return builder + } + builder.internal.Dashboard = &dashboardResource return builder } diff --git a/go/dashboard/textboxvariable_builder_gen.go b/go/dashboard/textboxvariable_builder_gen.go index 6fa6504..da3933f 100644 --- a/go/dashboard/textboxvariable_builder_gen.go +++ b/go/dashboard/textboxvariable_builder_gen.go @@ -71,7 +71,7 @@ func (builder *TextBoxVariableBuilder) Description(description string) *TextBoxV } // Query used to fetch values for a variable -func (builder *TextBoxVariableBuilder) DefaultValue(query StringOrAny) *TextBoxVariableBuilder { +func (builder *TextBoxVariableBuilder) DefaultValue(query StringOrMap) *TextBoxVariableBuilder { builder.internal.Query = &query return builder diff --git a/go/dashboard/types_gen.go b/go/dashboard/types_gen.go index 8efedaa..fef9956 100644 --- a/go/dashboard/types_gen.go +++ b/go/dashboard/types_gen.go @@ -149,7 +149,7 @@ type VariableModel struct { // Description of variable. It can be defined but `null`. Description *string `json:"description,omitempty"` // Query used to fetch values for a variable - Query *StringOrAny `json:"query,omitempty"` + Query *StringOrMap `json:"query,omitempty"` // Data source used to fetch values for a variable. It can be defined but `null`. Datasource *DataSourceRef `json:"datasource,omitempty"` // Shows current selected variable text/value on the dashboard @@ -548,7 +548,8 @@ type Snapshot struct { // url of the snapshot, if snapshot was shared internally Url *string `json:"url,omitempty"` // user id of the snapshot creator - UserId uint32 `json:"userId"` + UserId uint32 `json:"userId"` + Dashboard *Dashboard `json:"dashboard,omitempty"` } // Dashboard panels are the basic visualization building blocks. @@ -995,24 +996,24 @@ func (resource *PanelOrRowPanel) UnmarshalJSON(raw []byte) error { return fmt.Errorf("could not unmarshal resource with `type = %v`", discriminator) } -type StringOrAny struct { - String *string `json:"String,omitempty"` - Any any `json:"Any,omitempty"` +type StringOrMap struct { + String *string `json:"String,omitempty"` + Map map[string]any `json:"Map,omitempty"` } -func (resource StringOrAny) MarshalJSON() ([]byte, error) { +func (resource StringOrMap) MarshalJSON() ([]byte, error) { if resource.String != nil { return json.Marshal(resource.String) } - if resource.Any != nil { - return json.Marshal(resource.Any) + if resource.Map != nil { + return json.Marshal(resource.Map) } return nil, fmt.Errorf("no value for disjunction of scalars") } -func (resource *StringOrAny) UnmarshalJSON(raw []byte) error { +func (resource *StringOrMap) UnmarshalJSON(raw []byte) error { if raw == nil { return nil } @@ -1029,13 +1030,13 @@ func (resource *StringOrAny) UnmarshalJSON(raw []byte) error { return nil } - // Any - var Any any - if err := json.Unmarshal(raw, &Any); err != nil { + // Map + var Map map[string]any + if err := json.Unmarshal(raw, &Map); err != nil { errList = append(errList, err) - resource.Any = nil + resource.Map = nil } else { - resource.Any = &Any + resource.Map = Map return nil } diff --git a/go/elasticsearch/dataquery_builder_gen.go b/go/elasticsearch/dataquery_builder_gen.go index ed381e5..51cb1c7 100644 --- a/go/elasticsearch/dataquery_builder_gen.go +++ b/go/elasticsearch/dataquery_builder_gen.go @@ -79,7 +79,7 @@ func (builder *DataqueryBuilder) Metrics(metrics []MetricAggregation) *Dataquery // In server side expressions, the refId is used as a variable name to identify results. // By default, the UI will assign A->Z; however setting meaningful names may be useful. func (builder *DataqueryBuilder) RefId(refId string) *DataqueryBuilder { - builder.internal.RefId = &refId + builder.internal.RefId = refId return builder } diff --git a/go/elasticsearch/movingaverage_builder_gen.go b/go/elasticsearch/movingaverage_builder_gen.go index 83227e7..4420a1b 100644 --- a/go/elasticsearch/movingaverage_builder_gen.go +++ b/go/elasticsearch/movingaverage_builder_gen.go @@ -59,8 +59,8 @@ func (builder *MovingAverageBuilder) Id(id string) *MovingAverageBuilder { return builder } -func (builder *MovingAverageBuilder) Settings(settings any) *MovingAverageBuilder { - builder.internal.Settings = &settings +func (builder *MovingAverageBuilder) Settings(settings map[string]any) *MovingAverageBuilder { + builder.internal.Settings = settings return builder } diff --git a/go/elasticsearch/types_gen.go b/go/elasticsearch/types_gen.go index 240254e..c942c99 100644 --- a/go/elasticsearch/types_gen.go +++ b/go/elasticsearch/types_gen.go @@ -417,12 +417,12 @@ type MovingAverageHoltWintersModelSettings struct { // #MovingAverage's settings are overridden in types.ts type MovingAverage struct { - PipelineAgg *string `json:"pipelineAgg,omitempty"` - Field *string `json:"field,omitempty"` - Type string `json:"type"` - Id string `json:"id"` - Settings any `json:"settings,omitempty"` - Hide *bool `json:"hide,omitempty"` + PipelineAgg *string `json:"pipelineAgg,omitempty"` + Field *string `json:"field,omitempty"` + Type string `json:"type"` + Id string `json:"id"` + Settings map[string]any `json:"settings,omitempty"` + Hide *bool `json:"hide,omitempty"` } type MovingFunction struct { @@ -510,7 +510,7 @@ type Dataquery struct { // A unique identifier for the query within the list of targets. // In server side expressions, the refId is used as a variable name to identify results. // By default, the UI will assign A->Z; however setting meaningful names may be useful. - RefId *string `json:"refId,omitempty"` + RefId string `json:"refId"` // If hide is set to true, Grafana will filter out the response(s) associated with this query before returning it to the panel. Hide *bool `json:"hide,omitempty"` // Specify the query flavor diff --git a/go/grafanapyroscope/dataquery_builder_gen.go b/go/grafanapyroscope/dataquery_builder_gen.go index 6283837..b2c91f6 100644 --- a/go/grafanapyroscope/dataquery_builder_gen.go +++ b/go/grafanapyroscope/dataquery_builder_gen.go @@ -42,7 +42,7 @@ func (builder *DataqueryBuilder) Build() (cogvariants.Dataquery, error) { // Specifies the query label selectors. func (builder *DataqueryBuilder) LabelSelector(labelSelector string) *DataqueryBuilder { - builder.internal.LabelSelector = &labelSelector + builder.internal.LabelSelector = labelSelector return builder } @@ -56,7 +56,7 @@ func (builder *DataqueryBuilder) SpanSelector(spanSelector []string) *DataqueryB // Specifies the type of profile to query. func (builder *DataqueryBuilder) ProfileTypeId(profileTypeId string) *DataqueryBuilder { - builder.internal.ProfileTypeId = &profileTypeId + builder.internal.ProfileTypeId = profileTypeId return builder } @@ -79,7 +79,7 @@ func (builder *DataqueryBuilder) MaxNodes(maxNodes int64) *DataqueryBuilder { // In server side expressions, the refId is used as a variable name to identify results. // By default, the UI will assign A->Z; however setting meaningful names may be useful. func (builder *DataqueryBuilder) RefId(refId string) *DataqueryBuilder { - builder.internal.RefId = &refId + builder.internal.RefId = refId return builder } diff --git a/go/grafanapyroscope/types_gen.go b/go/grafanapyroscope/types_gen.go index 38b93fc..72ca853 100644 --- a/go/grafanapyroscope/types_gen.go +++ b/go/grafanapyroscope/types_gen.go @@ -18,19 +18,19 @@ const ( type Dataquery struct { // Specifies the query label selectors. - LabelSelector *string `json:"labelSelector,omitempty"` + LabelSelector string `json:"labelSelector"` // Specifies the query span selectors. SpanSelector []string `json:"spanSelector,omitempty"` // Specifies the type of profile to query. - ProfileTypeId *string `json:"profileTypeId,omitempty"` + ProfileTypeId string `json:"profileTypeId"` // Allows to group the results. - GroupBy []string `json:"groupBy,omitempty"` + GroupBy []string `json:"groupBy"` // Sets the maximum number of nodes in the flamegraph. MaxNodes *int64 `json:"maxNodes,omitempty"` // A unique identifier for the query within the list of targets. // In server side expressions, the refId is used as a variable name to identify results. // By default, the UI will assign A->Z; however setting meaningful names may be useful. - RefId *string `json:"refId,omitempty"` + RefId string `json:"refId"` // If hide is set to true, Grafana will filter out the response(s) associated with this query before returning it to the panel. Hide *bool `json:"hide,omitempty"` // Specify the query flavor diff --git a/go/loki/dataquery_builder_gen.go b/go/loki/dataquery_builder_gen.go index 4cb40da..103341c 100644 --- a/go/loki/dataquery_builder_gen.go +++ b/go/loki/dataquery_builder_gen.go @@ -42,7 +42,7 @@ func (builder *DataqueryBuilder) Build() (cogvariants.Dataquery, error) { // The LogQL query. func (builder *DataqueryBuilder) Expr(expr string) *DataqueryBuilder { - builder.internal.Expr = &expr + builder.internal.Expr = expr return builder } @@ -99,7 +99,7 @@ func (builder *DataqueryBuilder) Step(step string) *DataqueryBuilder { // In server side expressions, the refId is used as a variable name to identify results. // By default, the UI will assign A->Z; however setting meaningful names may be useful. func (builder *DataqueryBuilder) RefId(refId string) *DataqueryBuilder { - builder.internal.RefId = &refId + builder.internal.RefId = refId return builder } diff --git a/go/loki/types_gen.go b/go/loki/types_gen.go index 0b9c169..fde967a 100644 --- a/go/loki/types_gen.go +++ b/go/loki/types_gen.go @@ -41,7 +41,7 @@ const ( type Dataquery struct { // The LogQL query. - Expr *string `json:"expr,omitempty"` + Expr string `json:"expr"` // Used to override the name of the series. LegendFormat *string `json:"legendFormat,omitempty"` // Used to limit the number of log rows returned. @@ -58,7 +58,7 @@ type Dataquery struct { // A unique identifier for the query within the list of targets. // In server side expressions, the refId is used as a variable name to identify results. // By default, the UI will assign A->Z; however setting meaningful names may be useful. - RefId *string `json:"refId,omitempty"` + RefId string `json:"refId"` // If hide is set to true, Grafana will filter out the response(s) associated with this query before returning it to the panel. Hide *bool `json:"hide,omitempty"` // Specify the query flavor diff --git a/go/parca/dataquery_builder_gen.go b/go/parca/dataquery_builder_gen.go index 5419d69..202ab34 100644 --- a/go/parca/dataquery_builder_gen.go +++ b/go/parca/dataquery_builder_gen.go @@ -42,14 +42,14 @@ func (builder *DataqueryBuilder) Build() (cogvariants.Dataquery, error) { // Specifies the query label selectors. func (builder *DataqueryBuilder) LabelSelector(labelSelector string) *DataqueryBuilder { - builder.internal.LabelSelector = &labelSelector + builder.internal.LabelSelector = labelSelector return builder } // Specifies the type of profile to query. func (builder *DataqueryBuilder) ProfileTypeId(profileTypeId string) *DataqueryBuilder { - builder.internal.ProfileTypeId = &profileTypeId + builder.internal.ProfileTypeId = profileTypeId return builder } @@ -58,7 +58,7 @@ func (builder *DataqueryBuilder) ProfileTypeId(profileTypeId string) *DataqueryB // In server side expressions, the refId is used as a variable name to identify results. // By default, the UI will assign A->Z; however setting meaningful names may be useful. func (builder *DataqueryBuilder) RefId(refId string) *DataqueryBuilder { - builder.internal.RefId = &refId + builder.internal.RefId = refId return builder } diff --git a/go/parca/types_gen.go b/go/parca/types_gen.go index 6216bcb..bf22114 100644 --- a/go/parca/types_gen.go +++ b/go/parca/types_gen.go @@ -18,13 +18,13 @@ const ( type Dataquery struct { // Specifies the query label selectors. - LabelSelector *string `json:"labelSelector,omitempty"` + LabelSelector string `json:"labelSelector"` // Specifies the type of profile to query. - ProfileTypeId *string `json:"profileTypeId,omitempty"` + ProfileTypeId string `json:"profileTypeId"` // A unique identifier for the query within the list of targets. // In server side expressions, the refId is used as a variable name to identify results. // By default, the UI will assign A->Z; however setting meaningful names may be useful. - RefId *string `json:"refId,omitempty"` + RefId string `json:"refId"` // If hide is set to true, Grafana will filter out the response(s) associated with this query before returning it to the panel. Hide *bool `json:"hide,omitempty"` // Specify the query flavor diff --git a/go/prometheus/dataquery_builder_gen.go b/go/prometheus/dataquery_builder_gen.go index cb18d8d..804d6c0 100644 --- a/go/prometheus/dataquery_builder_gen.go +++ b/go/prometheus/dataquery_builder_gen.go @@ -42,21 +42,27 @@ func (builder *DataqueryBuilder) Build() (cogvariants.Dataquery, error) { // The actual expression/query that will be evaluated by Prometheus func (builder *DataqueryBuilder) Expr(expr string) *DataqueryBuilder { - builder.internal.Expr = &expr + builder.internal.Expr = expr return builder } // Returns only the latest value that Prometheus has scraped for the requested time series -func (builder *DataqueryBuilder) Instant(instant bool) *DataqueryBuilder { - builder.internal.Instant = &instant +func (builder *DataqueryBuilder) Instant() *DataqueryBuilder { + valInstant := true + builder.internal.Instant = &valInstant + valRange := false + builder.internal.Range = &valRange return builder } // Returns a Range vector, comprised of a set of time series containing a range of data points over time for each time series -func (builder *DataqueryBuilder) Range(rangeArg bool) *DataqueryBuilder { - builder.internal.Range = &rangeArg +func (builder *DataqueryBuilder) Range() *DataqueryBuilder { + valRange := true + builder.internal.Range = &valRange + valInstant := false + builder.internal.Instant = &valInstant return builder } @@ -101,7 +107,7 @@ func (builder *DataqueryBuilder) IntervalFactor(intervalFactor float64) *Dataque // In server side expressions, the refId is used as a variable name to identify results. // By default, the UI will assign A->Z; however setting meaningful names may be useful. func (builder *DataqueryBuilder) RefId(refId string) *DataqueryBuilder { - builder.internal.RefId = &refId + builder.internal.RefId = refId return builder } @@ -139,5 +145,14 @@ func (builder *DataqueryBuilder) Interval(interval string) *DataqueryBuilder { return builder } +func (builder *DataqueryBuilder) RangeAndInstant() *DataqueryBuilder { + valRange := true + builder.internal.Range = &valRange + valInstant := true + builder.internal.Instant = &valInstant + + return builder +} + func (builder *DataqueryBuilder) applyDefaults() { } diff --git a/go/prometheus/types_gen.go b/go/prometheus/types_gen.go index 0f0b6cb..55b5ead 100644 --- a/go/prometheus/types_gen.go +++ b/go/prometheus/types_gen.go @@ -25,7 +25,7 @@ const ( type Dataquery struct { // The actual expression/query that will be evaluated by Prometheus - Expr *string `json:"expr,omitempty"` + Expr string `json:"expr"` // Returns only the latest value that Prometheus has scraped for the requested time series Instant *bool `json:"instant,omitempty"` // Returns a Range vector, comprised of a set of time series containing a range of data points over time for each time series @@ -44,7 +44,7 @@ type Dataquery struct { // A unique identifier for the query within the list of targets. // In server side expressions, the refId is used as a variable name to identify results. // By default, the UI will assign A->Z; however setting meaningful names may be useful. - RefId *string `json:"refId,omitempty"` + RefId string `json:"refId"` // If hide is set to true, Grafana will filter out the response(s) associated with this query before returning it to the panel. Hide *bool `json:"hide,omitempty"` // Specify the query flavor 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/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 9165e9b..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", @@ -311,7 +311,10 @@ }, { "type": "object", - "additionalProperties": {} + "additionalProperties": { + "type": "object", + "additionalProperties": {} + } } ], "description": "Query used to fetch values for a variable" @@ -1024,6 +1027,9 @@ "userId": { "type": "integer", "description": "user id of the snapshot creator" + }, + "dashboard": { + "$ref": "#/definitions/Dashboard" } }, "description": "A dashboard snapshot shares an interactive dashboard publicly.\nIt is a read-only version of a dashboard, and is not editable.\nIt is possible to create a snapshot of a snapshot.\nGrafana strips away all sensitive information from the dashboard.\nSensitive information stripped: queries (metric, template,annotation) and panel links." diff --git a/jsonschema/elasticsearch.jsonschema.json b/jsonschema/elasticsearch.jsonschema.json index 1a41040..f80edcc 100644 --- a/jsonschema/elasticsearch.jsonschema.json +++ b/jsonschema/elasticsearch.jsonschema.json @@ -1287,7 +1287,10 @@ }, "settings": { "type": "object", - "additionalProperties": {} + "additionalProperties": { + "type": "object", + "additionalProperties": {} + } }, "hide": { "type": "boolean" @@ -1591,6 +1594,9 @@ "dataquery": { "type": "object", "additionalProperties": false, + "required": [ + "refId" + ], "properties": { "alias": { "type": "string", diff --git a/jsonschema/grafanapyroscope.jsonschema.json b/jsonschema/grafanapyroscope.jsonschema.json index 889530d..d16c059 100644 --- a/jsonschema/grafanapyroscope.jsonschema.json +++ b/jsonschema/grafanapyroscope.jsonschema.json @@ -11,6 +11,12 @@ "dataquery": { "type": "object", "additionalProperties": false, + "required": [ + "labelSelector", + "profileTypeId", + "groupBy", + "refId" + ], "properties": { "labelSelector": { "type": "string", diff --git a/jsonschema/loki.jsonschema.json b/jsonschema/loki.jsonschema.json index 47170b9..9b5e7d4 100644 --- a/jsonschema/loki.jsonschema.json +++ b/jsonschema/loki.jsonschema.json @@ -31,6 +31,10 @@ "dataquery": { "type": "object", "additionalProperties": false, + "required": [ + "expr", + "refId" + ], "properties": { "expr": { "type": "string", diff --git a/jsonschema/parca.jsonschema.json b/jsonschema/parca.jsonschema.json index 03cd164..c1235f5 100644 --- a/jsonschema/parca.jsonschema.json +++ b/jsonschema/parca.jsonschema.json @@ -11,6 +11,11 @@ "dataquery": { "type": "object", "additionalProperties": false, + "required": [ + "labelSelector", + "profileTypeId", + "refId" + ], "properties": { "labelSelector": { "type": "string", diff --git a/jsonschema/prometheus.jsonschema.json b/jsonschema/prometheus.jsonschema.json index 74862ac..cd6e9ce 100644 --- a/jsonschema/prometheus.jsonschema.json +++ b/jsonschema/prometheus.jsonschema.json @@ -17,6 +17,10 @@ "dataquery": { "type": "object", "additionalProperties": false, + "required": [ + "expr", + "refId" + ], "properties": { "expr": { "type": "string", 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/openapi/azuremonitor.openapi.json b/openapi/azuremonitor.openapi.json index 89bfca5..82454e4 100644 --- a/openapi/azuremonitor.openapi.json +++ b/openapi/azuremonitor.openapi.json @@ -212,6 +212,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/openapi/common.openapi.json b/openapi/common.openapi.json index e8bea4a..f03e8df 100644 --- a/openapi/common.openapi.json +++ b/openapi/common.openapi.json @@ -765,6 +765,14 @@ ], "description": "TODO docs" }, + "PercentChangeColorMode": { + "enum": [ + "standard", + "inverted", + "same_as_value" + ], + "description": "TODO docs" + }, "FieldTextAlignment": { "enum": [ "auto", diff --git a/openapi/dashboard.openapi.json b/openapi/dashboard.openapi.json index daf7a9a..a7ec373 100644 --- a/openapi/dashboard.openapi.json +++ b/openapi/dashboard.openapi.json @@ -108,7 +108,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", @@ -318,7 +318,10 @@ }, { "type": "object", - "additionalProperties": {} + "additionalProperties": { + "type": "object", + "additionalProperties": {} + } } ], "description": "Query used to fetch values for a variable" @@ -1031,6 +1034,9 @@ "userId": { "type": "integer", "description": "user id of the snapshot creator" + }, + "dashboard": { + "$ref": "#/components/schemas/Dashboard" } }, "description": "A dashboard snapshot shares an interactive dashboard publicly.\nIt is a read-only version of a dashboard, and is not editable.\nIt is possible to create a snapshot of a snapshot.\nGrafana strips away all sensitive information from the dashboard.\nSensitive information stripped: queries (metric, template,annotation) and panel links." diff --git a/openapi/elasticsearch.openapi.json b/openapi/elasticsearch.openapi.json index 841a3fa..e26ad77 100644 --- a/openapi/elasticsearch.openapi.json +++ b/openapi/elasticsearch.openapi.json @@ -1296,7 +1296,10 @@ }, "settings": { "type": "object", - "additionalProperties": {} + "additionalProperties": { + "type": "object", + "additionalProperties": {} + } }, "hide": { "type": "boolean" @@ -1600,6 +1603,9 @@ "dataquery": { "type": "object", "additionalProperties": false, + "required": [ + "refId" + ], "properties": { "alias": { "type": "string", diff --git a/openapi/grafanapyroscope.openapi.json b/openapi/grafanapyroscope.openapi.json index 63a1786..bdd707d 100644 --- a/openapi/grafanapyroscope.openapi.json +++ b/openapi/grafanapyroscope.openapi.json @@ -20,6 +20,12 @@ "dataquery": { "type": "object", "additionalProperties": false, + "required": [ + "labelSelector", + "profileTypeId", + "groupBy", + "refId" + ], "properties": { "labelSelector": { "type": "string", diff --git a/openapi/loki.openapi.json b/openapi/loki.openapi.json index 128ca5d..ee37f2e 100644 --- a/openapi/loki.openapi.json +++ b/openapi/loki.openapi.json @@ -40,6 +40,10 @@ "dataquery": { "type": "object", "additionalProperties": false, + "required": [ + "expr", + "refId" + ], "properties": { "expr": { "type": "string", diff --git a/openapi/parca.openapi.json b/openapi/parca.openapi.json index 7fc1fb1..b8bc76e 100644 --- a/openapi/parca.openapi.json +++ b/openapi/parca.openapi.json @@ -20,6 +20,11 @@ "dataquery": { "type": "object", "additionalProperties": false, + "required": [ + "labelSelector", + "profileTypeId", + "refId" + ], "properties": { "labelSelector": { "type": "string", diff --git a/openapi/prometheus.openapi.json b/openapi/prometheus.openapi.json index b1cd52e..6c24f9b 100644 --- a/openapi/prometheus.openapi.json +++ b/openapi/prometheus.openapi.json @@ -26,6 +26,10 @@ "dataquery": { "type": "object", "additionalProperties": false, + "required": [ + "expr", + "refId" + ], "properties": { "expr": { "type": "string", diff --git a/openapi/stat.openapi.json b/openapi/stat.openapi.json index 46ade6a..11291c3 100644 --- a/openapi/stat.openapi.json +++ b/openapi/stat.openapi.json @@ -19,8 +19,9 @@ "justifyMode", "textMode", "wideLayout", - "reduceOptions", "showPercentChange", + "reduceOptions", + "percentChangeColorMode", "orientation" ], "properties": { @@ -44,15 +45,19 @@ "type": "boolean", "default": true }, + "showPercentChange": { + "type": "boolean", + "default": false + }, "reduceOptions": { "$ref": "#/components/schemas/ReduceDataOptions" }, "text": { "$ref": "#/components/schemas/VizTextDisplayOptions" }, - "showPercentChange": { - "type": "boolean", - "default": false + "percentChangeColorMode": { + "$ref": "#/components/schemas/PercentChangeColorMode", + "default": "standard" }, "orientation": { "$ref": "#/components/schemas/VizOrientation" @@ -137,6 +142,14 @@ }, "description": "TODO docs" }, + "PercentChangeColorMode": { + "enum": [ + "standard", + "inverted", + "same_as_value" + ], + "description": "TODO docs" + }, "VizOrientation": { "enum": [ "auto", diff --git a/python/grafana_foundation_sdk/builders/azuremonitor.py b/python/grafana_foundation_sdk/builders/azuremonitor.py index ba68ef2..7c26cae 100644 --- a/python/grafana_foundation_sdk/builders/azuremonitor.py +++ b/python/grafana_foundation_sdk/builders/azuremonitor.py @@ -387,6 +387,15 @@ class AzureLogsQuery(cogbuilder.Builder[azuremonitor.AzureLogsQuery]): return self + def basic_logs_query(self, basic_logs_query: bool) -> typing.Self: + """ + If set to true the query will be run as a basic logs query + """ + + self._internal.basic_logs_query = basic_logs_query + + return self + def workspace(self, workspace: str) -> typing.Self: """ Workspace ID. This was removed in Grafana 8, but remains for backwards compat. diff --git a/python/grafana_foundation_sdk/builders/dashboard.py b/python/grafana_foundation_sdk/builders/dashboard.py index 164ed31..ddec2e5 100644 --- a/python/grafana_foundation_sdk/builders/dashboard.py +++ b/python/grafana_foundation_sdk/builders/dashboard.py @@ -232,12 +232,13 @@ class Dashboard(cogbuilder.Builder[dashboard.Dashboard]): row_panel_resource = row_panel.build() # Position the row on the grid - row_panel_resource.grid_pos = dashboard.GridPos( - x=0, - y=self.__current_y + self.__last_panel_height, - h=1, - w=24, - ) + if row_panel_resource.grid_pos is None or (row_panel_resource.grid_pos.x == 0 and row_panel_resource.grid_pos.y == 0): + row_panel_resource.grid_pos = dashboard.GridPos( + x=0, + y=self.__current_y + self.__last_panel_height, + h=1, + w=24, + ) self._internal.panels.append(row_panel_resource) # Reset the state for the next row @@ -895,15 +896,6 @@ class Snapshot(cogbuilder.Builder[dashboard.Snapshot]): def build(self) -> dashboard.Snapshot: return self._internal - def created(self, created: str) -> typing.Self: - """ - Time when the snapshot was created - """ - - self._internal.created = created - - return self - def expires(self, expires: str) -> typing.Self: """ Time when the snapshot expires, default is never to expire @@ -976,15 +968,6 @@ class Snapshot(cogbuilder.Builder[dashboard.Snapshot]): return self - def updated(self, updated: str) -> typing.Self: - """ - last time when the snapshot was updated - """ - - self._internal.updated = updated - - return self - def url(self, url: str) -> typing.Self: """ url of the snapshot, if snapshot was shared internally @@ -994,12 +977,9 @@ class Snapshot(cogbuilder.Builder[dashboard.Snapshot]): return self - def user_id(self, user_id: int) -> typing.Self: - """ - user id of the snapshot creator - """ - - self._internal.user_id = user_id + def dashboard(self, dashboard: cogbuilder.Builder[dashboard.Dashboard]) -> typing.Self: + dashboard_resource = dashboard.build() + self._internal.dashboard = dashboard_resource return self @@ -1507,6 +1487,15 @@ class Row(cogbuilder.Builder[dashboard.RowPanel]): return self + def grid_pos(self, grid_pos: dashboard.GridPos) -> typing.Self: + """ + Row grid position + """ + + self._internal.grid_pos = grid_pos + + return self + def id_val(self, id_val: int) -> typing.Self: """ Unique identifier of the panel. Generated by Grafana when creating a new panel. It must be unique within a dashboard, but not globally. @@ -1723,7 +1712,7 @@ class QueryVariable(cogbuilder.Builder[dashboard.VariableModel]): return self - def query(self, query: typing.Union[str, object]) -> typing.Self: + def query(self, query: typing.Union[str, dict[str, object]]) -> typing.Self: """ Query used to fetch values for a variable """ @@ -1918,7 +1907,7 @@ class ConstantVariable(cogbuilder.Builder[dashboard.VariableModel]): return self - def value(self, query: typing.Union[str, object]) -> typing.Self: + def value(self, query: typing.Union[str, dict[str, object]]) -> typing.Self: """ Query used to fetch values for a variable """ @@ -1979,7 +1968,7 @@ class DatasourceVariable(cogbuilder.Builder[dashboard.VariableModel]): return self - def type_val(self, query: typing.Union[str, object]) -> typing.Self: + def type_val(self, query: typing.Union[str, dict[str, object]]) -> typing.Self: """ Query used to fetch values for a variable """ @@ -2086,7 +2075,7 @@ class IntervalVariable(cogbuilder.Builder[dashboard.VariableModel]): return self - def values(self, query: typing.Union[str, object]) -> typing.Self: + def values(self, query: typing.Union[str, dict[str, object]]) -> typing.Self: """ Query used to fetch values for a variable """ @@ -2165,7 +2154,7 @@ class TextBoxVariable(cogbuilder.Builder[dashboard.VariableModel]): return self - def default_value(self, query: typing.Union[str, object]) -> typing.Self: + def default_value(self, query: typing.Union[str, dict[str, object]]) -> typing.Self: """ Query used to fetch values for a variable """ @@ -2244,7 +2233,7 @@ class CustomVariable(cogbuilder.Builder[dashboard.VariableModel]): return self - def values(self, query: typing.Union[str, object]) -> typing.Self: + def values(self, query: typing.Union[str, dict[str, object]]) -> typing.Self: """ Query used to fetch values for a variable """ diff --git a/python/grafana_foundation_sdk/builders/elasticsearch.py b/python/grafana_foundation_sdk/builders/elasticsearch.py index db446b5..8e8e4d4 100644 --- a/python/grafana_foundation_sdk/builders/elasticsearch.py +++ b/python/grafana_foundation_sdk/builders/elasticsearch.py @@ -1155,7 +1155,7 @@ class MovingAverage(cogbuilder.Builder[elasticsearch.MovingAverage]): return self - def settings(self, settings: object) -> typing.Self: + def settings(self, settings: dict[str, object]) -> typing.Self: self._internal.settings = settings return self diff --git a/python/grafana_foundation_sdk/builders/prometheus.py b/python/grafana_foundation_sdk/builders/prometheus.py index 25f88ad..a9feb45 100644 --- a/python/grafana_foundation_sdk/builders/prometheus.py +++ b/python/grafana_foundation_sdk/builders/prometheus.py @@ -23,21 +23,23 @@ class Dataquery(cogbuilder.Builder[prometheus.Dataquery]): return self - def instant(self, instant: bool) -> typing.Self: + def instant(self) -> typing.Self: """ Returns only the latest value that Prometheus has scraped for the requested time series """ - self._internal.instant = instant + self._internal.instant = True + self._internal.range_val = False return self - def range_val(self, range_val: bool) -> typing.Self: + def range_val(self) -> typing.Self: """ Returns a Range vector, comprised of a set of time series containing a range of data points over time for each time series """ - self._internal.range_val = range_val + self._internal.range_val = True + self._internal.instant = False return self @@ -138,4 +140,10 @@ class Dataquery(cogbuilder.Builder[prometheus.Dataquery]): self._internal.interval = interval return self + + def range_and_instant(self) -> typing.Self: + self._internal.range_val = True + self._internal.instant = True + + return self \ No newline at end of file diff --git a/python/grafana_foundation_sdk/builders/stat.py b/python/grafana_foundation_sdk/builders/stat.py index cf3b22b..cfac2fb 100644 --- a/python/grafana_foundation_sdk/builders/stat.py +++ b/python/grafana_foundation_sdk/builders/stat.py @@ -498,6 +498,14 @@ class Panel(cogbuilder.Builder[dashboard.Panel]): return self + def show_percent_change(self, show_percent_change: bool) -> typing.Self: + if self._internal.options is None: + self._internal.options = stat.Options() + assert isinstance(self._internal.options, stat.Options) + self._internal.options.show_percent_change = show_percent_change + + return self + def reduce_options(self, reduce_options: cogbuilder.Builder[common.ReduceDataOptions]) -> typing.Self: if self._internal.options is None: self._internal.options = stat.Options() @@ -516,11 +524,11 @@ class Panel(cogbuilder.Builder[dashboard.Panel]): return self - def show_percent_change(self, show_percent_change: bool) -> typing.Self: + def percent_change_color_mode(self, percent_change_color_mode: common.PercentChangeColorMode) -> typing.Self: if self._internal.options is None: self._internal.options = stat.Options() assert isinstance(self._internal.options, stat.Options) - self._internal.options.show_percent_change = show_percent_change + self._internal.options.percent_change_color_mode = percent_change_color_mode return self diff --git a/python/grafana_foundation_sdk/cog/plugins.py b/python/grafana_foundation_sdk/cog/plugins.py index 576007f..4571cfa 100644 --- a/python/grafana_foundation_sdk/cog/plugins.py +++ b/python/grafana_foundation_sdk/cog/plugins.py @@ -1,39 +1,39 @@ # Code generated - EDITING IS FUTILE. DO NOT EDIT. -from ..models import loki -from ..models import news -from ..models import stat from ..models import azuremonitor +from ..models import elasticsearch +from ..models import gauge +from ..models import trend +from ..models import annotationslist from ..models import bargauge -from ..models import googlecloudmonitoring -from ..models import xychart -from ..models import cloudwatch +from ..models import parca +from ..models import statushistory +from ..models import timeseries from ..models import dashboardlist -from ..models import nodegraph -from ..models import statetimeline -from ..models import table -from ..models import tempo -from ..models import candlestick -from ..models import annotationslist from ..models import logs -from ..models import parca -from ..models import piechart +from ..models import loki from ..models import barchart -from ..models import gauge -from ..models import statushistory -from ..models import trend -from ..models import heatmap from ..models import datagrid -from ..models import elasticsearch -from ..models import geomap +from ..models import tempo +from ..models import cloudwatch +from ..models import debug +from ..models import googlecloudmonitoring +from ..models import canvas from ..models import grafanapyroscope -from ..models import histogram -from ..models import timeseries +from ..models import news +from ..models import piechart +from ..models import statetimeline from ..models import expr -from ..models import canvas -from ..models import debug -from ..models import prometheus +from ..models import geomap +from ..models import heatmap +from ..models import histogram +from ..models import stat from ..models import text +from ..models import candlestick +from ..models import nodegraph +from ..models import table +from ..models import xychart +from ..models import prometheus from . import runtime as cogruntime diff --git a/python/grafana_foundation_sdk/models/azuremonitor.py b/python/grafana_foundation_sdk/models/azuremonitor.py index 0769860..93942e6 100644 --- a/python/grafana_foundation_sdk/models/azuremonitor.py +++ b/python/grafana_foundation_sdk/models/azuremonitor.py @@ -318,6 +318,8 @@ class AzureLogsQuery: dashboard_time: typing.Optional[bool] # 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 time_column: typing.Optional[str] + # If set to true the query will be run as a basic logs query + basic_logs_query: typing.Optional[bool] # Workspace ID. This was removed in Grafana 8, but remains for backwards compat. workspace: typing.Optional[str] # @deprecated Use resources instead @@ -325,12 +327,13 @@ class AzureLogsQuery: # @deprecated Use dashboardTime instead intersect_time: typing.Optional[bool] - def __init__(self, query: typing.Optional[str] = None, result_format: typing.Optional['ResultFormat'] = None, resources: typing.Optional[list[str]] = None, dashboard_time: typing.Optional[bool] = None, time_column: typing.Optional[str] = None, workspace: typing.Optional[str] = None, resource: typing.Optional[str] = None, intersect_time: typing.Optional[bool] = None): + def __init__(self, query: typing.Optional[str] = None, result_format: typing.Optional['ResultFormat'] = None, resources: typing.Optional[list[str]] = None, dashboard_time: typing.Optional[bool] = None, time_column: typing.Optional[str] = None, basic_logs_query: typing.Optional[bool] = None, workspace: typing.Optional[str] = None, resource: typing.Optional[str] = None, intersect_time: typing.Optional[bool] = None): self.query = query self.result_format = result_format self.resources = resources self.dashboard_time = dashboard_time self.time_column = time_column + self.basic_logs_query = basic_logs_query self.workspace = workspace self.resource = resource self.intersect_time = intersect_time @@ -348,6 +351,8 @@ class AzureLogsQuery: payload["dashboardTime"] = self.dashboard_time if self.time_column is not None: payload["timeColumn"] = self.time_column + if self.basic_logs_query is not None: + payload["basicLogsQuery"] = self.basic_logs_query if self.workspace is not None: payload["workspace"] = self.workspace if self.resource is not None: @@ -370,6 +375,8 @@ class AzureLogsQuery: args["dashboard_time"] = data["dashboardTime"] if "timeColumn" in data: args["time_column"] = data["timeColumn"] + if "basicLogsQuery" in data: + args["basic_logs_query"] = data["basicLogsQuery"] if "workspace" in data: args["workspace"] = data["workspace"] if "resource" in data: diff --git a/python/grafana_foundation_sdk/models/cloudwatch.py b/python/grafana_foundation_sdk/models/cloudwatch.py index 68ad69b..d9d5c79 100644 --- a/python/grafana_foundation_sdk/models/cloudwatch.py +++ b/python/grafana_foundation_sdk/models/cloudwatch.py @@ -894,7 +894,7 @@ CloudWatchQuery: typing.TypeAlias = typing.Union['CloudWatchMetricsQuery', 'Clou def variant_config() -> cogruntime.DataqueryConfig: - decoding_map: dict[str, typing.Union[typing.Type[CloudWatchMetricsQuery], typing.Type[CloudWatchLogsQuery], typing.Type[CloudWatchAnnotationQuery]]] = {"Metrics": CloudWatchMetricsQuery, "Logs": CloudWatchLogsQuery, "Annotations": CloudWatchAnnotationQuery} + decoding_map: dict[str, typing.Union[typing.Type[CloudWatchLogsQuery], typing.Type[CloudWatchAnnotationQuery], typing.Type[CloudWatchMetricsQuery]]] = {"Logs": CloudWatchLogsQuery, "Annotations": CloudWatchAnnotationQuery, "Metrics": CloudWatchMetricsQuery} return cogruntime.DataqueryConfig( identifier="cloudwatch", from_json_hook=lambda data: decoding_map[data["queryMode"]].from_json(data), diff --git a/python/grafana_foundation_sdk/models/common.py b/python/grafana_foundation_sdk/models/common.py index 56a8688..b7df805 100644 --- a/python/grafana_foundation_sdk/models/common.py +++ b/python/grafana_foundation_sdk/models/common.py @@ -1333,6 +1333,16 @@ class BigValueTextMode(enum.StrEnum): NONE = "none" +class PercentChangeColorMode(enum.StrEnum): + """ + TODO docs + """ + + STANDARD = "standard" + INVERTED = "inverted" + SAME_AS_VALUE = "same_as_value" + + class FieldTextAlignment(enum.StrEnum): """ TODO -- should not be table specific! diff --git a/python/grafana_foundation_sdk/models/dashboard.py b/python/grafana_foundation_sdk/models/dashboard.py index b1232a9..f497b5f 100644 --- a/python/grafana_foundation_sdk/models/dashboard.py +++ b/python/grafana_foundation_sdk/models/dashboard.py @@ -64,7 +64,7 @@ class Dashboard: # Snapshot options. They are present only if the dashboard is a snapshot. snapshot: typing.Optional['Snapshot'] - def __init__(self, id_val: typing.Optional[int] = None, uid: typing.Optional[str] = None, title: typing.Optional[str] = None, description: typing.Optional[str] = None, revision: typing.Optional[int] = None, gnet_id: typing.Optional[str] = None, tags: typing.Optional[list[str]] = None, timezone: typing.Optional[str] = "browser", editable: typing.Optional[bool] = True, graph_tooltip: typing.Optional['DashboardCursorSync'] = None, time: typing.Optional['DashboardDashboardTime'] = None, timepicker: typing.Optional['TimePickerConfig'] = None, fiscal_year_start_month: typing.Optional[int] = 0, live_now: typing.Optional[bool] = None, week_start: typing.Optional[str] = None, refresh: typing.Optional[str] = None, schema_version: int = 36, version: typing.Optional[int] = None, panels: typing.Optional[list[typing.Union['Panel', 'RowPanel']]] = None, templating: typing.Optional['DashboardDashboardTemplating'] = None, annotations: typing.Optional['AnnotationContainer'] = None, links: typing.Optional[list['DashboardLink']] = None, snapshot: typing.Optional['Snapshot'] = None): + def __init__(self, id_val: typing.Optional[int] = None, uid: typing.Optional[str] = None, title: typing.Optional[str] = None, description: typing.Optional[str] = None, revision: typing.Optional[int] = None, gnet_id: typing.Optional[str] = None, tags: typing.Optional[list[str]] = None, timezone: typing.Optional[str] = "browser", editable: typing.Optional[bool] = True, graph_tooltip: typing.Optional['DashboardCursorSync'] = None, time: typing.Optional['DashboardDashboardTime'] = None, timepicker: typing.Optional['TimePickerConfig'] = None, fiscal_year_start_month: typing.Optional[int] = 0, live_now: typing.Optional[bool] = None, week_start: typing.Optional[str] = None, refresh: typing.Optional[str] = None, schema_version: int = 39, version: typing.Optional[int] = None, panels: typing.Optional[list[typing.Union['Panel', 'RowPanel']]] = None, templating: typing.Optional['DashboardDashboardTemplating'] = None, annotations: typing.Optional['AnnotationContainer'] = None, links: typing.Optional[list['DashboardLink']] = None, snapshot: typing.Optional['Snapshot'] = None): self.id_val = id_val self.uid = uid self.title = title @@ -403,7 +403,7 @@ class VariableModel: # Description of variable. It can be defined but `null`. description: typing.Optional[str] # Query used to fetch values for a variable - query: typing.Optional[typing.Union[str, object]] + query: typing.Optional[typing.Union[str, dict[str, object]]] # Data source used to fetch values for a variable. It can be defined but `null`. datasource: typing.Optional['DataSourceRef'] # Shows current selected variable text/value on the dashboard @@ -424,7 +424,7 @@ class VariableModel: # Named capture groups can be used to separate the display text and value. regex: typing.Optional[str] - def __init__(self, type_val: typing.Optional['VariableType'] = None, name: str = "", label: typing.Optional[str] = None, hide: typing.Optional['VariableHide'] = None, skip_url_sync: typing.Optional[bool] = False, description: typing.Optional[str] = None, query: typing.Optional[typing.Union[str, object]] = None, datasource: typing.Optional['DataSourceRef'] = None, current: typing.Optional['VariableOption'] = None, multi: typing.Optional[bool] = False, options: typing.Optional[list['VariableOption']] = None, refresh: typing.Optional['VariableRefresh'] = None, sort: typing.Optional['VariableSort'] = None, include_all: typing.Optional[bool] = False, all_value: typing.Optional[str] = None, regex: typing.Optional[str] = None): + def __init__(self, type_val: typing.Optional['VariableType'] = None, name: str = "", label: typing.Optional[str] = None, hide: typing.Optional['VariableHide'] = None, skip_url_sync: typing.Optional[bool] = False, description: typing.Optional[str] = None, query: typing.Optional[typing.Union[str, dict[str, object]]] = None, datasource: typing.Optional['DataSourceRef'] = None, current: typing.Optional['VariableOption'] = None, multi: typing.Optional[bool] = False, options: typing.Optional[list['VariableOption']] = None, refresh: typing.Optional['VariableRefresh'] = None, sort: typing.Optional['VariableSort'] = None, include_all: typing.Optional[bool] = False, all_value: typing.Optional[str] = None, regex: typing.Optional[str] = None): self.type_val = type_val if type_val is not None else VariableType.QUERY self.name = name self.label = label @@ -1333,8 +1333,9 @@ class Snapshot: url: typing.Optional[str] # user id of the snapshot creator user_id: int + dashboard: typing.Optional['Dashboard'] - def __init__(self, created: str = "", expires: str = "", external: bool = False, external_url: str = "", original_url: str = "", id_val: int = 0, key: str = "", name: str = "", org_id: int = 0, updated: str = "", url: typing.Optional[str] = None, user_id: int = 0): + def __init__(self, created: str = "", expires: str = "", external: bool = False, external_url: str = "", original_url: str = "", id_val: int = 0, key: str = "", name: str = "", org_id: int = 0, updated: str = "", url: typing.Optional[str] = None, user_id: int = 0, dashboard: typing.Optional['Dashboard'] = None): self.created = created self.expires = expires self.external = external @@ -1347,6 +1348,7 @@ class Snapshot: self.updated = updated self.url = url self.user_id = user_id + self.dashboard = dashboard def to_json(self) -> dict[str, object]: payload: dict[str, object] = { @@ -1364,6 +1366,8 @@ class Snapshot: } if self.url is not None: payload["url"] = self.url + if self.dashboard is not None: + payload["dashboard"] = self.dashboard return payload @classmethod @@ -1393,7 +1397,9 @@ class Snapshot: ...*[Comment body truncated]*