mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Reset only metrics configured in collector before the createPodsOp
This commit is contained in:
		@@ -1139,7 +1139,10 @@ func runWorkload(tCtx ktesting.TContext, tc *testCase, w *workload, informerFact
 | 
			
		||||
				for _, collector := range collectors {
 | 
			
		||||
					// Need loop-local variable for function below.
 | 
			
		||||
					collector := collector
 | 
			
		||||
					collector.init()
 | 
			
		||||
					err = collector.init()
 | 
			
		||||
					if err != nil {
 | 
			
		||||
						tCtx.Fatalf("op %d: Failed to initialize data collector: %v", opIndex, err)
 | 
			
		||||
					}
 | 
			
		||||
					collectorWG.Add(1)
 | 
			
		||||
					go func() {
 | 
			
		||||
						defer collectorWG.Done()
 | 
			
		||||
@@ -1205,13 +1208,6 @@ func runWorkload(tCtx ktesting.TContext, tc *testCase, w *workload, informerFact
 | 
			
		||||
				}()
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if !concreteOp.SkipWaitToCompletion {
 | 
			
		||||
				// SkipWaitToCompletion=false indicates this step has waited for the Pods to be scheduled.
 | 
			
		||||
				// So we reset the metrics in global registry; otherwise metrics gathered in this step
 | 
			
		||||
				// will be carried over to next step.
 | 
			
		||||
				legacyregistry.Reset()
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
		case *churnOp:
 | 
			
		||||
			var namespace string
 | 
			
		||||
			if concreteOp.Namespace != nil {
 | 
			
		||||
@@ -1376,7 +1372,7 @@ func createNamespaceIfNotPresent(tCtx ktesting.TContext, namespace string, podsP
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type testDataCollector interface {
 | 
			
		||||
	init()
 | 
			
		||||
	init() error
 | 
			
		||||
	run(tCtx ktesting.TContext)
 | 
			
		||||
	collect() []DataItem
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -263,9 +263,19 @@ func newMetricsCollector(config *metricsCollectorConfig, labels map[string]strin
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (mc *metricsCollector) init() {
 | 
			
		||||
func (mc *metricsCollector) init() error {
 | 
			
		||||
	// Reset the metrics so that the measurements do not interfere with those collected during the previous steps.
 | 
			
		||||
	legacyregistry.Reset()
 | 
			
		||||
	m, err := legacyregistry.DefaultGatherer.Gather()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return fmt.Errorf("failed to gather metrics to reset: %w", err)
 | 
			
		||||
	}
 | 
			
		||||
	for _, mFamily := range m {
 | 
			
		||||
		// Reset only metrics defined in the collector.
 | 
			
		||||
		if _, ok := mc.Metrics[mFamily.GetName()]; ok {
 | 
			
		||||
			mFamily.Reset()
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (*metricsCollector) run(tCtx ktesting.TContext) {
 | 
			
		||||
@@ -381,7 +391,8 @@ func newThroughputCollector(podInformer coreinformers.PodInformer, labels map[st
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (tc *throughputCollector) init() {
 | 
			
		||||
func (tc *throughputCollector) init() error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (tc *throughputCollector) run(tCtx ktesting.TContext) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user