grafana / cog

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

Language/php examples #486

Closed K-Phoen closed 3 months ago

K-Phoen commented 3 months ago

This PR provides a better example for PHP dashboard builders, and runs it in the CI. A few tiny fixes were also needed along the way.

Contributes to #470

github-actions[bot] commented 3 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/query_builder_gen.go b/go/alerting/query_builder_gen.go index 94b524f..e2d3513 100644 --- a/go/alerting/query_builder_gen.go +++ b/go/alerting/query_builder_gen.go @@ -75,9 +75,6 @@ func (builder *QueryBuilder) RelativeTimeRange(from Duration, to Duration) *Quer builder.internal.RelativeTimeRange = &RelativeTimeRange{} } builder.internal.RelativeTimeRange.From = &from - if builder.internal.RelativeTimeRange == nil { - builder.internal.RelativeTimeRange = &RelativeTimeRange{} - } builder.internal.RelativeTimeRange.To = &to return builder diff --git a/go/dashboard/dashboard_builder_gen.go b/go/dashboard/dashboard_builder_gen.go index cebab62..284a7ae 100644 --- a/go/dashboard/dashboard_builder_gen.go +++ b/go/dashboard/dashboard_builder_gen.go @@ -137,12 +137,6 @@ func (builder *DashboardBuilder) Time(from string, to string) *DashboardBuilder }{} } builder.internal.Time.From = from - if builder.internal.Time == nil { - builder.internal.Time = &struct { - From string `json:"from"` - To string `json:"to"` - }{} - } builder.internal.Time.To = to return builder diff --git a/jsonschema/azuremonitor.jsonschema.json b/jsonschema/azuremonitor.jsonschema.json index 983c6d1..7a9da51 100644 --- a/jsonschema/azuremonitor.jsonschema.json +++ b/jsonschema/azuremonitor.jsonschema.json @@ -1,5 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/AzureMonitorQuery", "definitions": { "AzureMonitorQuery": { "type": "object", diff --git a/jsonschema/cloudwatch.jsonschema.json b/jsonschema/cloudwatch.jsonschema.json index 996b5ee..e8cd42e 100644 --- a/jsonschema/cloudwatch.jsonschema.json +++ b/jsonschema/cloudwatch.jsonschema.json @@ -1,5 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/CloudWatchQuery", "definitions": { "MetricStat": { "type": "object", diff --git a/jsonschema/elasticsearch.jsonschema.json b/jsonschema/elasticsearch.jsonschema.json index f80edcc..08b5c6f 100644 --- a/jsonschema/elasticsearch.jsonschema.json +++ b/jsonschema/elasticsearch.jsonschema.json @@ -1,5 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/dataquery", "definitions": { "BucketAggregation": { "anyOf": [ diff --git a/jsonschema/googlecloudmonitoring.jsonschema.json b/jsonschema/googlecloudmonitoring.jsonschema.json index c129a4b..8693f61 100644 --- a/jsonschema/googlecloudmonitoring.jsonschema.json +++ b/jsonschema/googlecloudmonitoring.jsonschema.json @@ -1,5 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/CloudMonitoringQuery", "definitions": { "CloudMonitoringQuery": { "type": "object", diff --git a/jsonschema/grafanapyroscope.jsonschema.json b/jsonschema/grafanapyroscope.jsonschema.json index d16c059..80c67c0 100644 --- a/jsonschema/grafanapyroscope.jsonschema.json +++ b/jsonschema/grafanapyroscope.jsonschema.json @@ -1,5 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/dataquery", "definitions": { "PyroscopeQueryType": { "enum": [ diff --git a/jsonschema/loki.jsonschema.json b/jsonschema/loki.jsonschema.json index 9b5e7d4..c9d5185 100644 --- a/jsonschema/loki.jsonschema.json +++ b/jsonschema/loki.jsonschema.json @@ -1,5 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/dataquery", "definitions": { "QueryEditorMode": { "enum": [ diff --git a/jsonschema/parca.jsonschema.json b/jsonschema/parca.jsonschema.json index c1235f5..6901bf8 100644 --- a/jsonschema/parca.jsonschema.json +++ b/jsonschema/parca.jsonschema.json @@ -1,5 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/dataquery", "definitions": { "ParcaQueryType": { "enum": [ diff --git a/jsonschema/prometheus.jsonschema.json b/jsonschema/prometheus.jsonschema.json index cd6e9ce..fde9f58 100644 --- a/jsonschema/prometheus.jsonschema.json +++ b/jsonschema/prometheus.jsonschema.json @@ -1,5 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/dataquery", "definitions": { "QueryEditorMode": { "enum": [ diff --git a/jsonschema/tempo.jsonschema.json b/jsonschema/tempo.jsonschema.json index de1fabf..744d96e 100644 --- a/jsonschema/tempo.jsonschema.json +++ b/jsonschema/tempo.jsonschema.json @@ -1,5 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/TempoQuery", "definitions": { "TempoQuery": { "type": "object", diff --git a/jsonschema/testdata.jsonschema.json b/jsonschema/testdata.jsonschema.json index 61a92bf..66fdf2c 100644 --- a/jsonschema/testdata.jsonschema.json +++ b/jsonschema/testdata.jsonschema.json @@ -1,5 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/testdata", "definitions": { "CSVWave": { "type": "object", diff --git a/python/grafana_foundation_sdk/builders/dashboard.py b/python/grafana_foundation_sdk/builders/dashboard.py index 72f976d..7d04fe8 100644 --- a/python/grafana_foundation_sdk/builders/dashboard.py +++ b/python/grafana_foundation_sdk/builders/dashboard.py @@ -131,9 +131,6 @@ class Dashboard(cogbuilder.Builder[dashboard.Dashboard]): self._internal.time = dashboard.DashboardDashboardTime() assert isinstance(self._internal.time, dashboard.DashboardDashboardTime) self._internal.time.from_val = from_val - if self._internal.time is None: - self._internal.time = dashboard.DashboardDashboardTime() - assert isinstance(self._internal.time, dashboard.DashboardDashboardTime) self._internal.time.to = to return self diff --git a/python/grafana_foundation_sdk/cog/plugins.py b/python/grafana_foundation_sdk/cog/plugins.py index 1a2e2d0..7c39963 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 googlecloudmonitoring -from ..models import nodegraph -from ..models import tempo -from ..models import text +from ..models import prometheus +from ..models import annotationslist from ..models import cloudwatch +from ..models import gauge +from ..models import statushistory +from ..models import xychart from ..models import dashboardlist -from ..models import parca +from ..models import googlecloudmonitoring from ..models import table -from ..models import barchart -from ..models import statushistory -from ..models import timeseries +from ..models import candlestick +from ..models import debug +from ..models import news from ..models import stat -from ..models import gauge -from ..models import heatmap -from ..models import xychart -from ..models import azuremonitor -from ..models import annotationslist -from ..models import bargauge -from ..models import elasticsearch +from ..models import statetimeline +from ..models import canvas +from ..models import datagrid from ..models import geomap -from ..models import histogram +from ..models import heatmap from ..models import logs -from ..models import candlestick +from ..models import expr from ..models import grafanapyroscope -from ..models import news +from ..models import nodegraph from ..models import piechart -from ..models import expr -from ..models import datagrid -from ..models import debug +from ..models import azuremonitor +from ..models import elasticsearch +from ..models import text from ..models import loki -from ..models import statetimeline +from ..models import timeseries from ..models import trend -from ..models import prometheus -from ..models import canvas +from ..models import barchart +from ..models import bargauge +from ..models import histogram +from ..models import parca +from ..models import tempo from . import runtime as cogruntime diff --git a/python/grafana_foundation_sdk/models/cloudwatch.py b/python/grafana_foundation_sdk/models/cloudwatch.py index 68ad69b..761fcb8 100644 --- a/python/grafana_foundation_sdk/models/cloudwatch.py +++ b/python/grafana_foundation_sdk/models/cloudwatch.py @@ -332,7 +332,7 @@ class SQLExpression: if "select" in data: args["select"] = QueryEditorFunctionExpression.from_json(data["select"]) if "from" in data: - decoding_map: dict[str, typing.Union[typing.Type[QueryEditorFunctionExpression], typing.Type[QueryEditorPropertyExpression]]] = {"function": QueryEditorFunctionExpression, "property": QueryEditorPropertyExpression} + decoding_map: dict[str, typing.Union[typing.Type[QueryEditorPropertyExpression], typing.Type[QueryEditorFunctionExpression]]] = {"property": QueryEditorPropertyExpression, "function": QueryEditorFunctionExpression} args["from_val"] = decoding_map[data["from"]["type"]].from_json(data["from"]) if "where" in data: args["where"] = QueryEditorArrayExpression.from_json(data["where"]) diff --git a/python/pyproject.toml b/python/pyproject.toml index 6382073..1bb9724 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -13,7 +13,7 @@ keywords = [ "traces", "metrics" ] -version = "1719238427!next" +version = "1719307464!next" dependencies = [] requires-python = ">=3.11" classifiers = [ diff --git a/typescript/package.json b/typescript/package.json index 20699cd..b1e3b37 100644 --- a/typescript/package.json +++ b/typescript/package.json @@ -1,6 +1,6 @@ { "name": "@grafana/grafana-foundation-sdk", - "version": "next-cogv0.0.x.1719238427", + "version": "next-cogv0.0.x.1719307464", "description": "A set of tools, types and libraries for building and manipulating Grafana objects.", "keywords": [ "observability", ```
K-Phoen commented 3 months ago

You fixed a pending issue with the safe guards too :)

Did I? :sweat_smile: