Skip to content

Commit 3047ab7

Browse files
committed
Reset only metrics configured in collector before the createPodsOp
1 parent fbaeab3 commit 3047ab7

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

test/integration/scheduler_perf/scheduler_perf.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,10 @@ func runWorkload(tCtx ktesting.TContext, tc *testCase, w *workload, informerFact
11391139
for _, collector := range collectors {
11401140
// Need loop-local variable for function below.
11411141
collector := collector
1142-
collector.init()
1142+
err = collector.init()
1143+
if err != nil {
1144+
tCtx.Fatalf("op %d: Failed to initialize data collector: %v", opIndex, err)
1145+
}
11431146
collectorWG.Add(1)
11441147
go func() {
11451148
defer collectorWG.Done()
@@ -1205,13 +1208,6 @@ func runWorkload(tCtx ktesting.TContext, tc *testCase, w *workload, informerFact
12051208
}()
12061209
}
12071210

1208-
if !concreteOp.SkipWaitToCompletion {
1209-
// SkipWaitToCompletion=false indicates this step has waited for the Pods to be scheduled.
1210-
// So we reset the metrics in global registry; otherwise metrics gathered in this step
1211-
// will be carried over to next step.
1212-
legacyregistry.Reset()
1213-
}
1214-
12151211
case *churnOp:
12161212
var namespace string
12171213
if concreteOp.Namespace != nil {
@@ -1376,7 +1372,7 @@ func createNamespaceIfNotPresent(tCtx ktesting.TContext, namespace string, podsP
13761372
}
13771373

13781374
type testDataCollector interface {
1379-
init()
1375+
init() error
13801376
run(tCtx ktesting.TContext)
13811377
collect() []DataItem
13821378
}

test/integration/scheduler_perf/util.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,19 @@ func newMetricsCollector(config *metricsCollectorConfig, labels map[string]strin
263263
}
264264
}
265265

266-
func (mc *metricsCollector) init() {
266+
func (mc *metricsCollector) init() error {
267267
// Reset the metrics so that the measurements do not interfere with those collected during the previous steps.
268-
legacyregistry.Reset()
268+
m, err := legacyregistry.DefaultGatherer.Gather()
269+
if err != nil {
270+
return fmt.Errorf("failed to gather metrics to reset: %w", err)
271+
}
272+
for _, mFamily := range m {
273+
// Reset only metrics defined in the collector.
274+
if _, ok := mc.Metrics[mFamily.GetName()]; ok {
275+
mFamily.Reset()
276+
}
277+
}
278+
return nil
269279
}
270280

271281
func (*metricsCollector) run(tCtx ktesting.TContext) {
@@ -381,7 +391,8 @@ func newThroughputCollector(podInformer coreinformers.PodInformer, labels map[st
381391
}
382392
}
383393

384-
func (tc *throughputCollector) init() {
394+
func (tc *throughputCollector) init() error {
395+
return nil
385396
}
386397

387398
func (tc *throughputCollector) run(tCtx ktesting.TContext) {

0 commit comments

Comments
 (0)