grafana / cog

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

Java: Use schema object name to create the map of builders #447

Closed spinillos closed 5 months ago

spinillos commented 5 months ago

In Java we have a map of builders used to decide if we should add the builder or not inside the class (common way to do in Java).

The problem is we were iterating the builder structure only and the names of the Builders differs from the one in Schema and it was impossible to find them.

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/recordrule_builder_gen.go b/go/alerting/recordrule_builder_gen.go new file mode 100644 index 0000000..55e8a10 --- /dev/null +++ b/go/alerting/recordrule_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[RecordRule] = (*RecordRuleBuilder)(nil) + +type RecordRuleBuilder struct { + internal *RecordRule + errors map[string]cog.BuildErrors +} + +func NewRecordRuleBuilder() *RecordRuleBuilder { + resource := &RecordRule{} + builder := &RecordRuleBuilder{ + internal: resource, + errors: make(map[string]cog.BuildErrors), + } + + builder.applyDefaults() + + return builder +} + +func (builder *RecordRuleBuilder) Build() (RecordRule, error) { + var errs cog.BuildErrors + + for _, err := range builder.errors { + errs = append(errs, cog.MakeBuildErrors("RecordRule", err)...) + } + + if len(errs) != 0 { + return RecordRule{}, errs + } + + return *builder.internal, nil +} + +func (builder *RecordRuleBuilder) From(from string) *RecordRuleBuilder { + builder.internal.From = from + + return builder +} + +func (builder *RecordRuleBuilder) Metric(metric string) *RecordRuleBuilder { + builder.internal.Metric = metric + + return builder +} + +func (builder *RecordRuleBuilder) applyDefaults() { +} diff --git a/go/alerting/rule_builder_gen.go b/go/alerting/rule_builder_gen.go index 6e66fe8..80c4122 100644 --- a/go/alerting/rule_builder_gen.go +++ b/go/alerting/rule_builder_gen.go @@ -156,6 +156,17 @@ func (builder *RuleBuilder) Provenance(provenance Provenance) *RuleBuilder { return builder } +func (builder *RuleBuilder) Record(record cog.Builder[RecordRule]) *RuleBuilder { + recordResource, err := record.Build() + if err != nil { + builder.errors["record"] = err.(cog.BuildErrors) + return builder + } + builder.internal.Record = &recordResource + + return builder +} + func (builder *RuleBuilder) RuleGroup(ruleGroup string) *RuleBuilder { if !(len([]rune(ruleGroup)) >= 1) { builder.errors["ruleGroup"] = cog.MakeBuildErrors("ruleGroup", errors.New("len([]rune(ruleGroup)) must be >= 1")) diff --git a/go/alerting/types_gen.go b/go/alerting/types_gen.go index f81d0b1..f1b30cd 100644 --- a/go/alerting/types_gen.go +++ b/go/alerting/types_gen.go @@ -165,12 +165,18 @@ type Rule struct { NotificationSettings *NotificationSettings `json:"notification_settings,omitempty"` OrgID int64 `json:"orgID"` Provenance *Provenance `json:"provenance,omitempty"` + Record *RecordRule `json:"record,omitempty"` RuleGroup string `json:"ruleGroup"` Title string `json:"title"` Uid *string `json:"uid,omitempty"` Updated *time.Time `json:"updated,omitempty"` } +type RecordRule struct { + From string `json:"from"` + Metric string `json:"metric"` +} + // RelativeTimeRange is the per query start and end time // for requests. type RelativeTimeRange struct { diff --git a/go/azuremonitor/azuremonitorquery_builder_gen.go b/go/azuremonitor/azuremonitorquery_builder_gen.go index 6affba5..5a912ac 100644 --- a/go/azuremonitor/azuremonitorquery_builder_gen.go +++ b/go/azuremonitor/azuremonitorquery_builder_gen.go @@ -152,6 +152,12 @@ func (builder *AzureMonitorQueryBuilder) Resource(resource string) *AzureMonitor return builder } +func (builder *AzureMonitorQueryBuilder) Region(region string) *AzureMonitorQueryBuilder { + builder.internal.Region = ®ion + + return builder +} + // For mixed data sources the selected datasource is on the query level. // For non mixed scenarios this is undefined. // TODO find a better way to do this ^ that's friendly to schema @@ -162,10 +168,9 @@ func (builder *AzureMonitorQueryBuilder) Datasource(datasource any) *AzureMonito return builder } -// Azure Monitor query type. -// queryType: #AzureQueryType -func (builder *AzureMonitorQueryBuilder) Region(region string) *AzureMonitorQueryBuilder { - builder.internal.Region = ®ion +// Used only for exemplar queries from Prometheus +func (builder *AzureMonitorQueryBuilder) Query(query string) *AzureMonitorQueryBuilder { + builder.internal.Query = &query return builder } diff --git a/go/azuremonitor/types_gen.go b/go/azuremonitor/types_gen.go index 0e789fb..d795d9b 100644 --- a/go/azuremonitor/types_gen.go +++ b/go/azuremonitor/types_gen.go @@ -38,14 +38,14 @@ type AzureMonitorQuery struct { ResourceGroup *string `json:"resourceGroup,omitempty"` Namespace *string `json:"namespace,omitempty"` Resource *string `json:"resource,omitempty"` + Region *string `json:"region,omitempty"` // For mixed data sources the selected datasource is on the query level. // For non mixed scenarios this is undefined. // TODO find a better way to do this ^ that's friendly to schema // TODO this shouldn't be unknown but DataSourceRef | null Datasource any `json:"datasource,omitempty"` - // Azure Monitor query type. - // queryType: #AzureQueryType - Region *string `json:"region,omitempty"` + // Used only for exemplar queries from Prometheus + Query *string `json:"query,omitempty"` } func (resource AzureMonitorQuery) ImplementsDataqueryVariant() {} @@ -81,6 +81,7 @@ const ( AzureQueryTypeWorkspacesQuery AzureQueryType = "Azure Workspaces" AzureQueryTypeLocationsQuery AzureQueryType = "Azure Regions" AzureQueryTypeGrafanaTemplateVariableFn AzureQueryType = "Grafana Template Variable Function" + AzureQueryTypeTraceExemplar AzureQueryType = "traceql" ) type AzureMetricQuery struct { diff --git a/go/common/tableautocelloptions_builder_gen.go b/go/common/tableautocelloptions_builder_gen.go new file mode 100644 index 0000000..4177c9f --- /dev/null +++ b/go/common/tableautocelloptions_builder_gen.go @@ -0,0 +1,51 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. + +package common + +import ( + cog "github.com/grafana/grafana-foundation-sdk/go/cog" +) + +var _ cog.Builder[TableAutoCellOptions] = (*TableAutoCellOptionsBuilder)(nil) + +// Auto mode table cell options +type TableAutoCellOptionsBuilder struct { + internal *TableAutoCellOptions + errors map[string]cog.BuildErrors +} + +func NewTableAutoCellOptionsBuilder() *TableAutoCellOptionsBuilder { + resource := &TableAutoCellOptions{} + builder := &TableAutoCellOptionsBuilder{ + internal: resource, + errors: make(map[string]cog.BuildErrors), + } + + builder.applyDefaults() + builder.internal.Type = "auto" + + return builder +} + +func (builder *TableAutoCellOptionsBuilder) Build() (TableAutoCellOptions, error) { + var errs cog.BuildErrors + + for _, err := range builder.errors { + errs = append(errs, cog.MakeBuildErrors("TableAutoCellOptions", err)...) + } + + if len(errs) != 0 { + return TableAutoCellOptions{}, errs + } + + return *builder.internal, nil +} + +func (builder *TableAutoCellOptionsBuilder) WrapText(wrapText bool) *TableAutoCellOptionsBuilder { + builder.internal.WrapText = &wrapText + + return builder +} + +func (builder *TableAutoCellOptionsBuilder) applyDefaults() { +} diff --git a/go/common/tablecoloredbackgroundcelloptions_builder_gen.go b/go/common/tablecoloredbackgroundcelloptions_builder_gen.go index fd519e9..57fe80b 100644 --- a/go/common/tablecoloredbackgroundcelloptions_builder_gen.go +++ b/go/common/tablecoloredbackgroundcelloptions_builder_gen.go @@ -53,5 +53,11 @@ func (builder *TableColoredBackgroundCellOptionsBuilder) ApplyToRow(applyToRow b return builder } +func (builder *TableColoredBackgroundCellOptionsBuilder) WrapText(wrapText bool) *TableColoredBackgroundCellOptionsBuilder { + builder.internal.WrapText = &wrapText + + return builder +} + func (builder *TableColoredBackgroundCellOptionsBuilder) applyDefaults() { } diff --git a/go/common/tablecolortextcelloptions_builder_gen.go b/go/common/tablecolortextcelloptions_builder_gen.go new file mode 100644 index 0000000..22edbc8 --- /dev/null +++ b/go/common/tablecolortextcelloptions_builder_gen.go @@ -0,0 +1,51 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. + +package common + +import ( + cog "github.com/grafana/grafana-foundation-sdk/go/cog" +) + +var _ cog.Builder[TableColorTextCellOptions] = (*TableColorTextCellOptionsBuilder)(nil) + +// Colored text cell options +type TableColorTextCellOptionsBuilder struct { + internal *TableColorTextCellOptions + errors map[string]cog.BuildErrors +} + +func NewTableColorTextCellOptionsBuilder() *TableColorTextCellOptionsBuilder { + resource := &TableColorTextCellOptions{} + builder := &TableColorTextCellOptionsBuilder{ + internal: resource, + errors: make(map[string]cog.BuildErrors), + } + + builder.applyDefaults() + builder.internal.Type = "color-text" + + return builder +} + +func (builder *TableColorTextCellOptionsBuilder) Build() (TableColorTextCellOptions, error) { + var errs cog.BuildErrors + + for _, err := range builder.errors { + errs = append(errs, cog.MakeBuildErrors("TableColorTextCellOptions", err)...) + } + + if len(errs) != 0 { + return TableColorTextCellOptions{}, errs + } + + return *builder.internal, nil +} + +func (builder *TableColorTextCellOptionsBuilder) WrapText(wrapText bool) *TableColorTextCellOptionsBuilder { + builder.internal.WrapText = &wrapText + + return builder +} + +func (builder *TableColorTextCellOptionsBuilder) applyDefaults() { +} diff --git a/go/common/types_gen.go b/go/common/types_gen.go index 515fd60..2a884e4 100644 --- a/go/common/types_gen.go +++ b/go/common/types_gen.go @@ -697,12 +697,14 @@ type TableFooterOptions struct { // Auto mode table cell options type TableAutoCellOptions struct { - Type string `json:"type"` + Type string `json:"type"` + WrapText *bool `json:"wrapText,omitempty"` } // Colored text cell options type TableColorTextCellOptions struct { - Type string `json:"type"` + Type string `json:"type"` + WrapText *bool `json:"wrapText,omitempty"` } // Json view cell options @@ -773,15 +775,17 @@ type TableColoredBackgroundCellOptions struct { Type string `json:"type"` Mode *TableCellBackgroundDisplayMode `json:"mode,omitempty"` ApplyToRow *bool `json:"applyToRow,omitempty"` + WrapText *bool `json:"wrapText,omitempty"` } // Height of a table cell type TableCellHeight string const ( - TableCellHeightSm TableCellHeight = "sm" - TableCellHeightMd TableCellHeight = "md" - TableCellHeightLg TableCellHeight = "lg" + TableCellHeightSm TableCellHeight = "sm" + TableCellHeightMd TableCellHeight = "md" + TableCellHeightLg TableCellHeight = "lg" + TableCellHeightAuto TableCellHeight = "auto" ) // Table cell options. Each cell has a display mode diff --git a/go/dashboard/datasourcevariable_builder_gen.go b/go/dashboard/datasourcevariable_builder_gen.go index 77cdec6..15f6a78 100644 --- a/go/dashboard/datasourcevariable_builder_gen.go +++ b/go/dashboard/datasourcevariable_builder_gen.go @@ -71,11 +71,11 @@ func (builder *DatasourceVariableBuilder) Description(description string) *Datas } // Query used to fetch values for a variable -func (builder *DatasourceVariableBuilder) Type(string string) *DatasourceVariableBuilder { +func (builder *DatasourceVariableBuilder) Type(stringArg string) *DatasourceVariableBuilder { if builder.internal.Query == nil { builder.internal.Query = &StringOrMap{} } - builder.internal.Query.String = &string + builder.internal.Query.String = &stringArg return builder } diff --git a/go/elasticsearch/inlinescript_builder_gen.go b/go/elasticsearch/inlinescript_builder_gen.go index cc49dde..f65a96c 100644 --- a/go/elasticsearch/inlinescript_builder_gen.go +++ b/go/elasticsearch/inlinescript_builder_gen.go @@ -39,8 +39,8 @@ func (builder *InlineScriptBuilder) Build() (InlineScript, error) { return *builder.internal, nil } -func (builder *InlineScriptBuilder) String(string string) *InlineScriptBuilder { - builder.internal.String = &string +func (builder *InlineScriptBuilder) String(stringArg string) *InlineScriptBuilder { + builder.internal.String = &stringArg return builder } diff --git a/go/elasticsearch/stringorstruct_builder_gen.go b/go/elasticsearch/stringorstruct_builder_gen.go index 2d2a01e..ef21877 100644 --- a/go/elasticsearch/stringorstruct_builder_gen.go +++ b/go/elasticsearch/stringorstruct_builder_gen.go @@ -39,8 +39,8 @@ func (builder *StringOrStructBuilder) Build() (StringOrStruct, error) { return *builder.internal, nil } -func (builder *StringOrStructBuilder) String(string string) *StringOrStructBuilder { - builder.internal.String = &string +func (builder *StringOrStructBuilder) String(stringArg string) *StringOrStructBuilder { + builder.internal.String = &stringArg return builder } diff --git a/go/heatmap/panel_builder_gen.go b/go/heatmap/panel_builder_gen.go index 9c62343..045788c 100644 --- a/go/heatmap/panel_builder_gen.go +++ b/go/heatmap/panel_builder_gen.go @@ -626,6 +626,16 @@ func (builder *PanelBuilder) ExemplarsColor(color string) *PanelBuilder { return builder } +// Controls which axis to allow selection on +func (builder *PanelBuilder) SelectionMode(selectionMode HeatmapSelectionMode) *PanelBuilder { + if builder.internal.Options == nil { + builder.internal.Options = &Options{} + } + builder.internal.Options.(*Options).SelectionMode = &selectionMode + + return builder +} + func (builder *PanelBuilder) ScaleDistribution(scaleDistribution cog.Builder[common.ScaleDistributionConfig]) *PanelBuilder { if builder.internal.FieldConfig == nil { builder.internal.FieldConfig = &dashboard.FieldConfigSource{} @@ -678,4 +688,5 @@ func (builder *PanelBuilder) applyDefaults() { builder.ShowValue("auto") builder.CellGap(1) builder.ExemplarsColor("rgba(255,0,255,0.7)") + builder.SelectionMode("x") } diff --git a/go/heatmap/types_gen.go b/go/heatmap/types_gen.go index 7938615..583f986 100644 --- a/go/heatmap/types_gen.go +++ b/go/heatmap/types_gen.go @@ -25,6 +25,15 @@ const ( HeatmapColorScaleExponential HeatmapColorScale = "exponential" ) +// Controls which axis to allow selection on +type HeatmapSelectionMode string + +const ( + HeatmapSelectionModeX HeatmapSelectionMode = "x" + HeatmapSelectionModeY HeatmapSelectionMode = "y" + HeatmapSelectionModeXy HeatmapSelectionMode = "xy" +) + // Controls various color options type HeatmapColorOptions struct { // Sets the color mode @@ -152,6 +161,8 @@ type Options struct { Tooltip HeatmapTooltip `json:"tooltip"` // Controls exemplar options Exemplars ExemplarConfig `json:"exemplars"` + // Controls which axis to allow selection on + SelectionMode *HeatmapSelectionMode `json:"selectionMode,omitempty"` } type FieldConfig struct { diff --git a/jsonschema/alerting.jsonschema.json b/jsonschema/alerting.jsonschema.json index f17d52d..bb926f0 100644 --- a/jsonschema/alerting.jsonschema.json +++ b/jsonschema/alerting.jsonschema.json @@ -299,6 +299,9 @@ "provenance": { "$ref": "#/definitions/Provenance" }, + "record": { + "$ref": "#/definitions/RecordRule" + }, "ruleGroup": { "type": "string", "minLength": 1, @@ -320,6 +323,22 @@ } } }, + "RecordRule": { + "type": "object", + "additionalProperties": false, + "required": [ + "from", + "metric" + ], + "properties": { + "from": { + "type": "string" + }, + "metric": { + "type": "string" + } + } + }, "RelativeTimeRange": { "type": "object", "additionalProperties": false, diff --git a/jsonschema/azuremonitor.jsonschema.json b/jsonschema/azuremonitor.jsonschema.json index 3aa1d09..983c6d1 100644 --- a/jsonschema/azuremonitor.jsonschema.json +++ b/jsonschema/azuremonitor.jsonschema.json @@ -61,14 +61,17 @@ "resource": { "type": "string" }, + "region": { + "type": "string" + }, "datasource": { "type": "object", "additionalProperties": {}, "description": "For mixed data sources the selected datasource is on the query level.\nFor non mixed scenarios this is undefined.\nTODO find a better way to do this ^ that's friendly to schema\nTODO this shouldn't be unknown but DataSourceRef | null" }, - "region": { + "query": { "type": "string", - "description": "Azure Monitor query type.\nqueryType: #AzureQueryType" + "description": "Used only for exemplar queries from Prometheus" } } }, @@ -85,7 +88,8 @@ "Azure Metric Names", "Azure Workspaces", "Azure Regions", - "Grafana Template Variable Function" + "Grafana Template Variable Function", + "traceql" ], "description": "Defines the supported queryTypes. GrafanaTemplateVariableFn is deprecated" }, diff --git a/jsonschema/common.jsonschema.json b/jsonschema/common.jsonschema.json index 9a0163c..ec9b99e 100644 --- a/jsonschema/common.jsonschema.json +++ b/jsonschema/common.jsonschema.json @@ -1123,6 +1123,9 @@ "type": { "type": "string", "const": "auto" + }, + "wrapText": { + "type": "boolean" } }, "description": "Auto mode table cell options" @@ -1137,6 +1140,9 @@ "type": { "type": "string", "const": "color-text" + }, + "wrapText": { + "type": "boolean" } }, "description": "Colored text cell options" @@ -1347,6 +1353,9 @@ }, "applyToRow": { "type": "boolean" + }, + "wrapText": { + "type": "boolean" } }, "description": "Colored background cell options" @@ -1355,7 +1364,8 @@ "enum": [ "sm", "md", - "lg" + "lg", + "auto" ], "description": "Height of a table cell" }, diff --git a/jsonschema/heatmap.jsonschema.json b/jsonschema/heatmap.jsonschema.json index a0e8d5e..ee7a168 100644 --- a/jsonschema/heatmap.jsonschema.json +++ b/jsonschema/heatmap.jsonschema.json @@ -15,6 +15,14 @@ ], "description": "Controls the color scale of the heatmap" }, + "HeatmapSelectionMode": { + "enum": [ + "x", + "y", + "xy" + ], + "description": "Controls which axis to allow selection on" + }, "HeatmapColorOptions": { "type": "object", "additionalProperties": false, @@ -308,6 +316,11 @@ "default": { "color": "rgba(255,0,255,0.7)" } + }, + "selectionMode": { + "$ref": "#/definitions/HeatmapSelectionMode", + "description": "Controls which axis to allow selection on", + "default": "x" } } }, diff --git a/jsonschema/table.jsonschema.json b/jsonschema/table.jsonschema.json index 09387da..4ac0b57 100644 --- a/jsonschema/table.jsonschema.json +++ b/jsonschema/table.jsonschema.json @@ -105,7 +105,8 @@ "enum": [ "sm", "md", - "lg" + "lg", + "auto" ], "description": "Height of a table cell" }, @@ -218,6 +219,9 @@ "type": { "type": "string", "const": "auto" + }, + "wrapText": { + "type": "boolean" } }, "description": "Auto mode table cell options" @@ -386,6 +390,9 @@ }, "applyToRow": { "type": "boolean" + }, + "wrapText": { + "type": "boolean" } }, "description": "Colored background cell options" @@ -400,6 +407,9 @@ "type": { "type": "string", "const": "color-text" + }, + "wrapText": { + "type": "boolean" } }, "description": "Colored text cell options" diff --git a/openapi/alerting.openapi.json b/openapi/alerting.openapi.json index c47f39c..9d6de84 100644 --- a/openapi/alerting.openapi.json +++ b/openapi/alerting.openapi.json @@ -307,6 +307,9 @@ "provenance": { "$ref": "#/components/schemas/Provenance" }, + "record": { + "$ref": "#/components/schemas/RecordRule" + }, "ruleGroup": { "type": "string", "minLength": 1, @@ -328,6 +331,22 @@ } } }, + "RecordRule": { + "type": "object", + "additionalProperties": false, + "required": [ + "from", + "metric" + ], + "properties": { + "from": { + "type": "string" + }, + "metric": { + "type": "string" + } + } + }, "RelativeTimeRange": { "type": "object", "additionalProperties": false, diff --git a/openapi/azuremonitor.openapi.json b/openapi/azuremonitor.openapi.json index 82454e4..571ef1a 100644 --- a/openapi/azuremonitor.openapi.json +++ b/openapi/azuremonitor.openapi.json @@ -70,14 +70,17 @@ "resource": { "type": "string" }, + "region": { + "type": "string" + }, "datasource": { "type": "object", "additionalProperties": {}, "description": "For mixed data sources the selected datasource is on the query level.\nFor non mixed scenarios this is undefined.\nTODO find a better way to do this ^ that's friendly to schema\nTODO this shouldn't be unknown but DataSourceRef | null" }, - "region": { + "query": { "type": "string", - "description": "Azure Monitor query type.\nqueryType: #AzureQueryType" + "description": "Used only for exemplar queries from Prometheus" } } }, @@ -94,7 +97,8 @@ "Azure Metric Names", "Azure Workspaces", "Azure Regions", - "Grafana Template Variable Function" + "Grafana Template Variable Function", + "traceql" ], "description": "Defines the supported queryTypes. GrafanaTemplateVariableFn is deprecated" }, diff --git a/openapi/common.openapi.json b/openapi/common.openapi.json index f03e8df..914e6b8 100644 --- a/openapi/common.openapi.json +++ b/openapi/common.openapi.json @@ -1131,6 +1131,9 @@ "type": { "type": "string", "const": "auto" + }, + "wrapText": { + "type": "boolean" } }, "description": "Auto mode table cell options" @@ -1145,6 +1148,9 @@ "type": { "type": "string", "const": "color-text" + }, + "wrapText": { + "type": "boolean" } }, "description": "Colored text cell options" @@ -1355,6 +1361,9 @@ }, "applyToRow": { "type": "boolean" + }, + "wrapText": { + "type": "boolean" } }, "description": "Colored background cell options" @@ -1363,7 +1372,8 @@ "enum": [ "sm", "md", - "lg" + "lg", + "auto" ], "description": "Height of a table cell" }, diff --git a/openapi/heatmap.openapi.json b/openapi/heatmap.openapi.json index 80cb0b9..b6d4cb4 100644 --- a/openapi/heatmap.openapi.json +++ b/openapi/heatmap.openapi.json @@ -24,6 +24,14 @@ ], "description": "Controls the color scale of the heatmap" }, + "HeatmapSelectionMode": { + "enum": [ + "x", + "y", + "xy" + ], + "description": "Controls which axis to allow selection on" + }, "HeatmapColorOptions": { "type": "object", "additionalProperties": false, @@ -317,6 +325,11 @@ "default": { "color": "rgba(255,0,255,0.7)" } + }, + "selectionMode": { + "$ref": "#/components/schemas/HeatmapSelectionMode", + "description": "Controls which axis to allow selection on", + "default": "x" } } }, diff --git a/openapi/table.openapi.json b/openapi/table.openapi.json index 930cc90..d42ed0e 100644 --- a/openapi/table.openapi.json +++ b/openapi/table.openapi.json @@ -114,7 +114,8 @@ "enum": [ "sm", "md", - "lg" + "lg", + "auto" ], "description": "Height of a table cell" }, @@ -227,6 +228,9 @@ "type": { "type": "string", "const": "auto" + }, + "wrapText": { + "type": "boolean" } }, "description": "Auto mode table cell options" @@ -395,6 +399,9 @@ }, "applyToRow": { "type": "boolean" + }, + "wrapText": { + "type": "boolean" } }, "description": "Colored background cell options" @@ -409,6 +416,9 @@ "type": { "type": "string", "const": "color-text" + }, + "wrapText": { + "type": "boolean" } }, "description": "Colored text cell options" diff --git a/python/grafana_foundation_sdk/builders/alerting.py b/python/grafana_foundation_sdk/builders/alerting.py index eaa3d84..4b1ea99 100644 --- a/python/grafana_foundation_sdk/builders/alerting.py +++ b/python/grafana_foundation_sdk/builders/alerting.py @@ -374,6 +374,12 @@ class Rule(cogbuilder.Builder[alerting.Rule]): return self + def record(self, record: cogbuilder.Builder[alerting.RecordRule]) -> typing.Self: + record_resource = record.build() + self._internal.record = record_resource + + return self + def rule_group(self, rule_group: str) -> typing.Self: if not len(rule_group) >= 1: raise ValueError("len(rule_group) must be >= 1") @@ -407,6 +413,26 @@ class Rule(cogbuilder.Builder[alerting.Rule]): return self +class RecordRule(cogbuilder.Builder[alerting.RecordRule]): + _internal: alerting.RecordRule + + def __init__(self): + self._internal = alerting.RecordRule() + + def build(self) -> alerting.RecordRule: + return self._internal + + def from_val(self, from_val: str) -> typing.Self: + self._internal.from_val = from_val + + return self + + def metric(self, metric: str) -> typing.Self: + self._internal.metric = metric + + return self + + class NotificationPolicy(cogbuilder.Builder[alerting.NotificationPolicy]): """ A Route is a node that contains definitions of how to handle alerts. This is modified diff --git a/python/grafana_foundation_sdk/builders/azuremonitor.py b/python/grafana_foundation_sdk/builders/azuremonitor.py index 7c26cae..a9e2529 100644 --- a/python/grafana_foundation_sdk/builders/azuremonitor.py +++ b/python/grafana_foundation_sdk/builders/azuremonitor.py @@ -130,6 +130,11 @@ class AzureMonitorQuery(cogbuilder.Builder[azuremonitor.AzureMonitorQuery]): return self + def region(self, region: str) -> typing.Self: + self._internal.region = region + + return self + def datasource(self, datasource: object) -> typing.Self: """ For mixed data sources the selected datasource is on the query level. @@ -142,13 +147,12 @@ class AzureMonitorQuery(cogbuilder.Builder[azuremonitor.AzureMonitorQuery]): return self - def region(self, region: str) -> typing.Self: + def query(self, query: str) -> typing.Self: """ - Azure Monitor query type. - queryType: #AzureQueryType + Used only for exemplar queries from Prometheus """ - self._internal.region = region + self._internal.query = query return self diff --git a/python/grafana_foundation_sdk/builders/common.py b/python/grafana_foundation_sdk/builders/common.py index 2c145b1..ad060e0 100644 --- a/python/grafana_foundation_sdk/builders/common.py +++ b/python/grafana_foundation_sdk/builders/common.py @@ -1283,6 +1283,46 @@ class TableFooterOptions(cogbuilder.Builder[common.TableFooterOptions]): return self +class TableAutoCellOptions(cogbuilder.Builder[common.TableAutoCellOptions]): + """ + Auto mode table cell options + """ + + _internal: common.TableAutoCellOptions + + def __init__(self): + self._internal = common.TableAutoCellOptions() + self._internal.type_val = "auto" + + def build(self) -> common.TableAutoCellOptions: + return self._internal + + def wrap_text(self, wrap_text: bool) -> typing.Self: + self._internal.wrap_text = wrap_text + + return self + + +class TableColorTextCellOptions(cogbuilder.Builder[common.TableColorTextCellOptions]): + """ + Colored text cell options + """ + + _internal: common.TableColorTextCellOptions + + def __init__(self): + self._internal = common.TableColorTextCellOptions() + self._internal.type_val = "color-text" + + def build(self) -> common.TableColorTextCellOptions: + return self._internal + + def wrap_text(self, wrap_text: bool) -> typing.Self: + self._internal.wrap_text = wrap_text + + return self + + class TableBarGaugeCellOptions(cogbuilder.Builder[common.TableBarGaugeCellOptions]): """ Gauge cell options @@ -1523,6 +1563,11 @@ class TableColoredBackgroundCellOptions(cogbuilder.Builder[common.TableColoredBa return self + def wrap_text(self, wrap_text: bool) -> typing.Self: + self._internal.wrap_text = wrap_text + + return self + class DataSourceRef(cogbuilder.Builder[common.DataSourceRef]): _internal: common.DataSourceRef diff --git a/python/grafana_foundation_sdk/builders/heatmap.py b/python/grafana_foundation_sdk/builders/heatmap.py index fc6d8af..9546e30 100644 --- a/python/grafana_foundation_sdk/builders/heatmap.py +++ b/python/grafana_foundation_sdk/builders/heatmap.py @@ -717,6 +717,18 @@ class Panel(cogbuilder.Builder[dashboard.Panel]): return self + def selection_mode(self, selection_mode: heatmap.HeatmapSelectionMode) -> typing.Self: + """ + Controls which axis to allow selection on + """ + + if self._internal.options is None: + self._internal.options = heatmap.Options() + assert isinstance(self._internal.options, heatmap.Options) + self._internal.options.selection_mode = selection_mode + + return self + def scale_distribution(self, scale_distribution: cogbuilder.Builder[common.ScaleDistributionConfig]) -> typing.Self: if self._internal.field_config is None: self._internal.field_config = dashboard.FieldConfigSource() diff --git a/python/grafana_foundation_sdk/cog/plugins.py b/python/grafana_foundation_sdk/cog/plugins.py index ea5481d..e34ddc9 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 dashboardlist -from ..models import debug -from ..models import histogram -from ..models import stat -from ..models import tempo -from ..models import expr -from ..models import barchart -from ..models import datagrid -from ..models import grafanapyroscope -from ..models import heatmap +from ..models import prometheus +from ..models import azuremonitor +from ..models import gauge from ..models import nodegraph -from ..models import cloudwatch from ..models import text -from ..models import timeseries -from ..models import canvas -from ..models import googlecloudmonitoring -from ..models import loki +from ..models import xychart +from ..models import logs from ..models import trend -from ..models import statushistory -from ..models import prometheus -from ..models import annotationslist -from ..models import statetimeline +from ..models import heatmap from ..models import bargauge -from ..models import gauge -from ..models import logs -from ..models import azuremonitor -from ..models import candlestick -from ..models import elasticsearch +from ..models import datagrid +from ..models import googlecloudmonitoring from ..models import piechart -from ..models import xychart +from ..models import statetimeline +from ..models import elasticsearch from ..models import geomap from ..models import news -from ..models import parca +from ..models import debug +from ..models import grafanapyroscope +from ..models import histogram +from ..models import annotationslist +from ..models import barchart +from ..models import cloudwatch +from ..models import loki +from ..models import statushistory +from ..models import expr +from ..models import canvas from ..models import table +from ..models import tempo +from ..models import timeseries +from ..models import candlestick +from ..models import dashboardlist +from ..models import parca +from ..models import stat from . import runtime as cogruntime diff --git a/python/grafana_foundation_sdk/models/alerting.py b/python/grafana_foundation_sdk/models/alerting.py index 4cf34db..8c51475 100644 --- a/python/grafana_foundation_sdk/models/alerting.py +++ b/python/grafana_foundation_sdk/models/alerting.py @@ -363,12 +363,13 @@ class Rule: notification_settings: typing.Optional['NotificationSettings'] org_id: int provenance: typing.Optional['Provenance'] + record: typing.Optional['RecordRule'] rule_group: str title: str uid: typing.Optional[str] updated: typing.Optional[str] - def __init__(self, annotations: typing.Optional[dict[str, str]] = None, condition: str = "", data: typing.Optional[list['Query']] = None, exec_err_state: typing.Optional[typing.Literal["OK", "Alerting", "Error"]] = None, folder_uid: str = "", for_val: str = "", id_val: typing.Optional[int] = None, is_paused: typing.Optional[bool] = None, labels: typing.Optional[dict[str, str]] = None, no_data_state: typing.Optional[typing.Literal["Alerting", "NoData", "OK"]] = None, notification_settings: typing.Optional['NotificationSettings'] = None, org_id: int = 0, provenance: typing.Optional['Provenance'] = None, rule_group: str = "", title: str = "", uid: typing.Optional[str] = None, updated: typing.Optional[str] = None): + def __init__(self, annotations: typing.Optional[dict[str, str]] = None, condition: str = "", data: typing.Optional[list['Query']] = None, exec_err_state: typing.Optional[typing.Literal["OK", "Alerting", "Error"]] = None, folder_uid: str = "", for_val: str = "", id_val: typing.Optional[int] = None, is_paused: typing.Optional[bool] = None, labels: typing.Optional[dict[str, str]] = None, no_data_state: typing.Optional[typing.Literal["Alerting", "NoData", "OK"]] = None, notification_settings: typing.Optional['NotificationSettings'] = None, org_id: int = 0, provenance: typing.Optional['Provenance'] = None, record: typing.Optional['RecordRule'] = None, rule_group: str = "", title: str = "", uid: typing.Optional[str] = None, updated: typing.Optional[str] = None): self.annotations = annotations self.condition = condition self.data = data if data is not None else [] @@ -382,6 +383,7 @@ class Rule: self.notification_settings = notification_settings self.org_id = org_id self.provenance = provenance + self.record = record self.rule_group = rule_group self.title = title self.uid = uid @@ -411,6 +413,8 @@ class Rule: payload["notification_settings"] = self.notification_settings if self.provenance is not None: payload["provenance"] = self.provenance + if self.record is not None: + payload["record"] = self.record if self.uid is not None: payload["uid"] = self.uid if self.updated is not None: @@ -447,6 +451,8 @@ class Rule: args["org_id"] = data["orgID"] if "provenance" in data: args["provenance"] = data["provenance"] + if "record" in data: + args["record"] = RecordRule.from_json(data["record"]) if "ruleGroup" in data: args["rule_group"] = data["ruleGroup"] if "title" in data: @@ -459,6 +465,33 @@ class Rule: return cls(**args) +class RecordRule: + from_val: str + metric: str + + def __init__(self, from_val: str = "", metric: str = ""): + self.from_val = from_val + self.metric = metric + + def to_json(self) -> dict[str, object]: + payload: dict[str, object] = { + "from": self.from_val, + "metric": self.metric, + } + return payload + + @classmethod + def from_json(cls, data: dict[str, typing.Any]) -> typing.Self: + args: dict[str, typing.Any] = {} + + if "from" in data: + args["from_val"] = data["from"] + if "metric" in data: + args["metric"] = data["metric"] + + return cls(**args) + + class RelativeTimeRange: """ RelativeTimeRange is the per query start and end time diff --git a/python/grafana_foundation_sdk/models/azuremonitor.py b/python/grafana_foundation_sdk/models/azuremonitor.py index 93942e6..caec76d 100644 --- a/python/grafana_foundation_sdk/models/azuremonitor.py +++ b/python/grafana_foundation_sdk/models/azuremonitor.py @@ -34,16 +34,16 @@ class AzureMonitorQuery(cogvariants.Dataquery): resource_group: typing.Optional[str] namespace: typing.Optional[str] resource: typing.Optional[str] + region: typing.Optional[str] # For mixed data sources the selected datasource is on the query level. # For non mixed scenarios this is undefined. # TODO find a better way to do this ^ that's friendly to schema # TODO this shouldn't be unknown but DataSourceRef | null datasource: typing.Optional[object] - # Azure Monitor query type. - # queryType: #AzureQueryType - region: typing.Optional[str] + # Used only for exemplar queries from Prometheus + query: typing.Optional[str] - def __init__(self, ref_id: str = "", hide: typing.Optional[bool] = None, query_type: typing.Optional[str] = None, subscription: typing.Optional[str] = None, subscriptions: typing.Optional[list[str]] = None, azure_monitor: typing.Optional['AzureMetricQuery'] = None, azure_log_analytics: typing.Optional['AzureLogsQuery'] = None, azure_resource_graph: typing.Optional['AzureResourceGraphQuery'] = None, azure_traces: typing.Optional['AzureTracesQuery'] = None, grafana_template_variable_fn: typing.Optional['GrafanaTemplateVariableQuery'] = None, resource_group: typing.Optional[str] = None, namespace: typing.Optional[str] = None, resource: typing.Optional[str] = None, datasource: typing.Optional[object] = None, region: typing.Optional[str] = None): + def __init__(self, ref_id: str = "", hide: typing.Optional[bool] = None, query_type: typing.Optional[str] = None, subscription: typing.Optional[str] = None, subscriptions: typing.Optional[list[str]] = None, azure_monitor: typing.Optional['AzureMetricQuery'] = None, azure_log_analytics: typing.Optional['AzureLogsQuery'] = None, azure_resource_graph: typing.Optional['AzureResourceGraphQuery'] = None, azure_traces: typing.Optional['AzureTracesQuery'] = None, grafana_template_variable_fn: typing.Optional['GrafanaTemplateVariableQuery'] = None, resource_group: typing.Optional[str] = None, namespace: typing.Optional[str] = None, resource: typing.Optional[str] = None, region: typing.Optional[str] = None, datasource: typing.Optional[object] = None, query: typing.Optional[str] = None): self.ref_id = ref_id self.hide = hide self.query_type = query_type @@ -57,8 +57,9 @@ class AzureMonitorQuery(cogvariants.Dataquery): self.resource_group = resource_group self.namespace = namespace self.resource = resource - self.datasource = datasource self.region = region + self.datasource = datasource + self.query = query def to_json(self) -> dict[str, object]: payload: dict[str, object] = { @@ -88,10 +89,12 @@ class AzureMonitorQuery(cogvariants.Dataquery): payload["namespace"] = self.namespace if self.resource is not None: payload["resource"] = self.resource - if self.datasource is not None: - payload["datasource"] = self.datasource if self.region is not None: payload["region"] = self.region + if self.datasource is not None: + payload["datasource"] = self.datasource + if self.query is not None: + payload["query"] = self.query return payload @classmethod @@ -124,10 +127,12 @@ class AzureMonitorQuery(cogvariants.Dataquery): args["namespace"] = data["namespace"] if "resource" in data: args["resource"] = data["resource"] + if "region" in data: + args["region"] = data["region"] if "datasource" in data: args["datasource"] = data["datasource"] - if "region" in data: - args["region"] = data["region"] + if "query" in data: + args["query"] = data["query"] return cls(**args) @@ -156,6 +161,7 @@ class AzureQueryType(enum.StrEnum): WORKSPACES_QUERY = "Azure Workspaces" LOCATIONS_QUERY = "Azure Regions" GRAFANA_TEMPLATE_VARIABLE_FN = "Grafana Template Variable Function" + TRACE_EXEMPLAR = "traceql" class AzureMetricQuery: diff --git a/python/grafana_foundation_sdk/models/cloudwatch.py b/python/grafana_foundation_sdk/models/cloudwatch.py index 761fcb8..4db2b96 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 b7df805..94e6f37 100644 --- a/python/grafana_foundation_sdk/models/common.py +++ b/python/grafana_foundation_sdk/models/common.py @@ -1917,19 +1917,27 @@ class TableAutoCellOptions: """ type_val: typing.Literal["auto"] + wrap_text: typing.Optional[bool] - def __init__(self, ): + def __init__(self, wrap_text: typing.Optional[bool] = None): self.type_val = "auto" + self.wrap_text = wrap_text def to_json(self) -> dict[str, object]: payload: dict[str, object] = { "type": self.type_val, } + if self.wrap_text is not None: + payload["wrapText"] = self.wrap_text return payload @classmethod def from_json(cls, data: dict[str, typing.Any]) -> typing.Self: args: dict[str, typing.Any] = {} + + if "wrapText" in data: + args["wrap_text"] = data["wrapText"] + return cls(**args) @@ -1939,19 +1947,27 @@ class TableColorTextCellOptions: """ type_val: typing.Literal["color-text"] + wrap_text: typing.Optional[bool] - def __init__(self, ): + def __init__(self, wrap_text: typing.Optional[bool] = None): self.type_val = "color-text" + self.wrap_text = wrap_text def to_json(self) -> dict[str, object]: payload: dict[str, object] = { "type": self.type_val, } + if self.wrap_text is not None: + payload["wrapText"] = self.wrap_text return payload @classmethod def from_json(cls, data: dict[str, typing.Any]) -> typing.Self: args: dict[str, typing.Any] = {} + + if "wrapText" in data: + args["wrap_text"] = data["wrapText"] + return cls(**args) @@ -2290,11 +2306,13 @@ class TableColoredBackgroundCellOptions: type_val: typing.Literal["color-background"] mode: typing.Optional['TableCellBackgroundDisplayMode'] apply_to_row: typing.Optional[bool] + wrap_text: typing.Optional[bool] - def __init__(self, mode: typing.Optional['TableCellBackgroundDisplayMode'] = None, apply_to_row: typing.Optional[bool] = None): + def __init__(self, mode: typing.Optional['TableCellBackgroundDisplayMode'] = None, apply_to_row: typing.Optional[bool] = None, wrap_text: typing.Optional[bool] = None): self.type_val = "color-background" self.mode = mode self.apply_to_row = apply_to_row + self.wrap_text = wrap_text def to_json(self) -> dict[str, object]: payload: dict[str, object] = { @@ -2304,6 +2322,8 @@ class TableColoredBackgroundCellOptions: payload["mode"] = self.mode if self.apply_to_row is not None: payload["applyToRow"] = self.apply_to_row + if self.wrap_text is not None: + payload["wrapText"] = self.wrap_text return payload @classmethod @@ -2313,7 +2333,9 @@ class TableColoredBackgroundCellOptions: if "mode" in data: args["mode"] = data["mode"] if "applyToRow" in data: - args["apply_to_row"] = data["applyToRow"] + args["apply_to_row"] = data["applyToRow"] + if "wrapText" in data: + args["wrap_text"] = data["wrapText"] return cls(**args) @@ -2326,6 +2348,7 @@ class TableCellHeight(enum.StrEnum): SM = "sm" MD = "md" LG = "lg" + AUTO = "auto" # Table cell options. Each cell has a display mode diff --git a/python/grafana_foundation_sdk/models/expr.py b/python/grafana_foundation_sdk/models/expr.py index 0f8654e..bcd9dbf 100644 --- a/python/grafana_foundation_sdk/models/expr.py +++ b/python/grafana_foundation_sdk/models/expr.py @@ -9,7 +9,7 @@ Expr: typing.TypeAlias = typing.Union['TypeMath', 'TypeReduce', 'TypeResample', def variant_config() -> cogruntime.DataqueryConfig: - decoding_map: dict[str, typing.Union[typing.Type[TypeClassicConditions], typing.Type[TypeThreshold], typing.Type[TypeSql], typing.Type[TypeMath], typing.Type[TypeReduce], typing.Type[TypeResample]]] = {"classic_conditions": TypeClassicConditions, "threshold": TypeThreshold, "sql": TypeSql, "math": TypeMath, "reduce": TypeReduce, "resample": TypeResample} + decoding_map: dict[str, typing.Union[typing.Type[TypeReduce], typing.Type[TypeResample], typing.Type[TypeClassicConditions], typing.Type[TypeThreshold], typing.Type[TypeSql], typing.Type[TypeMath]]] = {"reduce": TypeReduce, "resample": TypeResample, "classic_conditions": TypeClassicConditions, "threshold": TypeThreshold, "sql": TypeSql, "math": TypeMath} return cogruntime.DataqueryConfig( identifier="__expr__", from_json_hook=lambda data: decoding_map[data["type"]].from_json(data), diff --git a/python/grafana_foundation_sdk/models/heatmap.py b/python/grafana_foundation_sdk/models/heatmap.py index 1a9a40b..c20a649 100644 --- a/python/grafana_foundation_sdk/models/heatmap.py +++ b/python/grafana_foundation_sdk/models/heatmap.py @@ -24,6 +24,16 @@ class HeatmapColorScale(enum.StrEnum): EXPONENTIAL = "exponential" +class HeatmapSelectionMode(enum.StrEnum): + """ + Controls which axis to allow selection on + """ + + X = "x" + Y = "y" + XY = "xy" + + class HeatmapColorOptions: """ Controls various color options @@ -464,8 +474,10 @@ class Options: tooltip: 'HeatmapTooltip' # Controls exemplar options exemplars: 'ExemplarConfig' + # Controls which axis to allow selection on + selection_mode: typing.Optional['HeatmapSelectionMode'] - def __init__(self, calculate: typing.Optional[bool] = False, calculation: typing.Optional[common.HeatmapCalculationOptions] = None, color: typing.Optional['HeatmapColorOptions'] = None, filter_values: typing.Optional['FilterValueRange'] = None, rows_frame: typing.Optional['RowsHeatmapOptions'] = None, show_value: typing.Optional[common.VisibilityMode] = None, cell_gap: typing.Optional[int] = 1, cell_radius: typing.Optional[float] = None, cell_values: typing.Optional['CellValues'] = None, y_axis: typing.Optional['YAxisConfig'] = None, legend: typing.Optional['HeatmapLegend'] = None, tooltip: typing.Optional['HeatmapTooltip'] = None, exemplars: typing.Optional['ExemplarConfig'] = None): + def __init__(self, calculate: typing.Optional[bool] = False, calculation: typing.Optional[common.HeatmapCalculationOptions] = None, color: typing.Optional['HeatmapColorOptions'] = None, filter_values: typing.Optional['FilterValueRange'] = None, rows_frame: typing.Optional['RowsHeatmapOptions'] = None, show_value: typing.Optional[common.VisibilityMode] = None, cell_gap: typing.Optional[int] = 1, cell_radius: typing.Optional[float] = None, cell_values: typing.Optional['CellValues'] = None, y_axis: typing.Optional['YAxisConfig'] = None, legend: typing.Optional['HeatmapLegend'] = None, tooltip: typing.Optional['HeatmapTooltip'] = None, exemplars: typing.Optional['ExemplarConfig'] = None, selection_mode: typing.Optional['HeatmapSelectionMode'] = None): self.calculate = calculate self.calculation = calculation self.color = color if color is not None else HeatmapColorOptions(exponent=0.5, fill="dark-orange", reverse=False, scheme="Oranges", steps=64) @@ -479,6 +491,7 @@ class Options: self.legend = legend if legend is not None else HeatmapLegend(show=True) self.tooltip = tooltip if tooltip is not None else HeatmapTooltip() self.exemplars = exemplars if exemplars is not None else ExemplarConfig(color="rgba(255,0,255,0.7)") + self.selection_mode = selection_mode if selection_mode is not None else HeatmapSelectionMode.X def to_json(self) -> dict[str, object]: payload: dict[str, object] = { @@ -503,6 +516,8 @@ class Options: payload["cellRadius"] = self.cell_radius if self.cell_values is not None: payload["cellValues"] = self.cell_values + if self.selection_mode is not None: + payload["selectionMode"] = self.selection_mode return payload @classmethod @@ -534,7 +549,9 @@ class Options: if "tooltip" in data: args["tooltip"] = HeatmapTooltip.from_json(data["tooltip"]) if "exemplars" in data: - args["exemplars"] = ExemplarConfig.from_json(data["exemplars"]) + args["exemplars"] = ExemplarConfig.from_json(data["exemplars"]) + if "selectionMode" in data: + args["selection_mode"] = data["selectionMode"] return cls(**args) diff --git a/python/pyproject.toml b/python/pyproject.toml index 7b9c1fb..9878c92 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -13,7 +13,7 @@ keywords = [ "traces", "metrics" ] -version = "1717501769!next" +version = "1718105636!next" dependencies = [] requires-python = ">=3.11" classifiers = [ diff --git a/typescript/package.json b/typescript/package.json index 763fd20..7564643 100644 --- a/typescript/package.json +++ b/typescript/package.json @@ -1,6 +1,6 @@ { "name": "@grafana/grafana-foundation-sdk", - "version": "next-cogv0.0.x.1717501769", + "version": "next-cogv0.0.x.1718105636", "description": "A set of tools, types and libraries for building and manipulating Grafana objects.", "keywords": [ "observability", diff --git a/typescript/src/alerting/index.ts b/typescript/src/alerting/index.ts index 291bcd8..58d42da 100644 --- a/typescript/src/alerting/index.ts +++ b/typescript/src/alerting/index.ts @@ -18,6 +18,8 @@ export * from './notificationTemplateBuilder.gen'; export type * from './notificationTemplateBuilder.gen'; export * from './ruleBuilder.gen'; export type * from './ruleBuilder.gen'; +export * from './recordRuleBuilder.gen'; +export type * from './recordRuleBuilder.gen'; export * from './notificationPolicyBuilder.gen'; export type * from './notificationPolicyBuilder.gen'; export * from './timeIntervalBuilder.gen'; diff --git a/typescript/src/alerting/recordRuleBuilder.gen.ts b/typescript/src/alerting/recordRuleBuilder.gen.ts new file mode 100644 index 0000000..174a219 --- /dev/null +++ b/typescript/src/alerting/recordRuleBuilder.gen.ts @@ -0,0 +1,26 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. + +import * as cog from '../cog'; +import * as alerting from '../alerting'; + +export class RecordRuleBuilder implements cog.Builder { + protected readonly internal: alerting.RecordRule; + + constructor() { + this.internal = alerting.defaultRecordRule(); + } + + build(): alerting.RecordRule { + return this.internal; + } + + from(from: string): this { + this.internal.from = from; + return this; + } + + metric(metric: string): this { + this.internal.metric = metric; + return this; + } +} diff --git a/typescript/src/alerting/ruleBuilder.gen.ts b/typescript/src/alerting/ruleBuilder.gen.ts index f3ec26f..809191a 100644 --- a/typescript/src/alerting/ruleBuilder.gen.ts +++ b/typescript/src/alerting/ruleBuilder.gen.ts @@ -99,6 +99,12 @@ export class RuleBuilder implements cog.Builder { return this; } + record(record: cog.Builder): this { + const recordResource = record.build(); + this.internal.record = recordResource; + return this; + } + ruleGroup(ruleGroup: string): this { if (!(ruleGroup.length >= 1)) { throw new Error("ruleGroup.length must be >= 1"); diff --git a/typescript/src/alerting/types.gen.ts b/typescript/src/alerting/types.gen.ts index e0261e1..500119b 100644 --- a/typescript/src/alerting/types.gen.ts +++ b/typescript/src/alerting/types.gen.ts @@ -154,6 +154,7 @@ export interface Rule { notification_settings?: NotificationSettings; orgID: number; provenance?: Provenance; + record?: RecordRule; ruleGroup: string; title: string; uid?: string; @@ -172,6 +173,16 @@ export const defaultRule = (): Rule => ({ title: "", }); +export interface RecordRule { + from: string; + metric: string; +} + +export const defaultRecordRule = (): RecordRule => ({ + from: "", + metric: "", +}); + // RelativeTimeRange is the per query start and end time // for requests. export interface RelativeTimeRange { diff --git a/typescript/src/azuremonitor/azureMonitorQueryBuilder.gen.ts b/typescript/src/azuremonitor/azureMonitorQueryBuilder.gen.ts index cab3459..1e4f0d4 100644 --- a/typescript/src/azuremonitor/azureMonitorQueryBuilder.gen.ts +++ b/typescript/src/azuremonitor/azureMonitorQueryBuilder.gen.ts @@ -97,6 +97,11 @@ export class AzureMonitorQueryBuilder implements cog.Builder { return this; } + region(region: string): this { + this.internal.region = region; + return this; + } + // For mixed data sources the selected datasource is on the query level. // For non mixed scenarios this is undefined. // TODO find a better way to do this ^ that's friendly to schema @@ -106,10 +111,9 @@ export class AzureMonitorQueryBuilder implements cog.Builder { return this; } - // Azure Monitor query type. - // queryType: #AzureQueryType - region(region: string): this { - this.internal.region = region; + // Used only for exemplar queries from Prometheus + query(query: string): this { + this.internal.query = query; return this; } } diff --git a/typescript/src/azuremonitor/types.gen.ts b/typescript/src/azuremonitor/types.gen.ts index d33d19d..e43597b 100644 --- a/typescript/src/azuremonitor/types.gen.ts +++ b/typescript/src/azuremonitor/types.gen.ts @@ -28,14 +28,14 @@ export interface AzureMonitorQuery { resourceGroup?: string; namespace?: string; resource?: string; + region?: string; // For mixed data sources the selected datasource is on the query level. // For non mixed scenarios this is undefined. // TODO find a better way to do this ^ that's friendly to schema // TODO this shouldn't be unknown but DataSourceRef | null datasource?: any; - // Azure Monitor query type. - // queryType: #AzureQueryType - region?: string; + // Used only for exemplar queries from Prometheus + query?: string; _implementsDataqueryVariant(): void; } @@ -58,6 +58,7 @@ export enum AzureQueryType { WorkspacesQuery = "Azure Workspaces", LocationsQuery = "Azure Regions", GrafanaTemplateVariableFn = "Grafana Template Variable Function", + TraceExemplar = "traceql", } export const defaultAzureQueryType = (): AzureQueryType => (AzureQueryType.AzureMonitor); diff --git a/typescript/src/common/index.ts b/typescript/src/common/index.ts index d1193f2..92c72d9 100644 --- a/typescript/src/common/index.ts +++ b/typescript/src/common/index.ts @@ -68,6 +68,10 @@ export * from './tableSortByFieldStateBuilder.gen'; export type * from './tableSortByFieldStateBuilder.gen'; export * from './tableFooterOptionsBuilder.gen'; export type * from './tableFooterOptionsBuilder.gen'; +export * from './tableAutoCellOptionsBuilder.gen'; +export type * from './tableAutoCellOptionsBuilder.gen'; +export * from './tableColorTextCellOptionsBuilder.gen'; +export type * from './tableColorTextCellOptionsBuilder.gen'; export * from './tableBarGaugeCellOptionsBuilder.gen'; export type * from './tableBarGaugeCellOptionsBuilder.gen'; export * from './tableSparklineCellOptionsBuilder.gen'; diff --git a/typescript/src/common/tableAutoCellOptionsBuilder.gen.ts b/typescript/src/common/tableAutoCellOptionsBuilder.gen.ts new file mode 100644 index 0000000..70dc3c0 --- /dev/null +++ b/typescript/src/common/tableAutoCellOptionsBuilder.gen.ts @@ -0,0 +1,23 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. + +import * as cog from '../cog'; +import * as common from '../common'; + +// Auto mode table cell options +export class TableAutoCellOptionsBuilder implements cog.Builder { + protected readonly internal: common.TableAutoCellOptions; + + constructor() { + this.internal = common.defaultTableAutoCellOptions(); + this.internal.type = "auto"; + } + + build(): common.TableAutoCellOptions { + return this.internal; + } + + wrapText(wrapText: boolean): this { + this.internal.wrapText = wrapText; + return this; + } +} diff --git a/typescript/src/common/tableColorTextCellOptionsBuilder.gen.ts b/typescript/src/common/tableColorTextCellOptionsBuilder.gen.ts new file mode 100644 index 0000000..0ed3650 --- /dev/null +++ b/typescript/src/common/tableColorTextCellOptionsBuilder.gen.ts @@ -0,0 +1,23 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. + +import * as cog from '../cog'; +import * as common from '../common'; + +// Colored text cell options +export class TableColorTextCellOptionsBuilder implements cog.Builder { + protected readonly internal: common.TableColorTextCellOptions; + + constructor() { + this.internal = common.defaultTableColorTextCellOptions(); + this.internal.type = "color-text"; + } + + build(): common.TableColorTextCellOptions { + return this.internal; + } + + wrapText(wrapText: boolean): this { + this.internal.wrapText = wrapText; + return this; + } +} diff --git a/typescript/src/common/tableColoredBackgroundCellOptionsBuilder.gen.ts b/typescript/src/common/tableColoredBackgroundCellOptionsBuilder.gen.ts index c7c2ef7..2482dab 100644 --- a/typescript/src/common/tableColoredBackgroundCellOptionsBuilder.gen.ts +++ b/typescript/src/common/tableColoredBackgroundCellOptionsBuilder.gen.ts @@ -25,4 +25,9 @@ export class TableColoredBackgroundCellOptionsBuilder implements cog.Builder ({ // Auto mode table cell options export interface TableAutoCellOptions { type: "auto"; + wrapText?: boolean; } export const defaultTableAutoCellOptions = (): TableAutoCellOptions => ({ @@ -828,6 +829,7 @@ export const defaultTableAutoCellOptions = (): TableAutoCellOptions => ({ // Colored text cell options export interface TableColorTextCellOptions { type: "color-text"; + wrapText?: boolean; } export const defaultTableColorTextCellOptions = (): TableColorTextCellOptions => ({ @@ -922,6 +924,7 @@ export interface TableColoredBackgroundCellOptions { type: "color-background"; mode?: TableCellBackgroundDisplayMode; applyToRow?: boolean; + wrapText?: boolean; } export const defaultTableColoredBackgroundCellOptions = (): TableColoredBackgroundCellOptions => ({ @@ -933,6 +936,7 @@ export enum TableCellHeight { Sm = "sm", Md = "md", Lg = "lg", + Auto = "auto", } export const defaultTableCellHeight = (): TableCellHeight => (TableCellHeight.Sm); diff --git a/typescript/src/heatmap/panelBuilder.gen.ts b/typescript/src/heatmap/panelBuilder.gen.ts index b291b75..cf8608d 100644 --- a/typescript/src/heatmap/panelBuilder.gen.ts +++ b/typescript/src/heatmap/panelBuilder.gen.ts @@ -569,6 +569,15 @@ export class PanelBuilder implements cog.Builder { return this; } + // Controls which axis to allow selection on + selectionMode(selectionMode: heatmap.HeatmapSelectionMode): this { + if (!this.internal.options) { + this.internal.options = heatmap.defaultOptions(); + } + this.internal.options.selectionMode = selectionMode; + return this; + } + scaleDistribution(scaleDistribution: cog.Builder): this { if (!this.internal.fieldConfig) { this.internal.fieldConfig = dashboard.defaultFieldConfigSource(); diff --git a/typescript/src/heatmap/types.gen.ts b/typescript/src/heatmap/types.gen.ts index a6c60a0..ab349e5 100644 --- a/typescript/src/heatmap/types.gen.ts +++ b/typescript/src/heatmap/types.gen.ts @@ -19,6 +19,15 @@ export enum HeatmapColorScale { export const defaultHeatmapColorScale = (): HeatmapColorScale => (HeatmapColorScale.Linear); +// Controls which axis to allow selection on +export enum HeatmapSelectionMode { + X = "x", + Y = "y", + Xy = "xy", +} + +export const defaultHeatmapSelectionMode = (): HeatmapSelectionMode => (HeatmapSelectionMode.X); + // Controls various color options export interface HeatmapColorOptions { // Sets the color mode @@ -178,6 +187,8 @@ export interface Options { tooltip: HeatmapTooltip; // Controls exemplar options exemplars: ExemplarConfig; + // Controls which axis to allow selection on + selectionMode?: HeatmapSelectionMode; } export const defaultOptions = (): Options => ({ @@ -190,6 +201,7 @@ export const defaultOptions = (): Options => ({ legend: { show: true, }, tooltip: defaultHeatmapTooltip(), exemplars: { color: "rgba(255,0,255,0.7)", }, + selectionMode: HeatmapSelectionMode.X, }); export interface FieldConfig { ```