Skip to content

Commit 5894e20

Browse files
committed
Measure metrics only during a specific op in scheduler_perf
1 parent 7a4c962 commit 5894e20

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

test/integration/scheduler_perf/scheduler_perf.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,10 +1059,11 @@ func runWorkload(tCtx ktesting.TContext, tc *testCase, w *workload, informerFact
10591059
name := tCtx.Name()
10601060
// The first part is the same for each work load, therefore we can strip it.
10611061
name = name[strings.Index(name, "/")+1:]
1062-
collectors = getTestDataCollectors(collectorCtx, podInformer, fmt.Sprintf("%s/%s", name, namespace), namespace, tc.MetricsCollectorConfig, throughputErrorMargin)
1062+
collectors = getTestDataCollectors(podInformer, fmt.Sprintf("%s/%s", name, namespace), namespace, tc.MetricsCollectorConfig, throughputErrorMargin)
10631063
for _, collector := range collectors {
10641064
// Need loop-local variable for function below.
10651065
collector := collector
1066+
collector.init()
10661067
collectorWG.Add(1)
10671068
go func() {
10681069
defer collectorWG.Done()
@@ -1299,16 +1300,17 @@ func createNamespaceIfNotPresent(tCtx ktesting.TContext, namespace string, podsP
12991300
}
13001301

13011302
type testDataCollector interface {
1303+
init()
13021304
run(tCtx ktesting.TContext)
13031305
collect() []DataItem
13041306
}
13051307

1306-
func getTestDataCollectors(tCtx ktesting.TContext, podInformer coreinformers.PodInformer, name, namespace string, mcc *metricsCollectorConfig, throughputErrorMargin float64) []testDataCollector {
1308+
func getTestDataCollectors(podInformer coreinformers.PodInformer, name, namespace string, mcc *metricsCollectorConfig, throughputErrorMargin float64) []testDataCollector {
13071309
if mcc == nil {
13081310
mcc = &defaultMetricsCollectorConfig
13091311
}
13101312
return []testDataCollector{
1311-
newThroughputCollector(tCtx, podInformer, map[string]string{"Name": name}, []string{namespace}, throughputErrorMargin),
1313+
newThroughputCollector(podInformer, map[string]string{"Name": name}, []string{namespace}, throughputErrorMargin),
13121314
newMetricsCollector(mcc, map[string]string{"Name": name}),
13131315
}
13141316
}

test/integration/scheduler_perf/util.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,22 +266,27 @@ func newMetricsCollector(config *metricsCollectorConfig, labels map[string]strin
266266
}
267267
}
268268

269+
func (mc *metricsCollector) init() {
270+
// Reset the metrics so that the measurements do not interfere with those collected during the previous steps.
271+
legacyregistry.Reset()
272+
}
273+
269274
func (*metricsCollector) run(tCtx ktesting.TContext) {
270275
// metricCollector doesn't need to start before the tests, so nothing to do here.
271276
}
272277

273-
func (pc *metricsCollector) collect() []DataItem {
278+
func (mc *metricsCollector) collect() []DataItem {
274279
var dataItems []DataItem
275-
for metric, labelValsSlice := range pc.Metrics {
280+
for metric, labelValsSlice := range mc.Metrics {
276281
// no filter is specified, aggregate all the metrics within the same metricFamily.
277282
if labelValsSlice == nil {
278-
dataItem := collectHistogramVec(metric, pc.labels, nil)
283+
dataItem := collectHistogramVec(metric, mc.labels, nil)
279284
if dataItem != nil {
280285
dataItems = append(dataItems, *dataItem)
281286
}
282287
} else {
283288
for _, lvMap := range uniqueLVCombos(labelValsSlice) {
284-
dataItem := collectHistogramVec(metric, pc.labels, lvMap)
289+
dataItem := collectHistogramVec(metric, mc.labels, lvMap)
285290
if dataItem != nil {
286291
dataItems = append(dataItems, *dataItem)
287292
}
@@ -370,7 +375,7 @@ type throughputCollector struct {
370375
errorMargin float64
371376
}
372377

373-
func newThroughputCollector(tb ktesting.TB, podInformer coreinformers.PodInformer, labels map[string]string, namespaces []string, errorMargin float64) *throughputCollector {
378+
func newThroughputCollector(podInformer coreinformers.PodInformer, labels map[string]string, namespaces []string, errorMargin float64) *throughputCollector {
374379
return &throughputCollector{
375380
podInformer: podInformer,
376381
labels: labels,
@@ -379,6 +384,9 @@ func newThroughputCollector(tb ktesting.TB, podInformer coreinformers.PodInforme
379384
}
380385
}
381386

387+
func (tc *throughputCollector) init() {
388+
}
389+
382390
func (tc *throughputCollector) run(tCtx ktesting.TContext) {
383391
podsScheduled, _, err := getScheduledPods(tc.podInformer, tc.namespaces...)
384392
if err != nil {

0 commit comments

Comments
 (0)