Skip to content

Commit ed67d43

Browse files
authored
Merge pull request kubernetes#92530 from mattcary/metricsload
Avoid grabbing metrics when they're not validated
2 parents 3e438a9 + 028176d commit ed67d43

File tree

10 files changed

+66
-50
lines changed

10 files changed

+66
-50
lines changed

test/e2e/storage/testsuites/base.go

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ func init() {
6060

6161
type opCounts map[string]int64
6262

63+
// migrationOpCheck validates migrated metrics.
64+
type migrationOpCheck struct {
65+
cs clientset.Interface
66+
pluginName string
67+
skipCheck bool
68+
69+
// The old ops are not set if skipCheck is true.
70+
oldInTreeOps opCounts
71+
oldMigratedOps opCounts
72+
}
73+
6374
// BaseSuites is a list of storage test suites that work for in-tree and CSI drivers
6475
var BaseSuites = []func() TestSuite{
6576
InitVolumesTestSuite,
@@ -687,24 +698,18 @@ func getMigrationVolumeOpCounts(cs clientset.Interface, pluginName string) (opCo
687698
return opCounts{}, opCounts{}
688699
}
689700

690-
func validateMigrationVolumeOpCounts(cs clientset.Interface, pluginName string, oldInTreeOps, oldMigratedOps opCounts) {
701+
func newMigrationOpCheck(cs clientset.Interface, pluginName string) *migrationOpCheck {
702+
moc := migrationOpCheck{
703+
cs: cs,
704+
pluginName: pluginName,
705+
}
691706
if len(pluginName) == 0 {
692707
// This is a native CSI Driver and we don't check ops
693-
return
708+
moc.skipCheck = true
709+
return &moc
694710
}
695711

696-
if sets.NewString(strings.Split(*migratedPlugins, ",")...).Has(pluginName) {
697-
// If this plugin is migrated based on the test flag storage.migratedPlugins
698-
newInTreeOps, _ := getMigrationVolumeOpCounts(cs, pluginName)
699-
700-
for op, count := range newInTreeOps {
701-
if count != oldInTreeOps[op] {
702-
framework.Failf("In-tree plugin %v migrated to CSI Driver, however found %v %v metrics for in-tree plugin", pluginName, count-oldInTreeOps[op], op)
703-
}
704-
}
705-
// We don't check for migrated metrics because some negative test cases
706-
// may not do any volume operations and therefore not emit any metrics
707-
} else {
712+
if !sets.NewString(strings.Split(*migratedPlugins, ",")...).Has(pluginName) {
708713
// In-tree plugin is not migrated
709714
framework.Logf("In-tree plugin %v is not migrated, not validating any metrics", pluginName)
710715

@@ -721,7 +726,27 @@ func validateMigrationVolumeOpCounts(cs clientset.Interface, pluginName string,
721726
// and native CSI Driver metrics. This way we can check the counts for
722727
// migrated version of the driver for stronger negative test case
723728
// guarantees (as well as more informative metrics).
729+
moc.skipCheck = true
730+
return &moc
731+
}
732+
moc.oldInTreeOps, moc.oldMigratedOps = getMigrationVolumeOpCounts(cs, pluginName)
733+
return &moc
734+
}
735+
736+
func (moc *migrationOpCheck) validateMigrationVolumeOpCounts() {
737+
if moc.skipCheck {
738+
return
739+
}
740+
741+
newInTreeOps, _ := getMigrationVolumeOpCounts(moc.cs, moc.pluginName)
742+
743+
for op, count := range newInTreeOps {
744+
if count != moc.oldInTreeOps[op] {
745+
framework.Failf("In-tree plugin %v migrated to CSI Driver, however found %v %v metrics for in-tree plugin", moc.pluginName, count-moc.oldInTreeOps[op], op)
746+
}
724747
}
748+
// We don't check for migrated metrics because some negative test cases
749+
// may not do any volume operations and therefore not emit any metrics
725750
}
726751

727752
// Skip skipVolTypes patterns if the driver supports dynamic provisioning

test/e2e/storage/testsuites/multivolume.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ func (t *multiVolumeTestSuite) DefineTests(driver TestDriver, pattern testpatter
7979
driver TestDriver
8080
resources []*VolumeResource
8181

82-
intreeOps opCounts
83-
migratedOps opCounts
82+
migrationCheck *migrationOpCheck
8483
}
8584
var (
8685
dInfo = driver.GetDriverInfo()
@@ -108,7 +107,7 @@ func (t *multiVolumeTestSuite) DefineTests(driver TestDriver, pattern testpatter
108107

109108
// Now do the more expensive test initialization.
110109
l.config, l.driverCleanup = driver.PrepareTest(f)
111-
l.intreeOps, l.migratedOps = getMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName)
110+
l.migrationCheck = newMigrationOpCheck(f.ClientSet, dInfo.InTreePluginName)
112111
}
113112

114113
cleanup := func() {
@@ -120,7 +119,7 @@ func (t *multiVolumeTestSuite) DefineTests(driver TestDriver, pattern testpatter
120119
errs = append(errs, tryFunc(l.driverCleanup))
121120
l.driverCleanup = nil
122121
framework.ExpectNoError(errors.NewAggregate(errs), "while cleanup resource")
123-
validateMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName, l.intreeOps, l.migratedOps)
122+
l.migrationCheck.validateMigrationVolumeOpCounts()
124123
}
125124

126125
// This tests below configuration:

test/e2e/storage/testsuites/provisioning.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ func (p *provisioningTestSuite) DefineTests(driver TestDriver, pattern testpatte
103103
sourcePVC *v1.PersistentVolumeClaim
104104
sc *storagev1.StorageClass
105105

106-
intreeOps opCounts
107-
migratedOps opCounts
106+
migrationCheck *migrationOpCheck
108107
}
109108
var (
110109
dInfo = driver.GetDriverInfo()
@@ -139,7 +138,7 @@ func (p *provisioningTestSuite) DefineTests(driver TestDriver, pattern testpatte
139138

140139
// Now do the more expensive test initialization.
141140
l.config, l.driverCleanup = driver.PrepareTest(f)
142-
l.intreeOps, l.migratedOps = getMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName)
141+
l.migrationCheck = newMigrationOpCheck(f.ClientSet, dInfo.InTreePluginName)
143142
l.cs = l.config.Framework.ClientSet
144143
testVolumeSizeRange := p.GetTestSuiteInfo().SupportedSizeRange
145144
driverVolumeSizeRange := dDriver.GetDriverInfo().SupportedSizeRange
@@ -177,7 +176,7 @@ func (p *provisioningTestSuite) DefineTests(driver TestDriver, pattern testpatte
177176
l.driverCleanup = nil
178177
framework.ExpectNoError(err, "while cleaning up driver")
179178

180-
validateMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName, l.intreeOps, l.migratedOps)
179+
l.migrationCheck.validateMigrationVolumeOpCounts()
181180
}
182181

183182
ginkgo.It("should provision storage with mount options", func() {

test/e2e/storage/testsuites/stress.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ type stressTest struct {
4343
config *PerTestConfig
4444
driverCleanup func()
4545

46-
intreeOps opCounts
47-
migratedOps opCounts
46+
migrationCheck *migrationOpCheck
4847

4948
resources []*VolumeResource
5049
pods []*v1.Pod
@@ -110,7 +109,7 @@ func (t *stressTestSuite) DefineTests(driver TestDriver, pattern testpatterns.Te
110109

111110
// Now do the more expensive test initialization.
112111
l.config, l.driverCleanup = driver.PrepareTest(f)
113-
l.intreeOps, l.migratedOps = getMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName)
112+
l.migrationCheck = newMigrationOpCheck(f.ClientSet, dInfo.InTreePluginName)
114113
l.resources = []*VolumeResource{}
115114
l.pods = []*v1.Pod{}
116115
l.stopChs = []chan struct{}{}
@@ -140,7 +139,7 @@ func (t *stressTestSuite) DefineTests(driver TestDriver, pattern testpatterns.Te
140139

141140
errs = append(errs, tryFunc(l.driverCleanup))
142141
framework.ExpectNoError(errors.NewAggregate(errs), "while cleaning up resource")
143-
validateMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName, l.intreeOps, l.migratedOps)
142+
l.migrationCheck.validateMigrationVolumeOpCounts()
144143
}
145144

146145
ginkgo.It("multiple pods should access different volumes repeatedly [Slow] [Serial]", func() {

test/e2e/storage/testsuites/subpath.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ func (s *subPathTestSuite) DefineTests(driver TestDriver, pattern testpatterns.T
101101
filePathInSubpath string
102102
filePathInVolume string
103103

104-
intreeOps opCounts
105-
migratedOps opCounts
104+
migrationCheck *migrationOpCheck
106105
}
107106
var l local
108107

@@ -119,7 +118,7 @@ func (s *subPathTestSuite) DefineTests(driver TestDriver, pattern testpatterns.T
119118

120119
// Now do the more expensive test initialization.
121120
l.config, l.driverCleanup = driver.PrepareTest(f)
122-
l.intreeOps, l.migratedOps = getMigrationVolumeOpCounts(f.ClientSet, driver.GetDriverInfo().InTreePluginName)
121+
l.migrationCheck = newMigrationOpCheck(f.ClientSet, driver.GetDriverInfo().InTreePluginName)
123122
testVolumeSizeRange := s.GetTestSuiteInfo().SupportedSizeRange
124123
l.resource = CreateVolumeResource(driver, l.config, pattern, testVolumeSizeRange)
125124
l.hostExec = utils.NewHostExec(f)
@@ -183,7 +182,7 @@ func (s *subPathTestSuite) DefineTests(driver TestDriver, pattern testpatterns.T
183182
l.hostExec.Cleanup()
184183
}
185184

186-
validateMigrationVolumeOpCounts(f.ClientSet, driver.GetDriverInfo().InTreePluginName, l.intreeOps, l.migratedOps)
185+
l.migrationCheck.validateMigrationVolumeOpCounts()
187186
}
188187

189188
driverName := driver.GetDriverInfo().Name

test/e2e/storage/testsuites/topology.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ type topologyTest struct {
4545
config *PerTestConfig
4646
driverCleanup func()
4747

48-
intreeOps opCounts
49-
migratedOps opCounts
48+
migrationCheck *migrationOpCheck
5049

5150
resource VolumeResource
5251
pod *v1.Pod
@@ -148,7 +147,7 @@ func (t *topologyTestSuite) DefineTests(driver TestDriver, pattern testpatterns.
148147
StorageClassName: &(l.resource.Sc.Name),
149148
}, l.config.Framework.Namespace.Name)
150149

151-
l.intreeOps, l.migratedOps = getMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName)
150+
l.migrationCheck = newMigrationOpCheck(f.ClientSet, dInfo.InTreePluginName)
152151
return l
153152
}
154153

@@ -158,7 +157,7 @@ func (t *topologyTestSuite) DefineTests(driver TestDriver, pattern testpatterns.
158157
l.driverCleanup = nil
159158
framework.ExpectNoError(err, "while cleaning up driver")
160159

161-
validateMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName, l.intreeOps, l.migratedOps)
160+
l.migrationCheck.validateMigrationVolumeOpCounts()
162161
}
163162

164163
ginkgo.It("should provision a volume and schedule a pod with AllowedTopologies", func() {

test/e2e/storage/testsuites/volume_expand.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ func (v *volumeExpandTestSuite) DefineTests(driver TestDriver, pattern testpatte
8686
pod *v1.Pod
8787
pod2 *v1.Pod
8888

89-
intreeOps opCounts
90-
migratedOps opCounts
89+
migrationCheck *migrationOpCheck
9190
}
9291
var l local
9392

@@ -112,7 +111,7 @@ func (v *volumeExpandTestSuite) DefineTests(driver TestDriver, pattern testpatte
112111

113112
// Now do the more expensive test initialization.
114113
l.config, l.driverCleanup = driver.PrepareTest(f)
115-
l.intreeOps, l.migratedOps = getMigrationVolumeOpCounts(f.ClientSet, driver.GetDriverInfo().InTreePluginName)
114+
l.migrationCheck = newMigrationOpCheck(f.ClientSet, driver.GetDriverInfo().InTreePluginName)
116115
testVolumeSizeRange := v.GetTestSuiteInfo().SupportedSizeRange
117116
l.resource = CreateVolumeResource(driver, l.config, pattern, testVolumeSizeRange)
118117
}
@@ -141,7 +140,7 @@ func (v *volumeExpandTestSuite) DefineTests(driver TestDriver, pattern testpatte
141140
errs = append(errs, tryFunc(l.driverCleanup))
142141
l.driverCleanup = nil
143142
framework.ExpectNoError(errors.NewAggregate(errs), "while cleaning up resource")
144-
validateMigrationVolumeOpCounts(f.ClientSet, driver.GetDriverInfo().InTreePluginName, l.intreeOps, l.migratedOps)
143+
l.migrationCheck.validateMigrationVolumeOpCounts()
145144
}
146145

147146
if !pattern.AllowExpansion {

test/e2e/storage/testsuites/volume_io.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ func (t *volumeIOTestSuite) DefineTests(driver TestDriver, pattern testpatterns.
9595

9696
resource *VolumeResource
9797

98-
intreeOps opCounts
99-
migratedOps opCounts
98+
migrationCheck *migrationOpCheck
10099
}
101100
var (
102101
dInfo = driver.GetDriverInfo()
@@ -116,7 +115,7 @@ func (t *volumeIOTestSuite) DefineTests(driver TestDriver, pattern testpatterns.
116115

117116
// Now do the more expensive test initialization.
118117
l.config, l.driverCleanup = driver.PrepareTest(f)
119-
l.intreeOps, l.migratedOps = getMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName)
118+
l.migrationCheck = newMigrationOpCheck(f.ClientSet, dInfo.InTreePluginName)
120119

121120
testVolumeSizeRange := t.GetTestSuiteInfo().SupportedSizeRange
122121
l.resource = CreateVolumeResource(driver, l.config, pattern, testVolumeSizeRange)
@@ -139,7 +138,7 @@ func (t *volumeIOTestSuite) DefineTests(driver TestDriver, pattern testpatterns.
139138
}
140139

141140
framework.ExpectNoError(errors.NewAggregate(errs), "while cleaning up resource")
142-
validateMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName, l.intreeOps, l.migratedOps)
141+
l.migrationCheck.validateMigrationVolumeOpCounts()
143142
}
144143

145144
ginkgo.It("should write files of various sizes, verify size, validate content [Slow]", func() {

test/e2e/storage/testsuites/volumemode.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ func (t *volumeModeTestSuite) DefineTests(driver TestDriver, pattern testpattern
8989
// VolumeResource contains pv, pvc, sc, etc., owns cleaning that up
9090
VolumeResource
9191

92-
intreeOps opCounts
93-
migratedOps opCounts
92+
migrationCheck *migrationOpCheck
9493
}
9594
var (
9695
dInfo = driver.GetDriverInfo()
@@ -112,7 +111,7 @@ func (t *volumeModeTestSuite) DefineTests(driver TestDriver, pattern testpattern
112111

113112
// Now do the more expensive test initialization.
114113
l.config, l.driverCleanup = driver.PrepareTest(f)
115-
l.intreeOps, l.migratedOps = getMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName)
114+
l.migrationCheck = newMigrationOpCheck(f.ClientSet, dInfo.InTreePluginName)
116115
}
117116

118117
// manualInit initializes l.VolumeResource without creating the PV & PVC objects.
@@ -183,7 +182,7 @@ func (t *volumeModeTestSuite) DefineTests(driver TestDriver, pattern testpattern
183182
errs = append(errs, tryFunc(l.driverCleanup))
184183
l.driverCleanup = nil
185184
framework.ExpectNoError(errors.NewAggregate(errs), "while cleaning up resource")
186-
validateMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName, l.intreeOps, l.migratedOps)
185+
l.migrationCheck.validateMigrationVolumeOpCounts()
187186
}
188187

189188
// We register different tests depending on the drive

test/e2e/storage/testsuites/volumes.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ func (t *volumesTestSuite) DefineTests(driver TestDriver, pattern testpatterns.T
109109

110110
resource *VolumeResource
111111

112-
intreeOps opCounts
113-
migratedOps opCounts
112+
migrationCheck *migrationOpCheck
114113
}
115114
var dInfo = driver.GetDriverInfo()
116115
var l local
@@ -128,7 +127,7 @@ func (t *volumesTestSuite) DefineTests(driver TestDriver, pattern testpatterns.T
128127

129128
// Now do the more expensive test initialization.
130129
l.config, l.driverCleanup = driver.PrepareTest(f)
131-
l.intreeOps, l.migratedOps = getMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName)
130+
l.migrationCheck = newMigrationOpCheck(f.ClientSet, dInfo.InTreePluginName)
132131
testVolumeSizeRange := t.GetTestSuiteInfo().SupportedSizeRange
133132
l.resource = CreateVolumeResource(driver, l.config, pattern, testVolumeSizeRange)
134133
if l.resource.VolSource == nil {
@@ -146,7 +145,7 @@ func (t *volumesTestSuite) DefineTests(driver TestDriver, pattern testpatterns.T
146145
errs = append(errs, tryFunc(l.driverCleanup))
147146
l.driverCleanup = nil
148147
framework.ExpectNoError(errors.NewAggregate(errs), "while cleaning up resource")
149-
validateMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName, l.intreeOps, l.migratedOps)
148+
l.migrationCheck.validateMigrationVolumeOpCounts()
150149
}
151150

152151
ginkgo.It("should store data", func() {

0 commit comments

Comments
 (0)