Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 26 additions & 29 deletions cmd/epp/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,15 @@ import (

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

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

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

rawConfig, featureGates, err := r.parseConfigurationPhaseOne(ctx)
rawConfig, err := r.parseConfigurationPhaseOne(ctx)
if err != nil {
setupLog.Error(err, "Failed to parse configuration")
return err
}
r.featureGates = featureGates

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

// --- Setup Metrics Server ---
customCollectors := []prometheus.Collector{collectors.NewInferencePoolMetricsCollector(datastore)}
if r.customCollectors != nil {
customCollectors = append(customCollectors, r.customCollectors...)
Comment on lines -239 to -241
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a bug -
if custom collectors were used, the collector that emits the EPP's commit sha and version was not registered.

}
metrics.Register(customCollectors...)
r.customCollectors = append(r.customCollectors, collectors.NewInferencePoolMetricsCollector(datastore))
metrics.Register(r.customCollectors...)
metrics.RecordInferenceExtensionInfo(version.CommitSHA, version.BuildRef)
// Register metrics handler.
// Metrics endpoint is enabled in 'config/default/kustomization.yaml'. The Metrics options configure the server.
Expand Down Expand Up @@ -341,13 +341,7 @@ func (r *Runner) Run(ctx context.Context) error {
if err != nil {
return fmt.Errorf("failed to initialize Flow Registry: %w", err)
}
fc, err := fccontroller.NewFlowController(
ctx,
fcCfg.Controller,
registry,
saturationDetector,
setupLog,
)
fc, err := fccontroller.NewFlowController(ctx, fcCfg.Controller, registry, saturationDetector, setupLog)
if err != nil {
return fmt.Errorf("failed to initialize Flow Controller: %w", err)
}
Expand All @@ -358,11 +352,7 @@ func (r *Runner) Run(ctx context.Context) error {
admissionController = requestcontrol.NewLegacyAdmissionController(saturationDetector)
}

director := requestcontrol.NewDirectorWithConfig(
datastore,
scheduler,
admissionController,
r.requestControlConfig)
director := requestcontrol.NewDirectorWithConfig(datastore, scheduler, admissionController, r.requestControlConfig)

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

func (r *Runner) parseConfigurationPhaseOne(ctx context.Context) (*configapi.EndpointPickerConfig, config.FeatureConfig, error) {
func (r *Runner) parseConfigurationPhaseOne(ctx context.Context) (*configapi.EndpointPickerConfig, error) {
if *configText == "" && *configFile == "" {
return nil, nil, nil // configuring through code, not through file
return nil, nil // configuring through code, not through file
}

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

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

r.registerInTreePlugins()

return loader.LoadConfigPhaseOne(configBytes, logger)
rawConfig, featureGates, err := loader.LoadConfigPhaseOne(configBytes, logger)
if err != nil {
return nil, fmt.Errorf("failed to parse config - %w", err)
}

r.featureGates = featureGates

return rawConfig, nil
}

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

if _, ok := os.LookupEnv(enableExperimentalDatalayerV2); ok {
logger.Info("Enabling the experimental Data Layer V2 using environment variables is deprecated")
logger.Info("Enabling the experimental Data Layer V2 using environment variables is deprecated and will be removed in next version")
r.featureGates[datalayer.FeatureGate] = env.GetEnvBool(enableExperimentalDatalayerV2, false, logger)
}
if _, ok := os.LookupEnv(enableExperimentalFlowControlLayer); ok {
logger.Info("Enabling the experimental Flow Control layer using environment variables is deprecated")
logger.Info("Enabling the experimental Flow Control layer using environment variables is deprecated and will be removed in next version")
r.featureGates[flowcontrol.FeatureGate] = env.GetEnvBool(enableExperimentalFlowControlLayer, false, setupLog)
}

// Handle deprecated environment variable base Saturation Detector configuration

if _, ok := os.LookupEnv(EnvSdQueueDepthThreshold); ok {
logger.Info("Configuring Saturation Detector using environment variables is deprecated")
logger.Info("Configuring Saturation Detector using environment variables is deprecated and will be removed in next version")
cfg.SaturationDetectorConfig.QueueDepthThreshold =
env.GetEnvInt(EnvSdQueueDepthThreshold, saturationdetector.DefaultQueueDepthThreshold, logger)
if cfg.SaturationDetectorConfig.QueueDepthThreshold <= 0 {
cfg.SaturationDetectorConfig.QueueDepthThreshold = saturationdetector.DefaultQueueDepthThreshold
}
}
if _, ok := os.LookupEnv(EnvSdKVCacheUtilThreshold); ok {
logger.Info("Configuring Saturation Detector using environment variables is deprecated")
logger.Info("Configuring Saturation Detector using environment variables is deprecated and will be removed in next version")
cfg.SaturationDetectorConfig.KVCacheUtilThreshold = env.GetEnvFloat(EnvSdKVCacheUtilThreshold, saturationdetector.DefaultKVCacheUtilThreshold, logger)
if cfg.SaturationDetectorConfig.KVCacheUtilThreshold <= 0 || cfg.SaturationDetectorConfig.KVCacheUtilThreshold >= 1 {
cfg.SaturationDetectorConfig.KVCacheUtilThreshold = saturationdetector.DefaultKVCacheUtilThreshold
}
}
if _, ok := os.LookupEnv(EnvSdMetricsStalenessThreshold); ok {
logger.Info("Configuring Saturation Detector using environment variables is deprecated")
logger.Info("Configuring Saturation Detector using environment variables is deprecated and will be removed in next version")
cfg.SaturationDetectorConfig.MetricsStalenessThreshold = env.GetEnvDuration(EnvSdMetricsStalenessThreshold, saturationdetector.DefaultMetricsStalenessThreshold, logger)
if cfg.SaturationDetectorConfig.MetricsStalenessThreshold <= 0 {
cfg.SaturationDetectorConfig.MetricsStalenessThreshold = saturationdetector.DefaultMetricsStalenessThreshold
Expand Down
2 changes: 0 additions & 2 deletions pkg/epp/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,3 @@ type Config struct {
SchedulerConfig *scheduling.SchedulerConfig
SaturationDetectorConfig *saturationdetector.Config
}

type FeatureConfig map[string]bool
6 changes: 3 additions & 3 deletions pkg/epp/config/loader/configloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ import (

var scheme = runtime.NewScheme()

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

func init() {
utilruntime.Must(configapi.Install(scheme))
}

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

// RegisterFeatureGate registers feature gate keys for validation
func RegisterFeatureGate(gate string) {
registeredFeatureGates[gate] = struct{}{}
registeredFeatureGates.Insert(gate)
}
2 changes: 1 addition & 1 deletion pkg/epp/config/loader/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func validateFeatureGates(fg configapi.FeatureGates) error {
}

for _, gate := range fg {
if _, ok := registeredFeatureGates[gate]; !ok {
if !registeredFeatureGates.Has(gate) {
return errors.New(gate + " is an unregistered Feature Gate")
}
}
Expand Down