From 42751af62a412ccbb68401ccf36771c5f94d3140 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20Baung=C3=A5rd=20Hansen?= Date: Wed, 4 Sep 2024 11:17:08 +0200 Subject: [PATCH] Tests: Query grafana datasource via UID (#1553) * Tests: Query grafana datasource via UID Set UID of datasources manually and use that UID to query using tests. The older API is deprecated and soon to be removed. Signed-off-by: Jacob Baungard Hansen * Also set Grafana datasource UID for kind tests The kind tests uses a different than normal Grafana deployment, and as such this config needed to be changed to include a UID as well. Signed-off-by: Jacob Baungard Hansen --------- Signed-off-by: Jacob Baungard Hansen --- .../controllers/multiclusterobservability/grafana.go | 3 +++ tests/pkg/utils/mco_metric.go | 2 +- tests/run-in-kind/grafana/grafana-datasources-test.yaml | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/operators/multiclusterobservability/controllers/multiclusterobservability/grafana.go b/operators/multiclusterobservability/controllers/multiclusterobservability/grafana.go index 75eb768cf2..13551e9ffc 100644 --- a/operators/multiclusterobservability/controllers/multiclusterobservability/grafana.go +++ b/operators/multiclusterobservability/controllers/multiclusterobservability/grafana.go @@ -54,6 +54,7 @@ type GrafanaDatasource struct { Type string `yaml:"type,omitempty"` URL string `yaml:"url,omitempty"` Version int `yaml:"version,omitempty"` + UID string `yaml:"uid,omitempty"` JSONData *JsonData `yaml:"jsonData,omitempty"` SecureJSONData *SecureJsonData `yaml:"secureJsonData,omitempty"` } @@ -101,6 +102,7 @@ func GenerateGrafanaDataSource( config.ProxyServiceName, config.GetDefaultNamespace(), ), + UID: "000000001", JSONData: &JsonData{ Timeout: "300", CustomQueryParameters: "max_source_resolution=auto", @@ -118,6 +120,7 @@ func GenerateGrafanaDataSource( config.ProxyServiceName, config.GetDefaultNamespace(), ), + UID: "000000002", JSONData: &JsonData{ Timeout: "300", CustomQueryParameters: "max_source_resolution=auto", diff --git a/tests/pkg/utils/mco_metric.go b/tests/pkg/utils/mco_metric.go index 05723eb052..763671a08a 100644 --- a/tests/pkg/utils/mco_metric.go +++ b/tests/pkg/utils/mco_metric.go @@ -60,7 +60,7 @@ func (r GrafanaResponse) String() string { func QueryGrafana(opt TestOptions, query string) (*GrafanaResponse, error) { grafanaConsoleURL := GetGrafanaURL(opt) - path := "/api/datasources/proxy/1/api/v1/query?" + path := "/api/datasources/proxy/uid/000000001/api/v1/query?" queryParams := url.PathEscape(fmt.Sprintf("query=%s", query)) req, err := http.NewRequest( "GET", diff --git a/tests/run-in-kind/grafana/grafana-datasources-test.yaml b/tests/run-in-kind/grafana/grafana-datasources-test.yaml index eb24499823..d1f37bb83b 100644 --- a/tests/run-in-kind/grafana/grafana-datasources-test.yaml +++ b/tests/run-in-kind/grafana/grafana-datasources-test.yaml @@ -16,6 +16,7 @@ stringData: version: 0 jsonData: null secureJsonData: null + uid: "000000001" kind: Secret metadata: name: grafana-datasources-test