Cloudwatch: Refactor metrics resource request (#57424)

* refactor metrics request

* Update pkg/tsdb/cloudwatch/routes/dimension_keys_test.go

Co-authored-by: Shirley <4163034+fridgepoet@users.noreply.github.com>

* return metric struct value intead of pointer

* make it possible to test hard coded metrics service

* test all paths in route

* fix broken test

* fix one more broken test

* add integration test

Co-authored-by: Shirley <4163034+fridgepoet@users.noreply.github.com>
This commit is contained in:
Erik Sundell
2022-10-25 14:00:54 +02:00
committed by GitHub
co-authored by Shirley
parent 53d7404e2b
commit 4c654ddb76
21 changed files with 458 additions and 91 deletions
@@ -0,0 +1,43 @@
package services
import (
"fmt"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/constants"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/models"
)
var GetHardCodedDimensionKeysByNamespace = func(namespace string) ([]string, error) {
var dimensionKeys []string
exists := false
if dimensionKeys, exists = constants.NamespaceDimensionKeysMap[namespace]; !exists {
return nil, fmt.Errorf("unable to find dimensions for namespace '%q'", namespace)
}
return dimensionKeys, nil
}
var GetHardCodedMetricsByNamespace = func(namespace string) ([]models.Metric, error) {
response := []models.Metric{}
exists := false
var metrics []string
if metrics, exists = constants.NamespaceMetricsMap[namespace]; !exists {
return nil, fmt.Errorf("unable to find metrics for namespace '%q'", namespace)
}
for _, metric := range metrics {
response = append(response, models.Metric{Namespace: namespace, Name: metric})
}
return response, nil
}
var GetAllHardCodedMetrics = func() []models.Metric {
response := []models.Metric{}
for namespace, metrics := range constants.NamespaceMetricsMap {
for _, metric := range metrics {
response = append(response, models.Metric{Namespace: namespace, Name: metric})
}
}
return response
}