Skip to content

Commit cd0e626

Browse files
committed
some cleanup in runner and config loading + deprecation notes
Signed-off-by: Nir Rozenbaum <[email protected]>
1 parent 943e676 commit cd0e626

File tree

4 files changed

+30
-35
lines changed

4 files changed

+30
-35
lines changed

cmd/epp/runner/runner.go

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,15 @@ import (
7575

7676
const (
7777
// enableExperimentalDatalayerV2 defines the environment variable used as feature flag for the pluggable data layer.
78+
// DEPRECATION NOTICE - this env var will be depreacated in the next version as we switch into configuring EPP using FeatureGates in the config file.
7879
enableExperimentalDatalayerV2 = "ENABLE_EXPERIMENTAL_DATALAYER_V2"
7980
// enableExperimentalFlowControlLayer defines the environment variable used as a feature flag for the pluggable flow
8081
// control layer.
82+
// DEPRECATION NOTICE - this env var will be depreacated in the next version as we switch into configuring EPP using FeatureGates in the config file.
8183
enableExperimentalFlowControlLayer = "ENABLE_EXPERIMENTAL_FLOW_CONTROL_LAYER"
8284

8385
// Saturation Detector deprecated configuration environment variables
86+
// DEPRECATION NOTICE - these env vars will be depreacated in the next version as we switch into configuring EPP using FeatureGates in the config file.
8487
EnvSdQueueDepthThreshold = "SD_QUEUE_DEPTH_THRESHOLD"
8588
EnvSdKVCacheUtilThreshold = "SD_KV_CACHE_UTIL_THRESHOLD"
8689
EnvSdMetricsStalenessThreshold = "SD_METRICS_STALENESS_THRESHOLD"
@@ -144,13 +147,14 @@ func NewRunner() *Runner {
144147
return &Runner{
145148
eppExecutableName: "GIE",
146149
requestControlConfig: requestcontrol.NewConfig(), // default requestcontrol config has empty plugin list
150+
customCollectors: []prometheus.Collector{},
147151
}
148152
}
149153

150154
// Runner is used to run epp with its plugins
151155
type Runner struct {
152156
eppExecutableName string // the EPP executable name
153-
featureGates config.FeatureConfig
157+
featureGates map[string]bool
154158
requestControlConfig *requestcontrol.Config
155159
schedulerConfig *scheduling.SchedulerConfig
156160
customCollectors []prometheus.Collector
@@ -215,12 +219,11 @@ func (r *Runner) Run(ctx context.Context) error {
215219
return err
216220
}
217221

218-
rawConfig, featureGates, err := r.parseConfigurationPhaseOne(ctx)
222+
rawConfig, err := r.parseConfigurationPhaseOne(ctx)
219223
if err != nil {
220224
setupLog.Error(err, "Failed to parse configuration")
221225
return err
222226
}
223-
r.featureGates = featureGates
224227

225228
// --- Setup Datastore ---
226229
epf, err := r.setupMetricsCollection(setupLog, r.featureGates[datalayer.FeatureGate])
@@ -236,11 +239,8 @@ func (r *Runner) Run(ctx context.Context) error {
236239
}
237240

238241
// --- Setup Metrics Server ---
239-
customCollectors := []prometheus.Collector{collectors.NewInferencePoolMetricsCollector(datastore)}
240-
if r.customCollectors != nil {
241-
customCollectors = append(customCollectors, r.customCollectors...)
242-
}
243-
metrics.Register(customCollectors...)
242+
r.customCollectors = append(r.customCollectors, collectors.NewInferencePoolMetricsCollector(datastore))
243+
metrics.Register(r.customCollectors...)
244244
metrics.RecordInferenceExtensionInfo(version.CommitSHA, version.BuildRef)
245245
// Register metrics handler.
246246
// Metrics endpoint is enabled in 'config/default/kustomization.yaml'. The Metrics options configure the server.
@@ -341,13 +341,7 @@ func (r *Runner) Run(ctx context.Context) error {
341341
if err != nil {
342342
return fmt.Errorf("failed to initialize Flow Registry: %w", err)
343343
}
344-
fc, err := fccontroller.NewFlowController(
345-
ctx,
346-
fcCfg.Controller,
347-
registry,
348-
saturationDetector,
349-
setupLog,
350-
)
344+
fc, err := fccontroller.NewFlowController(ctx, fcCfg.Controller, registry, saturationDetector, setupLog)
351345
if err != nil {
352346
return fmt.Errorf("failed to initialize Flow Controller: %w", err)
353347
}
@@ -358,11 +352,7 @@ func (r *Runner) Run(ctx context.Context) error {
358352
admissionController = requestcontrol.NewLegacyAdmissionController(saturationDetector)
359353
}
360354

361-
director := requestcontrol.NewDirectorWithConfig(
362-
datastore,
363-
scheduler,
364-
admissionController,
365-
r.requestControlConfig)
355+
director := requestcontrol.NewDirectorWithConfig(datastore, scheduler, admissionController, r.requestControlConfig)
366356

367357
// --- Setup ExtProc Server Runner ---
368358
serverRunner := &runserver.ExtProcServerRunner{
@@ -420,9 +410,9 @@ func (r *Runner) registerInTreePlugins() {
420410
plugins.Register(testfilter.HeaderBasedTestingFilterType, testfilter.HeaderBasedTestingFilterFactory)
421411
}
422412

423-
func (r *Runner) parseConfigurationPhaseOne(ctx context.Context) (*configapi.EndpointPickerConfig, config.FeatureConfig, error) {
413+
func (r *Runner) parseConfigurationPhaseOne(ctx context.Context) (*configapi.EndpointPickerConfig, error) {
424414
if *configText == "" && *configFile == "" {
425-
return nil, nil, nil // configuring through code, not through file
415+
return nil, nil // configuring through code, not through file
426416
}
427417

428418
logger := log.FromContext(ctx)
@@ -434,7 +424,7 @@ func (r *Runner) parseConfigurationPhaseOne(ctx context.Context) (*configapi.End
434424
var err error
435425
configBytes, err = os.ReadFile(*configFile)
436426
if err != nil {
437-
return nil, nil, fmt.Errorf("failed to load config from a file '%s' - %w", *configFile, err)
427+
return nil, fmt.Errorf("failed to load config from a file '%s' - %w", *configFile, err)
438428
}
439429
}
440430

@@ -443,7 +433,14 @@ func (r *Runner) parseConfigurationPhaseOne(ctx context.Context) (*configapi.End
443433

444434
r.registerInTreePlugins()
445435

446-
return loader.LoadConfigPhaseOne(configBytes, logger)
436+
rawConfig, featureGates, err := loader.LoadConfigPhaseOne(configBytes, logger)
437+
if err != nil {
438+
return nil, fmt.Errorf("failed to parse config - %w", err)
439+
}
440+
441+
r.featureGates = featureGates
442+
443+
return rawConfig, nil
447444
}
448445

449446
func (r *Runner) parseConfigurationPhaseTwo(ctx context.Context, rawConfig *configapi.EndpointPickerConfig, ds datastore.Datastore) (*config.Config, error) {
@@ -471,33 +468,33 @@ func (r *Runner) deprecatedConfigurationHelper(cfg *config.Config, logger logr.L
471468
// Handle deprecated environment variable based feature flags
472469

473470
if _, ok := os.LookupEnv(enableExperimentalDatalayerV2); ok {
474-
logger.Info("Enabling the experimental Data Layer V2 using environment variables is deprecated")
471+
logger.Info("Enabling the experimental Data Layer V2 using environment variables is deprecated and will be removed in next version")
475472
r.featureGates[datalayer.FeatureGate] = env.GetEnvBool(enableExperimentalDatalayerV2, false, logger)
476473
}
477474
if _, ok := os.LookupEnv(enableExperimentalFlowControlLayer); ok {
478-
logger.Info("Enabling the experimental Flow Control layer using environment variables is deprecated")
475+
logger.Info("Enabling the experimental Flow Control layer using environment variables is deprecated and will be removed in next version")
479476
r.featureGates[flowcontrol.FeatureGate] = env.GetEnvBool(enableExperimentalFlowControlLayer, false, setupLog)
480477
}
481478

482479
// Handle deprecated environment variable base Saturation Detector configuration
483480

484481
if _, ok := os.LookupEnv(EnvSdQueueDepthThreshold); ok {
485-
logger.Info("Configuring Saturation Detector using environment variables is deprecated")
482+
logger.Info("Configuring Saturation Detector using environment variables is deprecated and will be removed in next version")
486483
cfg.SaturationDetectorConfig.QueueDepthThreshold =
487484
env.GetEnvInt(EnvSdQueueDepthThreshold, saturationdetector.DefaultQueueDepthThreshold, logger)
488485
if cfg.SaturationDetectorConfig.QueueDepthThreshold <= 0 {
489486
cfg.SaturationDetectorConfig.QueueDepthThreshold = saturationdetector.DefaultQueueDepthThreshold
490487
}
491488
}
492489
if _, ok := os.LookupEnv(EnvSdKVCacheUtilThreshold); ok {
493-
logger.Info("Configuring Saturation Detector using environment variables is deprecated")
490+
logger.Info("Configuring Saturation Detector using environment variables is deprecated and will be removed in next version")
494491
cfg.SaturationDetectorConfig.KVCacheUtilThreshold = env.GetEnvFloat(EnvSdKVCacheUtilThreshold, saturationdetector.DefaultKVCacheUtilThreshold, logger)
495492
if cfg.SaturationDetectorConfig.KVCacheUtilThreshold <= 0 || cfg.SaturationDetectorConfig.KVCacheUtilThreshold >= 1 {
496493
cfg.SaturationDetectorConfig.KVCacheUtilThreshold = saturationdetector.DefaultKVCacheUtilThreshold
497494
}
498495
}
499496
if _, ok := os.LookupEnv(EnvSdMetricsStalenessThreshold); ok {
500-
logger.Info("Configuring Saturation Detector using environment variables is deprecated")
497+
logger.Info("Configuring Saturation Detector using environment variables is deprecated and will be removed in next version")
501498
cfg.SaturationDetectorConfig.MetricsStalenessThreshold = env.GetEnvDuration(EnvSdMetricsStalenessThreshold, saturationdetector.DefaultMetricsStalenessThreshold, logger)
502499
if cfg.SaturationDetectorConfig.MetricsStalenessThreshold <= 0 {
503500
cfg.SaturationDetectorConfig.MetricsStalenessThreshold = saturationdetector.DefaultMetricsStalenessThreshold

pkg/epp/config/config.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,3 @@ type Config struct {
2626
SchedulerConfig *scheduling.SchedulerConfig
2727
SaturationDetectorConfig *saturationdetector.Config
2828
}
29-
30-
type FeatureConfig map[string]bool

pkg/epp/config/loader/configloader.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ import (
3737

3838
var scheme = runtime.NewScheme()
3939

40-
var registeredFeatureGates = map[string]struct{}{}
40+
var registeredFeatureGates = sets.New[string]() // set of feature gates names, a name must be unique
4141

4242
func init() {
4343
utilruntime.Must(configapi.Install(scheme))
4444
}
4545

4646
// LoadConfigPhaseOne first phase of loading configuration from supplied text that was converted to []byte
47-
func LoadConfigPhaseOne(configBytes []byte, logger logr.Logger) (*configapi.EndpointPickerConfig, config.FeatureConfig, error) {
47+
func LoadConfigPhaseOne(configBytes []byte, logger logr.Logger) (*configapi.EndpointPickerConfig, map[string]bool, error) {
4848
rawConfig, err := loadRawConfig(configBytes)
4949
if err != nil {
5050
return nil, nil, err
@@ -201,5 +201,5 @@ func instantiatePlugins(configuredPlugins []configapi.PluginSpec, handle plugins
201201

202202
// RegisterFeatureGate registers feature gate keys for validation
203203
func RegisterFeatureGate(gate string) {
204-
registeredFeatureGates[gate] = struct{}{}
204+
registeredFeatureGates.Insert(gate)
205205
}

pkg/epp/config/loader/validation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func validateFeatureGates(fg configapi.FeatureGates) error {
6262
}
6363

6464
for _, gate := range fg {
65-
if _, ok := registeredFeatureGates[gate]; !ok {
65+
if !registeredFeatureGates.Has(gate) {
6666
return errors.New(gate + " is an unregistered Feature Gate")
6767
}
6868
}

0 commit comments

Comments
 (0)