From 133daabf9f41400d2eeb7d34ad0c1a1c92e46992 Mon Sep 17 00:00:00 2001 From: Ross <ross.rhodes@krakenflex.com> Date: Wed, 19 Mar 2025 20:09:31 +0000 Subject: [PATCH 1/3] test: namespace metrics and dimensions have same key set --- pkg/cloudWatchConsts/metrics_test.go | 48 ++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/pkg/cloudWatchConsts/metrics_test.go b/pkg/cloudWatchConsts/metrics_test.go index 08d4d8b..ad43f93 100644 --- a/pkg/cloudWatchConsts/metrics_test.go +++ b/pkg/cloudWatchConsts/metrics_test.go @@ -2,15 +2,17 @@ package cloudWatchConsts import ( "fmt" + "maps" "slices" "sort" + "strings" "testing" "github.com/stretchr/testify/assert" ) -// test to check NamespaceMetricsMap is sorted alphabetically -func TestNamespaceMetricsMap(t *testing.T) { +// test to check NamespaceMetricsMap metrics are sorted alphabetically +func TestNamespaceMetricsAlphabetized(t *testing.T) { unsortedMetricNamespaces := namespacesWithUnsortedMetrics(NamespaceMetricsMap) if len(unsortedMetricNamespaces) != 0 { assert.Fail(t, "NamespaceMetricsMap is not sorted alphabetically. Please replace the printed services") @@ -18,6 +20,30 @@ func TestNamespaceMetricsMap(t *testing.T) { } } +func TestNamespaceMetricKeysAllHaveDimensions(t *testing.T) { + namespaceMetricsKeys := slices.Collect(maps.Keys(NamespaceMetricsMap)) + namespaceDimensionKeys := slices.Collect(maps.Keys(NamespaceDimensionKeysMap)) + + namespaceMetricsMissingKeys := findMetricKeysFromAMissingInB(namespaceDimensionKeys, namespaceMetricsKeys) + + if len(namespaceMetricsMissingKeys) != 0 { + assert.Fail(t, fmt.Sprintf("NamespaceMetricsMap is missing key(s) from NamespaceDimensionKeysMap.")) + fmt.Println(strings.Join(namespaceMetricsMissingKeys, "\n")) + } +} + +func TestNamespaceDimensionKeysAllHaveMetrics(t *testing.T) { + namespaceMetricsKeys := slices.Collect(maps.Keys(NamespaceMetricsMap)) + namespaceDimensionKeys := slices.Collect(maps.Keys(NamespaceDimensionKeysMap)) + + namespaceDimensionMissingKeys := findMetricKeysFromAMissingInB(namespaceMetricsKeys, namespaceDimensionKeys) + + if len(namespaceDimensionMissingKeys) != 0 { + assert.Fail(t, fmt.Sprintf("NamespaceDimensionKeysMap is missing key(s) from NamespaceMetricsMap.")) + fmt.Println(strings.Join(namespaceDimensionMissingKeys, "\n")) + } +} + func printNamespacesThatNeedSorted(unsortedMetricNamespaces []string) { slices.Sort(unsortedMetricNamespaces) @@ -37,10 +63,8 @@ func printNamespacesThatNeedSorted(unsortedMetricNamespaces []string) { // namespacesWithUnsortedMetrics returns which namespaces have unsorted metrics func namespacesWithUnsortedMetrics(NamespaceMetricsMap map[string][]string) []string { // Extract keys from the map and sort them - keys := make([]string, 0, len(NamespaceMetricsMap)) - for k := range NamespaceMetricsMap { - keys = append(keys, k) - } + keys := slices.Collect(maps.Keys(NamespaceMetricsMap)) + sort.Strings(keys) var unsortedNamespace []string @@ -62,3 +86,15 @@ func namespacesWithUnsortedMetrics(NamespaceMetricsMap map[string][]string) []st return unsortedNamespace } + +func findMetricKeysFromAMissingInB(a []string, b []string) []string { + var missingKeys []string + + for i := range a { + if !slices.Contains(b, a[i]) { + missingKeys = append(missingKeys, a[i]) + } + } + + return missingKeys +} From bbadff83510ff7df15b2dbff6a583611ce141999 Mon Sep 17 00:00:00 2001 From: Ross <ross.rhodes@krakenflex.com> Date: Wed, 19 Mar 2025 20:09:48 +0000 Subject: [PATCH 2/3] fix: add missing keys to dimensions --- pkg/cloudWatchConsts/metrics.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/cloudWatchConsts/metrics.go b/pkg/cloudWatchConsts/metrics.go index 55d0805..068f076 100644 --- a/pkg/cloudWatchConsts/metrics.go +++ b/pkg/cloudWatchConsts/metrics.go @@ -3330,6 +3330,7 @@ var NamespaceDimensionKeysMap = map[string][]string{ "AWS/ElasticMapReduce": {"ClusterId", "JobFlowId", "JobId"}, "AWS/EMRServerless": {"ApplicationId", "WorkerType", "CapacityAllocationType"}, "AWS/ElasticTranscoder": {"Operation", "PipelineId"}, + "AWS/EventBridge/Pipes": {}, "AWS/Events": {"EventBusName", "EventSourceName", "RuleName"}, "AWS/FSx": {"FileSystemId"}, "AWS/Firehose": {"DeliveryStreamName"}, @@ -3345,6 +3346,7 @@ var NamespaceDimensionKeysMap = map[string][]string{ "AWS/IoTSiteWise": {"AccountId", "GatewayId", "PropertyGroup", "Reason", "SourceName", "StreamName", "ThrottledAt"}, "AWS/KMS": {"KeyId"}, "AWS/Kafka": {"Broker ID", "Cluster Name", "Consumer Group", "Topic"}, + "AWS/KafkaConnect": {}, "AWS/Kendra": {"DataSourceId", "IndexId"}, "AWS/Kinesis": {"ShardId", "StreamName"}, "AWS/KinesisAnalytics": {"Application", "Flow", "Id", "Operator", "Parallelism", "Task"}, From 0c30c097a72b7147247de8c050ccd117f8f25952 Mon Sep 17 00:00:00 2001 From: Ross <ross.rhodes@krakenflex.com> Date: Thu, 20 Mar 2025 16:28:45 +0000 Subject: [PATCH 3/3] chore: remove redundant string format --- pkg/cloudWatchConsts/metrics_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/cloudWatchConsts/metrics_test.go b/pkg/cloudWatchConsts/metrics_test.go index ad43f93..cd5e9b4 100644 --- a/pkg/cloudWatchConsts/metrics_test.go +++ b/pkg/cloudWatchConsts/metrics_test.go @@ -27,7 +27,7 @@ func TestNamespaceMetricKeysAllHaveDimensions(t *testing.T) { namespaceMetricsMissingKeys := findMetricKeysFromAMissingInB(namespaceDimensionKeys, namespaceMetricsKeys) if len(namespaceMetricsMissingKeys) != 0 { - assert.Fail(t, fmt.Sprintf("NamespaceMetricsMap is missing key(s) from NamespaceDimensionKeysMap.")) + assert.Fail(t, "NamespaceMetricsMap is missing key(s) from NamespaceDimensionKeysMap.") fmt.Println(strings.Join(namespaceMetricsMissingKeys, "\n")) } } @@ -39,7 +39,7 @@ func TestNamespaceDimensionKeysAllHaveMetrics(t *testing.T) { namespaceDimensionMissingKeys := findMetricKeysFromAMissingInB(namespaceMetricsKeys, namespaceDimensionKeys) if len(namespaceDimensionMissingKeys) != 0 { - assert.Fail(t, fmt.Sprintf("NamespaceDimensionKeysMap is missing key(s) from NamespaceMetricsMap.")) + assert.Fail(t, "NamespaceDimensionKeysMap is missing key(s) from NamespaceMetricsMap.") fmt.Println(strings.Join(namespaceDimensionMissingKeys, "\n")) } }