diff --git a/test/e2e/instrumentation/monitoring/custom_metrics_stackdriver.go b/test/e2e/instrumentation/monitoring/custom_metrics_stackdriver.go index 66de22c42ae..d4116da70a5 100644 --- a/test/e2e/instrumentation/monitoring/custom_metrics_stackdriver.go +++ b/test/e2e/instrumentation/monitoring/custom_metrics_stackdriver.go @@ -175,20 +175,10 @@ func verifyResponsesFromCustomMetricsAPI(f *framework.Framework, customMetricsCl if err != nil { framework.Failf("Failed to retrieve a list of supported metrics: %s", err) } - gotCustomMetric, gotUnusedMetric := false, false - for _, resource := range resources.APIResources { - if resource.Name == "*/"+CustomMetricName { - gotCustomMetric = true - } else if resource.Name == "*/"+UnusedMetricName { - gotUnusedMetric = true - } else { - framework.Failf("Unexpected metric %s. Only metric %s should be supported", resource.Name, CustomMetricName) - } - } - if !gotCustomMetric { + if !containsResource(resources.APIResources, "*/custom.googleapis.com|"+CustomMetricName) { framework.Failf("Metric '%s' expected but not received", CustomMetricName) } - if !gotUnusedMetric { + if !containsResource(resources.APIResources, "*/custom.googleapis.com|"+UnusedMetricName) { framework.Failf("Metric '%s' expected but not received", UnusedMetricName) } value, err := customMetricsClient.NamespacedMetrics(f.Namespace.Name).GetForObject(schema.GroupKind{Group: "", Kind: "Pod"}, stackdriverExporterPod1, CustomMetricName) @@ -214,6 +204,15 @@ func verifyResponsesFromCustomMetricsAPI(f *framework.Framework, customMetricsCl } } +func containsResource(resourcesList []metav1.APIResource, resourceName string) bool { + for _, resource := range resourcesList { + if resource.Name == resourceName { + return true + } + } + return false +} + func verifyResponseFromExternalMetricsAPI(f *framework.Framework, externalMetricsClient externalclient.ExternalMetricsClient, pod *v1.Pod) { req1, _ := labels.NewRequirement("resource.type", selection.Equals, []string{"gke_container"}) // It's important to filter out only metrics from the right namespace, since multiple e2e tests