grafana / cog

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

Use constructor functions to create struct fields #437

Closed K-Phoen closed 5 months ago

K-Phoen commented 5 months ago

To ensure that struct fields are created in a consistent way.

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/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/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/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/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/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/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..5997c22 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 geomap +from ..models import logs from ..models import nodegraph -from ..models import cloudwatch -from ..models import text from ..models import timeseries +from ..models import bargauge +from ..models import xychart +from ..models import statushistory +from ..models import azuremonitor +from ..models import barchart +from ..models import gauge +from ..models import news +from ..models import text +from ..models import trend +from ..models import expr +from ..models import loki from ..models import canvas +from ..models import dashboardlist +from ..models import elasticsearch from ..models import googlecloudmonitoring -from ..models import loki -from ..models import trend -from ..models import statushistory -from ..models import prometheus -from ..models import annotationslist +from ..models import grafanapyroscope from ..models import statetimeline -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 piechart -from ..models import xychart -from ..models import geomap -from ..models import news +from ..models import cloudwatch +from ..models import prometheus +from ..models import annotationslist +from ..models import datagrid +from ..models import debug +from ..models import heatmap from ..models import parca +from ..models import stat +from ..models import histogram from ..models import table +from ..models import tempo 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/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/grafana_foundation_sdk/models/rolebinding.py b/python/grafana_foundation_sdk/models/rolebinding.py index e8f302c..eafa911 100644 --- a/python/grafana_foundation_sdk/models/rolebinding.py +++ b/python/grafana_foundation_sdk/models/rolebinding.py @@ -25,7 +25,7 @@ class RoleBinding: args: dict[str, typing.Any] = {} if "role" in data: - decoding_map: dict[str, typing.Union[typing.Type[BuiltinRoleRef], typing.Type[CustomRoleRef]]] = {"BuiltinRole": BuiltinRoleRef, "Role": CustomRoleRef} + decoding_map: dict[str, typing.Union[typing.Type[CustomRoleRef], typing.Type[BuiltinRoleRef]]] = {"Role": CustomRoleRef, "BuiltinRole": BuiltinRoleRef} args["role"] = decoding_map[data["role"]["kind"]].from_json(data["role"]) if "subject" in data: args["subject"] = RoleBindingSubject.from_json(data["subject"]) diff --git a/python/pyproject.toml b/python/pyproject.toml index 7b9c1fb..d4b323c 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -13,7 +13,7 @@ keywords = [ "traces", "metrics" ] -version = "1717501769!next" +version = "1717759410!next" dependencies = [] requires-python = ">=3.11" classifiers = [ diff --git a/typescript/package.json b/typescript/package.json index 763fd20..6e20fbe 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.1717759410", "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/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 { ```