@@ -179,11 +179,14 @@ var _ = framework.KubeDescribe("PodSandbox", func() {
179179
180180 Expect (err ).ToNot (HaveOccurred ())
181181
182+ By ("list metric descriptors" )
183+ descs := listMetricDescriptors (rc )
184+
182185 By ("list pod sandbox metrics" )
183186 metrics := listPodSandboxMetrics (rc )
184187
185188 By ("verify pod metrics are present" )
186- testPodSandboxMetrics (metrics , podID )
189+ testPodSandboxMetrics (metrics , descs , podID )
187190 })
188191 })
189192})
@@ -347,7 +350,7 @@ func listPodSandboxMetrics(c internalapi.RuntimeService) []*runtimeapi.PodSandbo
347350}
348351
349352// testPodSandboxMetrics verifies that metrics are present for the specified pod.
350- func testPodSandboxMetrics (allMetrics []* runtimeapi.PodSandboxMetrics , podID string ) {
353+ func testPodSandboxMetrics (allMetrics []* runtimeapi.PodSandboxMetrics , descs [] * runtimeapi. MetricDescriptor , podID string ) {
351354 var podMetrics * runtimeapi.PodSandboxMetrics
352355
353356 for _ , m := range allMetrics {
@@ -360,29 +363,39 @@ func testPodSandboxMetrics(allMetrics []*runtimeapi.PodSandboxMetrics, podID str
360363
361364 Expect (podMetrics ).NotTo (BeNil (), "Metrics for pod %q should be present" , podID )
362365
363- metricNamesFound := make (map [string ]bool )
366+ metricNamesFound := make (map [string ][] string )
364367
365368 for _ , metric := range podMetrics .GetMetrics () {
366- if ! metricNamesFound [metric .GetName ()] {
367- metricNamesFound [metric .GetName ()] = true
369+ if len ( metricNamesFound [metric .GetName ()]) == 0 {
370+ metricNamesFound [metric .GetName ()] = metric . GetLabelValues ()
368371 }
369372 }
370373
371374 for _ , containerMetric := range podMetrics .GetContainerMetrics () {
372375 for _ , metric := range containerMetric .GetMetrics () {
373- if ! metricNamesFound [metric .GetName ()] {
374- metricNamesFound [metric .GetName ()] = true
376+ if len ( metricNamesFound [metric .GetName ()]) == 0 {
377+ metricNamesFound [metric .GetName ()] = metric . GetLabelValues ()
375378 }
376379 }
377380 }
378381
379382 missingMetrics := []string {}
380383
381384 for _ , expectedName := range expectedMetricDescriptorNames {
382- if ! metricNamesFound [expectedName ] {
385+ if len ( metricNamesFound [expectedName ]) == 0 {
383386 missingMetrics = append (missingMetrics , expectedName )
384387 }
385388 }
386389
387390 Expect (missingMetrics ).To (BeEmpty (), "Expected %s metrics to be present and they were not" , strings .Join (missingMetrics , " " ))
391+
392+ mismatchedLabels := []string {}
393+ for _ , desc := range descs {
394+ if len (metricNamesFound [desc .GetName ()]) != len (desc .GetLabelKeys ()) {
395+ mismatchedLabels = append (mismatchedLabels , desc .GetName ())
396+ }
397+ }
398+
399+ Expect (mismatchedLabels ).To (BeEmpty (), "Expected %s metrics to have same set of labels in ListMetricDescriptors and ListPodSandboxMetrics" , strings .Join (mismatchedLabels , "," ))
400+
388401}
0 commit comments