Skip to content

Commit

Permalink
Tests: Query grafana datasource via UID (#1553)
Browse files Browse the repository at this point in the history
* 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 <jacobbaungard@redhat.com>

* 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 <jacobbaungard@redhat.com>

---------

Signed-off-by: Jacob Baungard Hansen <jacobbaungard@redhat.com>
  • Loading branch information
jacobbaungard authored Sep 4, 2024
1 parent 61ae82f commit 578db6d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down Expand Up @@ -101,6 +102,7 @@ func GenerateGrafanaDataSource(
config.ProxyServiceName,
config.GetDefaultNamespace(),
),
UID: "000000001",
JSONData: &JsonData{
Timeout: "300",
CustomQueryParameters: "max_source_resolution=auto",
Expand All @@ -118,6 +120,7 @@ func GenerateGrafanaDataSource(
config.ProxyServiceName,
config.GetDefaultNamespace(),
),
UID: "000000002",
JSONData: &JsonData{
Timeout: "300",
CustomQueryParameters: "max_source_resolution=auto",
Expand Down
2 changes: 1 addition & 1 deletion tests/pkg/utils/mco_metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions tests/run-in-kind/grafana/grafana-datasources-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ stringData:
version: 0
jsonData: null
secureJsonData: null
uid: "000000001"
kind: Secret
metadata:
name: grafana-datasources-test
Expand Down

0 comments on commit 578db6d

Please sign in to comment.