Skip to content

Commit 036cf78

Browse files
authored
Merge pull request kubernetes#85619 from gnufied/debug-volume-metric-failure
Fix attach/detach metric failure
2 parents e51caab + 59274b5 commit 036cf78

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

test/e2e/storage/volume_metrics.go

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,16 @@ var _ = utils.SIGDescribe("[Serial] Volume metrics", func() {
104104
framework.Skipf("Environment does not support getting controller-manager metrics - skipping")
105105
}
106106

107+
ginkgo.By("Getting plugin name")
108+
defaultClass, err := c.StorageV1().StorageClasses().Get(defaultScName, metav1.GetOptions{})
109+
framework.ExpectNoError(err, "Error getting default storageclass: %v", err)
110+
pluginName := defaultClass.Provisioner
111+
107112
controllerMetrics, err := metricsGrabber.GrabFromControllerManager()
108113

109114
framework.ExpectNoError(err, "Error getting c-m metrics : %v", err)
110115

111-
storageOpMetrics := getControllerStorageMetrics(controllerMetrics)
116+
storageOpMetrics := getControllerStorageMetrics(controllerMetrics, pluginName)
112117

113118
pvc, err = c.CoreV1().PersistentVolumeClaims(pvc.Namespace).Create(pvc)
114119
framework.ExpectNoError(err)
@@ -126,7 +131,7 @@ var _ = utils.SIGDescribe("[Serial] Volume metrics", func() {
126131
framework.Logf("Deleting pod %q/%q", pod.Namespace, pod.Name)
127132
framework.ExpectNoError(e2epod.DeletePodWithWait(c, pod))
128133

129-
updatedStorageMetrics := waitForDetachAndGrabMetrics(storageOpMetrics, metricsGrabber)
134+
updatedStorageMetrics := waitForDetachAndGrabMetrics(storageOpMetrics, metricsGrabber, pluginName)
130135

131136
framework.ExpectNotEqual(len(updatedStorageMetrics.latencyMetrics), 0, "Error fetching c-m updated storage metrics")
132137
framework.ExpectNotEqual(len(updatedStorageMetrics.statusMetrics), 0, "Error fetching c-m updated storage metrics")
@@ -145,15 +150,16 @@ var _ = utils.SIGDescribe("[Serial] Volume metrics", func() {
145150
framework.Skipf("Environment does not support getting controller-manager metrics - skipping")
146151
}
147152

153+
ginkgo.By("Geting default storageclass")
154+
defaultClass, err := c.StorageV1().StorageClasses().Get(defaultScName, metav1.GetOptions{})
155+
framework.ExpectNoError(err, "Error getting default storageclass: %v", err)
156+
pluginName := defaultClass.Provisioner
157+
148158
controllerMetrics, err := metricsGrabber.GrabFromControllerManager()
149159

150160
framework.ExpectNoError(err, "Error getting c-m metrics : %v", err)
151161

152-
storageOpMetrics := getControllerStorageMetrics(controllerMetrics)
153-
154-
ginkgo.By("Creating an invalid storageclass")
155-
defaultClass, err := c.StorageV1().StorageClasses().Get(defaultScName, metav1.GetOptions{})
156-
framework.ExpectNoError(err, "Error getting default storageclass: %v", err)
162+
storageOpMetrics := getControllerStorageMetrics(controllerMetrics, pluginName)
157163

158164
invalidSc = &storagev1.StorageClass{
159165
ObjectMeta: metav1.ObjectMeta{
@@ -188,7 +194,7 @@ var _ = utils.SIGDescribe("[Serial] Volume metrics", func() {
188194
ginkgo.By("Checking failure metrics")
189195
updatedControllerMetrics, err := metricsGrabber.GrabFromControllerManager()
190196
framework.ExpectNoError(err, "failed to get controller manager metrics")
191-
updatedStorageMetrics := getControllerStorageMetrics(updatedControllerMetrics)
197+
updatedStorageMetrics := getControllerStorageMetrics(updatedControllerMetrics, pluginName)
192198

193199
framework.ExpectNotEqual(len(updatedStorageMetrics.statusMetrics), 0, "Error fetching c-m updated storage metrics")
194200
verifyMetricCount(storageOpMetrics, updatedStorageMetrics, "volume_provision", true)
@@ -521,7 +527,7 @@ func newStorageControllerMetrics() *storageControllerMetrics {
521527
}
522528
}
523529

524-
func waitForDetachAndGrabMetrics(oldMetrics *storageControllerMetrics, metricsGrabber *metrics.Grabber) *storageControllerMetrics {
530+
func waitForDetachAndGrabMetrics(oldMetrics *storageControllerMetrics, metricsGrabber *metrics.Grabber, pluginName string) *storageControllerMetrics {
525531
backoff := wait.Backoff{
526532
Duration: 10 * time.Second,
527533
Factor: 1.2,
@@ -542,7 +548,7 @@ func waitForDetachAndGrabMetrics(oldMetrics *storageControllerMetrics, metricsGr
542548
return false, err
543549
}
544550

545-
updatedStorageMetrics = getControllerStorageMetrics(updatedMetrics)
551+
updatedStorageMetrics = getControllerStorageMetrics(updatedMetrics, pluginName)
546552
newDetachCount, ok := updatedStorageMetrics.latencyMetrics["volume_detach"]
547553

548554
// if detach metrics are not yet there, we need to retry
@@ -555,6 +561,7 @@ func waitForDetachAndGrabMetrics(oldMetrics *storageControllerMetrics, metricsGr
555561
if oldDetachCount >= newDetachCount {
556562
return false, nil
557563
}
564+
558565
return true, nil
559566
}
560567

@@ -602,7 +609,7 @@ func verifyMetricCount(oldMetrics, newMetrics *storageControllerMetrics, metricN
602609
gomega.Expect(newStatusCount).To(gomega.BeNumerically(">", oldStatusCount), "New status count %d should be more than old count %d for action %s", newStatusCount, oldStatusCount, metricName)
603610
}
604611

605-
func getControllerStorageMetrics(ms metrics.ControllerManagerMetrics) *storageControllerMetrics {
612+
func getControllerStorageMetrics(ms metrics.ControllerManagerMetrics, pluginName string) *storageControllerMetrics {
606613
result := newStorageControllerMetrics()
607614

608615
for method, samples := range ms {
@@ -612,6 +619,10 @@ func getControllerStorageMetrics(ms metrics.ControllerManagerMetrics) *storageCo
612619
for _, sample := range samples {
613620
count := int64(sample.Value)
614621
operation := string(sample.Metric["operation_name"])
622+
metricPluginName := string(sample.Metric["volume_plugin"])
623+
if len(pluginName) > 0 && pluginName != metricPluginName {
624+
continue
625+
}
615626
result.latencyMetrics[operation] = count
616627
}
617628
case "storage_operation_status_count":
@@ -620,6 +631,10 @@ func getControllerStorageMetrics(ms metrics.ControllerManagerMetrics) *storageCo
620631
operation := string(sample.Metric["operation_name"])
621632
status := string(sample.Metric["status"])
622633
statusCounts := result.statusMetrics[operation]
634+
metricPluginName := string(sample.Metric["volume_plugin"])
635+
if len(pluginName) > 0 && pluginName != metricPluginName {
636+
continue
637+
}
623638
switch status {
624639
case "success":
625640
statusCounts.successCount = count

0 commit comments

Comments
 (0)