mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
parent
65cacd31c2
commit
bc21adf712
@ -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
|
||||
}
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user