@@ -871,6 +871,10 @@ type startCollectingMetricsOp struct {
871
871
Name string
872
872
// Namespaces for which the scheduling throughput metric is calculated.
873
873
Namespaces []string
874
+ // Labels used to filter the pods for which the scheduling throughput metric is collected.
875
+ // If empty, it will collect the metric for all pods in the selected namespaces.
876
+ // Optional.
877
+ LabelSelector map [string ]string
874
878
}
875
879
876
880
func (scm * startCollectingMetricsOp ) isValid (_ bool ) error {
@@ -1227,12 +1231,12 @@ func checkEmptyInFlightEvents() error {
1227
1231
return nil
1228
1232
}
1229
1233
1230
- func startCollectingMetrics (tCtx ktesting.TContext , collectorWG * sync.WaitGroup , podInformer coreinformers.PodInformer , mcc * metricsCollectorConfig , throughputErrorMargin float64 , opIndex int , name string , namespaces []string ) (ktesting.TContext , []testDataCollector ) {
1234
+ func startCollectingMetrics (tCtx ktesting.TContext , collectorWG * sync.WaitGroup , podInformer coreinformers.PodInformer , mcc * metricsCollectorConfig , throughputErrorMargin float64 , opIndex int , name string , namespaces []string , labelSelector map [ string ] string ) (ktesting.TContext , []testDataCollector ) {
1231
1235
collectorCtx := ktesting .WithCancel (tCtx )
1232
1236
workloadName := tCtx .Name ()
1233
1237
// The first part is the same for each workload, therefore we can strip it.
1234
1238
workloadName = workloadName [strings .Index (name , "/" )+ 1 :]
1235
- collectors := getTestDataCollectors (podInformer , fmt .Sprintf ("%s/%s" , workloadName , name ), namespaces , mcc , throughputErrorMargin )
1239
+ collectors := getTestDataCollectors (podInformer , fmt .Sprintf ("%s/%s" , workloadName , name ), namespaces , labelSelector , mcc , throughputErrorMargin )
1236
1240
for _ , collector := range collectors {
1237
1241
// Need loop-local variable for function below.
1238
1242
collector := collector
@@ -1373,7 +1377,7 @@ func runWorkload(tCtx ktesting.TContext, tc *testCase, w *workload, informerFact
1373
1377
if collectorCtx != nil {
1374
1378
tCtx .Fatalf ("op %d: Metrics collection is overlapping. Probably second collector was started before stopping a previous one" , opIndex )
1375
1379
}
1376
- collectorCtx , collectors = startCollectingMetrics (tCtx , & collectorWG , podInformer , tc .MetricsCollectorConfig , throughputErrorMargin , opIndex , namespace , []string {namespace })
1380
+ collectorCtx , collectors = startCollectingMetrics (tCtx , & collectorWG , podInformer , tc .MetricsCollectorConfig , throughputErrorMargin , opIndex , namespace , []string {namespace }, nil )
1377
1381
defer collectorCtx .Cancel ("cleaning up" )
1378
1382
}
1379
1383
if err := createPodsRapidly (tCtx , namespace , concreteOp ); err != nil {
@@ -1584,7 +1588,7 @@ func runWorkload(tCtx ktesting.TContext, tc *testCase, w *workload, informerFact
1584
1588
if collectorCtx != nil {
1585
1589
tCtx .Fatalf ("op %d: Metrics collection is overlapping. Probably second collector was started before stopping a previous one" , opIndex )
1586
1590
}
1587
- collectorCtx , collectors = startCollectingMetrics (tCtx , & collectorWG , podInformer , tc .MetricsCollectorConfig , throughputErrorMargin , opIndex , concreteOp .Name , concreteOp .Namespaces )
1591
+ collectorCtx , collectors = startCollectingMetrics (tCtx , & collectorWG , podInformer , tc .MetricsCollectorConfig , throughputErrorMargin , opIndex , concreteOp .Name , concreteOp .Namespaces , concreteOp . LabelSelector )
1588
1592
defer collectorCtx .Cancel ("cleaning up" )
1589
1593
1590
1594
case * stopCollectingMetricsOp :
@@ -1633,12 +1637,12 @@ type testDataCollector interface {
1633
1637
collect () []DataItem
1634
1638
}
1635
1639
1636
- func getTestDataCollectors (podInformer coreinformers.PodInformer , name string , namespaces []string , mcc * metricsCollectorConfig , throughputErrorMargin float64 ) []testDataCollector {
1640
+ func getTestDataCollectors (podInformer coreinformers.PodInformer , name string , namespaces []string , labelSelector map [ string ] string , mcc * metricsCollectorConfig , throughputErrorMargin float64 ) []testDataCollector {
1637
1641
if mcc == nil {
1638
1642
mcc = & defaultMetricsCollectorConfig
1639
1643
}
1640
1644
return []testDataCollector {
1641
- newThroughputCollector (podInformer , map [string ]string {"Name" : name }, namespaces , throughputErrorMargin ),
1645
+ newThroughputCollector (podInformer , map [string ]string {"Name" : name }, labelSelector , namespaces , throughputErrorMargin ),
1642
1646
newMetricsCollector (mcc , map [string ]string {"Name" : name }),
1643
1647
}
1644
1648
}
0 commit comments