CloudWatch: Allow use of missing AWS namespaces using custom metrics (#30961)

* add tests

* CloudWatch: Allow use of missing AWS namespaces using custom metrics

* CloudWatch: Allow use of missing AWS namespaces using custom metrics
This commit is contained in:
Matthew Coltman 2021-05-17 07:32:32 +02:00 committed by GitHub
parent 65cacd31c2
commit bc21adf712
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 1 deletions

View File

@ -813,5 +813,8 @@ func isDuplicate(nameList []string, target string) bool {
}
func isCustomMetrics(namespace string) bool {
return strings.Index(namespace, "AWS/") != 0
if _, ok := metricsMap[namespace]; ok {
return false
}
return true
}

View File

@ -465,6 +465,49 @@ func TestQuery_ResourceARNs(t *testing.T) {
})
}
func Test_isCustomMetrics(t *testing.T) {
metricsMap = map[string][]string{
"AWS/EC2": {"ExampleMetric"},
}
type args struct {
namespace string
}
tests := []struct {
name string
args args
want bool
}{
{name: "A custom metric should return true",
want: true,
args: args{
namespace: "Custom/MyApp",
},
},
{name: "An AWS metric not included in this package should return true",
want: true,
args: args{
namespace: "AWS/MyApp",
},
},
{name: "An AWS metric included in this package should return false",
want: false,
args: args{
namespace: "AWS/EC2",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := isCustomMetrics(tt.args.namespace); got != tt.want {
t.Errorf("isCustomMetrics() = %v, want %v", got, tt.want)
}
})
}
}
func TestQuery_ListMetricsPagination(t *testing.T) {
origNewCWClient := NewCWClient
t.Cleanup(func() {