Merge pull request #92530 from mattcary/metricsload

Avoid grabbing metrics when they're not validated
This commit is contained in:
Kubernetes Prow Robot 2020-06-26 11:49:46 -07:00 committed by GitHub
commit ed67d43ea4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 66 additions and 50 deletions

View File

@ -60,6 +60,17 @@ func init() {
type opCounts map[string]int64
// migrationOpCheck validates migrated metrics.
type migrationOpCheck struct {
cs clientset.Interface
pluginName string
skipCheck bool
// The old ops are not set if skipCheck is true.
oldInTreeOps opCounts
oldMigratedOps opCounts
}
// BaseSuites is a list of storage test suites that work for in-tree and CSI drivers
var BaseSuites = []func() TestSuite{
InitVolumesTestSuite,
@ -687,24 +698,18 @@ func getMigrationVolumeOpCounts(cs clientset.Interface, pluginName string) (opCo
return opCounts{}, opCounts{}
}
func validateMigrationVolumeOpCounts(cs clientset.Interface, pluginName string, oldInTreeOps, oldMigratedOps opCounts) {
func newMigrationOpCheck(cs clientset.Interface, pluginName string) *migrationOpCheck {
moc := migrationOpCheck{
cs: cs,
pluginName: pluginName,
}
if len(pluginName) == 0 {
// This is a native CSI Driver and we don't check ops
return
moc.skipCheck = true
return &moc
}
if sets.NewString(strings.Split(*migratedPlugins, ",")...).Has(pluginName) {
// If this plugin is migrated based on the test flag storage.migratedPlugins
newInTreeOps, _ := getMigrationVolumeOpCounts(cs, pluginName)
for op, count := range newInTreeOps {
if count != oldInTreeOps[op] {
framework.Failf("In-tree plugin %v migrated to CSI Driver, however found %v %v metrics for in-tree plugin", pluginName, count-oldInTreeOps[op], op)
}
}
// We don't check for migrated metrics because some negative test cases
// may not do any volume operations and therefore not emit any metrics
} else {
if !sets.NewString(strings.Split(*migratedPlugins, ",")...).Has(pluginName) {
// In-tree plugin is not migrated
framework.Logf("In-tree plugin %v is not migrated, not validating any metrics", pluginName)
@ -721,7 +726,27 @@ func validateMigrationVolumeOpCounts(cs clientset.Interface, pluginName string,
// and native CSI Driver metrics. This way we can check the counts for
// migrated version of the driver for stronger negative test case
// guarantees (as well as more informative metrics).
moc.skipCheck = true
return &moc
}
moc.oldInTreeOps, moc.oldMigratedOps = getMigrationVolumeOpCounts(cs, pluginName)
return &moc
}
func (moc *migrationOpCheck) validateMigrationVolumeOpCounts() {
if moc.skipCheck {
return
}
newInTreeOps, _ := getMigrationVolumeOpCounts(moc.cs, moc.pluginName)
for op, count := range newInTreeOps {
if count != moc.oldInTreeOps[op] {
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)
}
}
// We don't check for migrated metrics because some negative test cases
// may not do any volume operations and therefore not emit any metrics
}
// Skip skipVolTypes patterns if the driver supports dynamic provisioning

View File

@ -79,8 +79,7 @@ func (t *multiVolumeTestSuite) DefineTests(driver TestDriver, pattern testpatter
driver TestDriver
resources []*VolumeResource
intreeOps opCounts
migratedOps opCounts
migrationCheck *migrationOpCheck
}
var (
dInfo = driver.GetDriverInfo()
@ -108,7 +107,7 @@ func (t *multiVolumeTestSuite) DefineTests(driver TestDriver, pattern testpatter
// Now do the more expensive test initialization.
l.config, l.driverCleanup = driver.PrepareTest(f)
l.intreeOps, l.migratedOps = getMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName)
l.migrationCheck = newMigrationOpCheck(f.ClientSet, dInfo.InTreePluginName)
}
cleanup := func() {
@ -120,7 +119,7 @@ func (t *multiVolumeTestSuite) DefineTests(driver TestDriver, pattern testpatter
errs = append(errs, tryFunc(l.driverCleanup))
l.driverCleanup = nil
framework.ExpectNoError(errors.NewAggregate(errs), "while cleanup resource")
validateMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName, l.intreeOps, l.migratedOps)
l.migrationCheck.validateMigrationVolumeOpCounts()
}
// This tests below configuration:

View File

@ -103,8 +103,7 @@ func (p *provisioningTestSuite) DefineTests(driver TestDriver, pattern testpatte
sourcePVC *v1.PersistentVolumeClaim
sc *storagev1.StorageClass
intreeOps opCounts
migratedOps opCounts
migrationCheck *migrationOpCheck
}
var (
dInfo = driver.GetDriverInfo()
@ -139,7 +138,7 @@ func (p *provisioningTestSuite) DefineTests(driver TestDriver, pattern testpatte
// Now do the more expensive test initialization.
l.config, l.driverCleanup = driver.PrepareTest(f)
l.intreeOps, l.migratedOps = getMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName)
l.migrationCheck = newMigrationOpCheck(f.ClientSet, dInfo.InTreePluginName)
l.cs = l.config.Framework.ClientSet
testVolumeSizeRange := p.GetTestSuiteInfo().SupportedSizeRange
driverVolumeSizeRange := dDriver.GetDriverInfo().SupportedSizeRange
@ -177,7 +176,7 @@ func (p *provisioningTestSuite) DefineTests(driver TestDriver, pattern testpatte
l.driverCleanup = nil
framework.ExpectNoError(err, "while cleaning up driver")
validateMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName, l.intreeOps, l.migratedOps)
l.migrationCheck.validateMigrationVolumeOpCounts()
}
ginkgo.It("should provision storage with mount options", func() {

View File

@ -43,8 +43,7 @@ type stressTest struct {
config *PerTestConfig
driverCleanup func()
intreeOps opCounts
migratedOps opCounts
migrationCheck *migrationOpCheck
resources []*VolumeResource
pods []*v1.Pod
@ -110,7 +109,7 @@ func (t *stressTestSuite) DefineTests(driver TestDriver, pattern testpatterns.Te
// Now do the more expensive test initialization.
l.config, l.driverCleanup = driver.PrepareTest(f)
l.intreeOps, l.migratedOps = getMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName)
l.migrationCheck = newMigrationOpCheck(f.ClientSet, dInfo.InTreePluginName)
l.resources = []*VolumeResource{}
l.pods = []*v1.Pod{}
l.stopChs = []chan struct{}{}
@ -140,7 +139,7 @@ func (t *stressTestSuite) DefineTests(driver TestDriver, pattern testpatterns.Te
errs = append(errs, tryFunc(l.driverCleanup))
framework.ExpectNoError(errors.NewAggregate(errs), "while cleaning up resource")
validateMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName, l.intreeOps, l.migratedOps)
l.migrationCheck.validateMigrationVolumeOpCounts()
}
ginkgo.It("multiple pods should access different volumes repeatedly [Slow] [Serial]", func() {

View File

@ -101,8 +101,7 @@ func (s *subPathTestSuite) DefineTests(driver TestDriver, pattern testpatterns.T
filePathInSubpath string
filePathInVolume string
intreeOps opCounts
migratedOps opCounts
migrationCheck *migrationOpCheck
}
var l local
@ -119,7 +118,7 @@ func (s *subPathTestSuite) DefineTests(driver TestDriver, pattern testpatterns.T
// Now do the more expensive test initialization.
l.config, l.driverCleanup = driver.PrepareTest(f)
l.intreeOps, l.migratedOps = getMigrationVolumeOpCounts(f.ClientSet, driver.GetDriverInfo().InTreePluginName)
l.migrationCheck = newMigrationOpCheck(f.ClientSet, driver.GetDriverInfo().InTreePluginName)
testVolumeSizeRange := s.GetTestSuiteInfo().SupportedSizeRange
l.resource = CreateVolumeResource(driver, l.config, pattern, testVolumeSizeRange)
l.hostExec = utils.NewHostExec(f)
@ -183,7 +182,7 @@ func (s *subPathTestSuite) DefineTests(driver TestDriver, pattern testpatterns.T
l.hostExec.Cleanup()
}
validateMigrationVolumeOpCounts(f.ClientSet, driver.GetDriverInfo().InTreePluginName, l.intreeOps, l.migratedOps)
l.migrationCheck.validateMigrationVolumeOpCounts()
}
driverName := driver.GetDriverInfo().Name

View File

@ -45,8 +45,7 @@ type topologyTest struct {
config *PerTestConfig
driverCleanup func()
intreeOps opCounts
migratedOps opCounts
migrationCheck *migrationOpCheck
resource VolumeResource
pod *v1.Pod
@ -148,7 +147,7 @@ func (t *topologyTestSuite) DefineTests(driver TestDriver, pattern testpatterns.
StorageClassName: &(l.resource.Sc.Name),
}, l.config.Framework.Namespace.Name)
l.intreeOps, l.migratedOps = getMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName)
l.migrationCheck = newMigrationOpCheck(f.ClientSet, dInfo.InTreePluginName)
return l
}
@ -158,7 +157,7 @@ func (t *topologyTestSuite) DefineTests(driver TestDriver, pattern testpatterns.
l.driverCleanup = nil
framework.ExpectNoError(err, "while cleaning up driver")
validateMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName, l.intreeOps, l.migratedOps)
l.migrationCheck.validateMigrationVolumeOpCounts()
}
ginkgo.It("should provision a volume and schedule a pod with AllowedTopologies", func() {

View File

@ -86,8 +86,7 @@ func (v *volumeExpandTestSuite) DefineTests(driver TestDriver, pattern testpatte
pod *v1.Pod
pod2 *v1.Pod
intreeOps opCounts
migratedOps opCounts
migrationCheck *migrationOpCheck
}
var l local
@ -112,7 +111,7 @@ func (v *volumeExpandTestSuite) DefineTests(driver TestDriver, pattern testpatte
// Now do the more expensive test initialization.
l.config, l.driverCleanup = driver.PrepareTest(f)
l.intreeOps, l.migratedOps = getMigrationVolumeOpCounts(f.ClientSet, driver.GetDriverInfo().InTreePluginName)
l.migrationCheck = newMigrationOpCheck(f.ClientSet, driver.GetDriverInfo().InTreePluginName)
testVolumeSizeRange := v.GetTestSuiteInfo().SupportedSizeRange
l.resource = CreateVolumeResource(driver, l.config, pattern, testVolumeSizeRange)
}
@ -141,7 +140,7 @@ func (v *volumeExpandTestSuite) DefineTests(driver TestDriver, pattern testpatte
errs = append(errs, tryFunc(l.driverCleanup))
l.driverCleanup = nil
framework.ExpectNoError(errors.NewAggregate(errs), "while cleaning up resource")
validateMigrationVolumeOpCounts(f.ClientSet, driver.GetDriverInfo().InTreePluginName, l.intreeOps, l.migratedOps)
l.migrationCheck.validateMigrationVolumeOpCounts()
}
if !pattern.AllowExpansion {

View File

@ -95,8 +95,7 @@ func (t *volumeIOTestSuite) DefineTests(driver TestDriver, pattern testpatterns.
resource *VolumeResource
intreeOps opCounts
migratedOps opCounts
migrationCheck *migrationOpCheck
}
var (
dInfo = driver.GetDriverInfo()
@ -116,7 +115,7 @@ func (t *volumeIOTestSuite) DefineTests(driver TestDriver, pattern testpatterns.
// Now do the more expensive test initialization.
l.config, l.driverCleanup = driver.PrepareTest(f)
l.intreeOps, l.migratedOps = getMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName)
l.migrationCheck = newMigrationOpCheck(f.ClientSet, dInfo.InTreePluginName)
testVolumeSizeRange := t.GetTestSuiteInfo().SupportedSizeRange
l.resource = CreateVolumeResource(driver, l.config, pattern, testVolumeSizeRange)
@ -139,7 +138,7 @@ func (t *volumeIOTestSuite) DefineTests(driver TestDriver, pattern testpatterns.
}
framework.ExpectNoError(errors.NewAggregate(errs), "while cleaning up resource")
validateMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName, l.intreeOps, l.migratedOps)
l.migrationCheck.validateMigrationVolumeOpCounts()
}
ginkgo.It("should write files of various sizes, verify size, validate content [Slow]", func() {

View File

@ -89,8 +89,7 @@ func (t *volumeModeTestSuite) DefineTests(driver TestDriver, pattern testpattern
// VolumeResource contains pv, pvc, sc, etc., owns cleaning that up
VolumeResource
intreeOps opCounts
migratedOps opCounts
migrationCheck *migrationOpCheck
}
var (
dInfo = driver.GetDriverInfo()
@ -112,7 +111,7 @@ func (t *volumeModeTestSuite) DefineTests(driver TestDriver, pattern testpattern
// Now do the more expensive test initialization.
l.config, l.driverCleanup = driver.PrepareTest(f)
l.intreeOps, l.migratedOps = getMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName)
l.migrationCheck = newMigrationOpCheck(f.ClientSet, dInfo.InTreePluginName)
}
// manualInit initializes l.VolumeResource without creating the PV & PVC objects.
@ -183,7 +182,7 @@ func (t *volumeModeTestSuite) DefineTests(driver TestDriver, pattern testpattern
errs = append(errs, tryFunc(l.driverCleanup))
l.driverCleanup = nil
framework.ExpectNoError(errors.NewAggregate(errs), "while cleaning up resource")
validateMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName, l.intreeOps, l.migratedOps)
l.migrationCheck.validateMigrationVolumeOpCounts()
}
// We register different tests depending on the drive

View File

@ -109,8 +109,7 @@ func (t *volumesTestSuite) DefineTests(driver TestDriver, pattern testpatterns.T
resource *VolumeResource
intreeOps opCounts
migratedOps opCounts
migrationCheck *migrationOpCheck
}
var dInfo = driver.GetDriverInfo()
var l local
@ -128,7 +127,7 @@ func (t *volumesTestSuite) DefineTests(driver TestDriver, pattern testpatterns.T
// Now do the more expensive test initialization.
l.config, l.driverCleanup = driver.PrepareTest(f)
l.intreeOps, l.migratedOps = getMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName)
l.migrationCheck = newMigrationOpCheck(f.ClientSet, dInfo.InTreePluginName)
testVolumeSizeRange := t.GetTestSuiteInfo().SupportedSizeRange
l.resource = CreateVolumeResource(driver, l.config, pattern, testVolumeSizeRange)
if l.resource.VolSource == nil {
@ -146,7 +145,7 @@ func (t *volumesTestSuite) DefineTests(driver TestDriver, pattern testpatterns.T
errs = append(errs, tryFunc(l.driverCleanup))
l.driverCleanup = nil
framework.ExpectNoError(errors.NewAggregate(errs), "while cleaning up resource")
validateMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName, l.intreeOps, l.migratedOps)
l.migrationCheck.validateMigrationVolumeOpCounts()
}
ginkgo.It("should store data", func() {