From cdcd77d5f23c11352b28a62ea1eb1b53ed803c54 Mon Sep 17 00:00:00 2001 From: Celian GARCIA Date: Thu, 20 Aug 2026 17:09:31 +0200 Subject: [PATCH] [BUGFIX] migration of datasource selector when it's a datasource var ref Signed-off-by: Celian GARCIA --- .../migrate/migrate.cue | 13 ++++++++++--- .../migrate/tests/legend-format/expected.json | 5 +---- .../schemas/prometheus-time-series-query/query.cue | 2 -- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/prometheus/schemas/prometheus-time-series-query/migrate/migrate.cue b/prometheus/schemas/prometheus-time-series-query/migrate/migrate.cue index 68a7e2229..86b0a1b16 100644 --- a/prometheus/schemas/prometheus-time-series-query/migrate/migrate.cue +++ b/prometheus/schemas/prometheus-time-series-query/migrate/migrate.cue @@ -13,6 +13,8 @@ package migrate +import "github.com/perses/shared/cue/common" + #target: { datasource?: { type?: "prometheus" @@ -31,9 +33,14 @@ package migrate kind: "PrometheusTimeSeriesQuery" spec: { if #target.datasource != _|_ { - datasource: { - kind: "PrometheusDatasource" - name: #target.datasource.uid + if #target.datasource.uid =~ common.#variableSyntaxRegex { + datasource: #target.datasource.uid + } + if #target.datasource.uid !~ common.#variableSyntaxRegex { + datasource: { + kind: "PrometheusDatasource" + name: #target.datasource.uid + } } } query: #target.expr diff --git a/prometheus/schemas/prometheus-time-series-query/migrate/tests/legend-format/expected.json b/prometheus/schemas/prometheus-time-series-query/migrate/tests/legend-format/expected.json index d57f0ba29..f804b4b50 100644 --- a/prometheus/schemas/prometheus-time-series-query/migrate/tests/legend-format/expected.json +++ b/prometheus/schemas/prometheus-time-series-query/migrate/tests/legend-format/expected.json @@ -1,10 +1,7 @@ { "kind": "PrometheusTimeSeriesQuery", "spec": { - "datasource": { - "kind": "PrometheusDatasource", - "name": "${datasource}" - }, + "datasource": "${datasource}", "minStep": "", "query": "avg without (instance) (hadoop_hdfs_datanode_capacity{bar_stack_id=\"$bar_stack_id\", _target=~\"$datanode\"})", "seriesNameFormat": "{{_target}}" diff --git a/prometheus/schemas/prometheus-time-series-query/query.cue b/prometheus/schemas/prometheus-time-series-query/query.cue index 13efd1b49..53c61c447 100644 --- a/prometheus/schemas/prometheus-time-series-query/query.cue +++ b/prometheus/schemas/prometheus-time-series-query/query.cue @@ -27,5 +27,3 @@ spec: close({ minStep?: =~ds.#durationRegex | =~common.#variableSyntaxRegex resolution?: number }) - -#variableSyntaxRegex: "^\\$\\w+$"