33package config
44
55import (
6- "math"
7-
86 "github.com/go-logr/logr"
97 "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/util/env"
108)
@@ -16,6 +14,10 @@ const (
1614 // - "PREFILL_ENABLE_" + pluginName Enables the named plugin for prefill processing
1715 // - "PREFILL_" + pluginName + "_WEIGHT" The weight for a scorer in prefill processing
1816
17+ prefillPrefix = "PREFILL_"
18+ enablePrefix = "ENABLE_"
19+ weightSuffix = "_WEIGHT"
20+
1921 // KVCacheScorerName name of the kv-cache scorer in configuration
2022 KVCacheScorerName = "KVCACHE_AWARE_SCORER"
2123 // LoadAwareScorerName name of the load aware scorer in configuration
@@ -25,10 +27,6 @@ const (
2527 // SessionAwareScorerName name of the session aware scorer in configuration
2628 SessionAwareScorerName = "SESSION_AWARE_SCORER"
2729
28- prefillPrefix = "PREFILL_"
29- enablePrefix = "ENABLE_"
30- weightSuffix = "_WEIGHT"
31-
3230 // Plugins from Upstream
3331
3432 // GIELeastKVCacheFilterName name of the GIE least kv-cache filter in configuration
@@ -58,47 +56,34 @@ const (
5856
5957// Config contains scheduler configuration, currently configuration is loaded from environment variables
6058type Config struct {
61- logger logr.Logger
6259 DecodeSchedulerPlugins map [string ]int
6360 PrefillSchedulerPlugins map [string ]int
64-
65- PDEnabled bool
66- PDThreshold int
67- PrefixBlockSize int
61+ PDEnabled bool
62+ PDThreshold int
63+ PrefixBlockSize int
6864}
6965
70- // NewConfig creates a new instance if Config
71- func NewConfig (logger logr.Logger ) * Config {
72- return & Config {
73- logger : logger ,
74- DecodeSchedulerPlugins : map [string ]int {},
75- PrefillSchedulerPlugins : map [string ]int {},
76- PDEnabled : false ,
77- PDThreshold : math .MaxInt ,
78- PrefixBlockSize : prefixScorerBlockSizeDefault ,
79- }
80- }
81-
82- // LoadConfig loads configuration from environment variables
83- func (c * Config ) LoadConfig () {
84- c .loadPluginInfo (c .DecodeSchedulerPlugins , false ,
85- KVCacheScorerName , LoadAwareScorerName , PrefixScorerName , SessionAwareScorerName ,
86- GIELeastKVCacheFilterName , GIELeastQueueFilterName , GIELoraAffinityFilterName ,
87- GIELowQueueFilterName , GIESheddableCapacityFilterName ,
88- GIEKVCacheUtilizationScorerName , GIEQueueScorerName , GIEPrefixScorerName )
89-
90- c .loadPluginInfo (c .PrefillSchedulerPlugins , true ,
66+ // LoadConfig loads configuration from environment variables and returns a new instance of Config
67+ func LoadConfig (logger logr.Logger ) * Config {
68+ pluginNames := []string {
9169 KVCacheScorerName , LoadAwareScorerName , PrefixScorerName , SessionAwareScorerName ,
9270 GIELeastKVCacheFilterName , GIELeastQueueFilterName , GIELoraAffinityFilterName ,
9371 GIELowQueueFilterName , GIESheddableCapacityFilterName ,
94- GIEKVCacheUtilizationScorerName , GIEQueueScorerName , GIEPrefixScorerName )
72+ GIEKVCacheUtilizationScorerName , GIEQueueScorerName , GIEPrefixScorerName ,
73+ }
9574
96- c .PDEnabled = env .GetEnvString (pdEnabledEnvKey , "false" , c .logger ) == "true"
97- c .PDThreshold = env .GetEnvInt (pdPromptLenThresholdEnvKey , pdPromptLenThresholdDefault , c .logger )
98- c .PrefixBlockSize = env .GetEnvInt (prefixScorerBlockSizeEnvKey , prefixScorerBlockSizeDefault , c .logger )
75+ return & Config {
76+ DecodeSchedulerPlugins : loadPluginInfo (logger , false , pluginNames ... ),
77+ PrefillSchedulerPlugins : loadPluginInfo (logger , true , pluginNames ... ),
78+ PDEnabled : env .GetEnvString (pdEnabledEnvKey , "false" , logger ) == "true" ,
79+ PDThreshold : env .GetEnvInt (pdPromptLenThresholdEnvKey , pdPromptLenThresholdDefault , logger ),
80+ PrefixBlockSize : env .GetEnvInt (prefixScorerBlockSizeEnvKey , prefixScorerBlockSizeDefault , logger ),
81+ }
9982}
10083
101- func (c * Config ) loadPluginInfo (plugins map [string ]int , prefill bool , pluginNames ... string ) {
84+ func loadPluginInfo (logger logr.Logger , prefill bool , pluginNames ... string ) map [string ]int {
85+ result := map [string ]int {}
86+
10287 for _ , pluginName := range pluginNames {
10388 var enablementKey string
10489 var weightKey string
@@ -110,13 +95,15 @@ func (c *Config) loadPluginInfo(plugins map[string]int, prefill bool, pluginName
11095 weightKey = pluginName + weightSuffix
11196 }
11297
113- if env .GetEnvString (enablementKey , "false" , c . logger ) != "true" {
114- c . logger .Info ("Skipping plugin creation as it is not enabled" , "name" , pluginName )
98+ if env .GetEnvString (enablementKey , "false" , logger ) != "true" {
99+ logger .Info ("Skipping plugin creation as it is not enabled" , "name" , pluginName )
115100 } else {
116- weight := env .GetEnvInt (weightKey , 1 , c . logger )
101+ weight := env .GetEnvInt (weightKey , 1 , logger )
117102
118- plugins [pluginName ] = weight
119- c . logger .Info ("Initialized plugin" , "plugin" , pluginName , "weight" , weight )
103+ result [pluginName ] = weight
104+ logger .Info ("Initialized plugin" , "plugin" , pluginName , "weight" , weight )
120105 }
121106 }
107+
108+ return result
122109}
0 commit comments