@@ -45,7 +45,7 @@ import (
45
45
"sigs.k8s.io/gateway-api-inference-extension/internal/runnable"
46
46
"sigs.k8s.io/gateway-api-inference-extension/pkg/common"
47
47
backendmetrics "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/backend/metrics"
48
- "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/config/loader"
48
+ "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/common/ config/loader"
49
49
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/datastore"
50
50
51
51
// Import the latency predictor package
@@ -325,6 +325,11 @@ func (r *Runner) Run(ctx context.Context) error {
325
325
setupLog .Error (err , "Failed to create controller manager" )
326
326
return err
327
327
}
328
+ err = setupPprofHandlers (mgr )
329
+ if err != nil {
330
+ setupLog .Error (err , "Failed to setup pprof handlers" )
331
+ return err
332
+ }
328
333
329
334
// ===================================================================
330
335
// == Latency Predictor Integration
@@ -368,37 +373,40 @@ func (r *Runner) Run(ctx context.Context) error {
368
373
}
369
374
}
370
375
376
+ // START DIFF
377
+ // below is what was incomming
378
+ err = r .parseConfiguration (ctx )
379
+ if err != nil {
380
+ setupLog .Error (err , "Failed to parse the configuration" )
381
+ return err
382
+ }
383
+
384
+ // below is what was current
371
385
if len (* configText ) != 0 || len (* configFile ) != 0 {
372
- theConfig , err := config .LoadConfig ([]byte (* configText ), * configFile )
386
+ theConfig , err := loader .LoadConfig ([]byte (* configText ), * configFile )
373
387
if err != nil {
374
388
setupLog .Error (err , "Failed to load the configuration" )
375
389
return err
376
390
}
377
391
378
- epp := eppHandle {}
379
- instantiatedPlugins , err := config .LoadPluginReferences (theConfig .Plugins , epp )
392
+ epp := newEppHandle ()
393
+
394
+ err = loader .LoadPluginReferences (theConfig .Plugins , epp )
380
395
if err != nil {
381
396
setupLog .Error (err , "Failed to instantiate the plugins" )
382
397
return err
383
398
}
384
- }
385
399
386
- r .schedulerConfig , err = scheduling .LoadSchedulerConfig (theConfig .SchedulingProfiles , instantiatedPlugins )
387
- if err != nil {
388
- setupLog .Error (err , "Failed to create Scheduler configuration" )
389
- return err
390
- }
391
-
392
- err = r .parsePluginsConfiguration (ctx )
393
- if err != nil {
394
- setupLog .Error (err , "Failed to parse plugins configuration" )
395
- return err
396
- }
400
+ r .schedulerConfig , err = loader .LoadSchedulerConfig (theConfig .SchedulingProfiles , epp )
401
+ if err != nil {
402
+ setupLog .Error (err , "Failed to create Scheduler configuration" )
403
+ return err
404
+ }
397
405
398
- // Add requestcontrol plugins
399
- if instantiatedPlugins != nil {
400
- r .requestControlConfig = requestcontrol .LoadRequestControlConfig (instantiatedPlugins )
406
+ // Add requestControl plugins
407
+ r .requestControlConfig .AddPlugins (epp .Plugins ().GetAllPlugins ()... )
401
408
}
409
+ // END DIFF
402
410
403
411
// --- Initialize Core EPP Components ---
404
412
if r .schedulerConfig == nil {
@@ -418,18 +426,20 @@ func (r *Runner) Run(ctx context.Context) error {
418
426
419
427
// --- Setup ExtProc Server Runner ---
420
428
serverRunner := & runserver.ExtProcServerRunner {
421
- GrpcPort : * grpcPort ,
422
- PoolNamespacedName : poolNamespacedName ,
423
- PoolGKNN : poolGKNN ,
424
- Datastore : datastore ,
425
- SecureServing : * secureServing ,
426
- HealthChecking : * healthChecking ,
427
- CertPath : * certPath ,
428
- RefreshPrometheusMetricsInterval : * refreshPrometheusMetricsInterval ,
429
- MetricsStalenessThreshold : * metricsStalenessThreshold ,
430
- Director : director ,
431
- SaturationDetector : saturationDetector ,
432
- LatencyPredictor : predictor ,
429
+ GrpcPort : * grpcPort ,
430
+ PoolNamespacedName : poolNamespacedName ,
431
+ PoolGKNN : poolGKNN ,
432
+ Datastore : datastore ,
433
+ SecureServing : * secureServing ,
434
+ HealthChecking : * healthChecking ,
435
+ CertPath : * certPath ,
436
+ RefreshPrometheusMetricsInterval : * refreshPrometheusMetricsInterval ,
437
+ MetricsStalenessThreshold : * metricsStalenessThreshold ,
438
+ Director : director ,
439
+ SaturationDetector : saturationDetector ,
440
+ LatencyPredictor : predictor ,
441
+ DestinationEndpointHintMetadataNamespace : * destinationEndpointHintMetadataNamespace ,
442
+ DestinationEndpointHintKey : * destinationEndpointHintKey ,
433
443
}
434
444
if err := serverRunner .SetupWithManager (ctx , mgr ); err != nil {
435
445
setupLog .Error (err , "Failed to setup EPP controllers" )
@@ -507,19 +517,19 @@ func (r *Runner) parsePluginsConfiguration(ctx context.Context) error {
507
517
508
518
func (r * Runner ) initializeScheduler (datastore datastore.Datastore , predictor * latencypredictor.Predictor ) (* scheduling.Scheduler , error ) {
509
519
if r .schedulerConfig != nil {
510
- return scheduling .NewSchedulerWithConfig (datastore , r .schedulerConfig ), nil
520
+ return scheduling .NewSchedulerWithConfig (r .schedulerConfig ), nil
511
521
}
512
522
513
523
// otherwise, no one configured from outside scheduler config. use existing configuration
514
- scheduler := scheduling .NewScheduler (datastore )
524
+ scheduler := scheduling .NewScheduler ()
515
525
if schedulerV2 {
516
526
queueScorerWeight := envutil .GetEnvInt ("QUEUE_SCORE_WEIGHT" , scorer .DefaultQueueScorerWeight , setupLog )
517
527
kvCacheScorerWeight := envutil .GetEnvInt ("KV_CACHE_SCORE_WEIGHT" , scorer .DefaultKVCacheScorerWeight , setupLog )
518
528
519
529
schedulerProfile := framework .NewSchedulerProfile ().
520
530
WithScorers (framework .NewWeightedScorer (scorer .NewQueueScorer (), queueScorerWeight ),
521
531
framework .NewWeightedScorer (scorer .NewKVCacheScorer (), kvCacheScorerWeight )).
522
- WithPicker (picker .NewMaxScorePicker ())
532
+ WithPicker (picker .NewMaxScorePicker (picker . DefaultMaxNumOfEndpoints ))
523
533
524
534
if prefixCacheScheduling {
525
535
prefixScorerWeight := envutil .GetEnvInt ("PREFIX_CACHE_SCORE_WEIGHT" , prefix .DefaultScorerWeight , setupLog )
@@ -529,16 +539,41 @@ func (r *Runner) initializeScheduler(datastore datastore.Datastore, predictor *l
529
539
}
530
540
531
541
schedulerConfig := scheduling .NewSchedulerConfig (profile .NewSingleProfileHandler (), map [string ]* framework.SchedulerProfile {"schedulerv2" : schedulerProfile })
532
- scheduler = scheduling .NewSchedulerWithConfig (datastore , schedulerConfig )
542
+ scheduler = scheduling .NewSchedulerWithConfig (schedulerConfig )
533
543
}
534
544
535
545
if reqHeaderBasedSchedulerForTesting {
536
- scheduler = conformance_epp .NewReqHeaderBasedScheduler (datastore )
546
+ scheduler = conformance_epp .NewReqHeaderBasedScheduler ()
537
547
}
538
548
539
549
return scheduler , nil
540
550
}
541
551
552
+ func (r * Runner ) parseConfiguration (ctx context.Context ) error {
553
+ if len (* configText ) != 0 || len (* configFile ) != 0 {
554
+ theConfig , err := loader .LoadConfig ([]byte (* configText ), * configFile )
555
+ if err != nil {
556
+ return fmt .Errorf ("failed to load the configuration - %w" , err )
557
+ }
558
+
559
+ epp := newEppHandle (ctx )
560
+
561
+ err = loader .LoadPluginReferences (theConfig .Plugins , epp )
562
+ if err != nil {
563
+ return fmt .Errorf ("failed to instantiate the plugins - %w" , err )
564
+ }
565
+
566
+ r .schedulerConfig , err = loader .LoadSchedulerConfig (theConfig .SchedulingProfiles , epp )
567
+ if err != nil {
568
+ return fmt .Errorf ("failed to create Scheduler configuration - %w" , err )
569
+ }
570
+
571
+ // Add requestControl plugins
572
+ r .requestControlConfig .AddPlugins (epp .Plugins ().GetAllPlugins ()... )
573
+ }
574
+ return nil
575
+ }
576
+
542
577
func initLogging (opts * zap.Options ) {
543
578
// Unless -zap-log-level is explicitly set, use -v
544
579
useV := true
@@ -652,3 +687,24 @@ func (p *predictorRunnable) Start(ctx context.Context) error {
652
687
p .predictor .Stop ()
653
688
return nil
654
689
}
690
+
691
+ // setupPprofHandlers only implements the pre-defined profiles:
692
+ // https://cs.opensource.google/go/go/+/refs/tags/go1.24.4:src/runtime/pprof/pprof.go;l=108
693
+ func setupPprofHandlers (mgr ctrl.Manager ) error {
694
+ var err error
695
+ profiles := []string {
696
+ "heap" ,
697
+ "goroutine" ,
698
+ "allocs" ,
699
+ "threadcreate" ,
700
+ "block" ,
701
+ "mutex" ,
702
+ }
703
+ for _ , p := range profiles {
704
+ err = mgr .AddMetricsServerExtraHandler ("/debug/pprof/" + p , pprof .Handler (p ))
705
+ if err != nil {
706
+ return err
707
+ }
708
+ }
709
+ return nil
710
+ }
0 commit comments