Skip to content

Commit cbe46d7

Browse files
committed
kvcache-aware-scorer fails on misconfig
Signed-off-by: Maroon Ayoub <[email protected]>
1 parent 83a91a6 commit cbe46d7

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

pkg/epp/scheduling/plugins/scorers/kvcache-aware-scorer.go

+15-13
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import (
3434
const (
3535
kvCacheAwareScorerName = "KVCacheAwareScorer"
3636
cacheStalenessThreshold = 5 * time.Second
37+
kvCacheRedisEnvVar = "KVCACHE_INDEXER_REDIS_ADDR"
38+
huggingFaceTokenEnvVar = "HF_TOKEN"
3739
)
3840

3941
// KVCacheAwareScorer is a concrete implementation of the Scorer interface.
@@ -45,29 +47,29 @@ type KVCacheAwareScorer struct {
4547
scoresCacheLastUpdate time.Time
4648
}
4749

48-
func kvCacheIndexerConfigFromEnv() *kvcache.Config {
50+
// NewKVCacheAwareScorer creates a new KVCacheAwareScorer instance.
51+
// It initializes the KVCacheIndexer with the provided configuration,
52+
// and runs it with the given context.
53+
//
54+
// If the configuration is nil, it uses the default configuration.
55+
func NewKVCacheAwareScorer(ctx context.Context) (types.Scorer, error) {
4956
config := kvcache.NewDefaultConfig()
5057

51-
redisAddr := os.Getenv("KVCACHE_INDEXER_REDIS_ADDR")
58+
redisAddr := os.Getenv(kvCacheRedisEnvVar)
5259
if redisAddr != "" {
5360
config.KVBlockIndexerConfig.RedisKVBlockIndexerConfig.RedisAddr = redisAddr
61+
} else {
62+
return nil, fmt.Errorf("environment variable %s is not set", kvCacheRedisEnvVar)
5463
}
5564

56-
hfToken := os.Getenv("HF_TOKEN")
65+
hfToken := os.Getenv(huggingFaceTokenEnvVar)
5766
if hfToken != "" {
5867
config.TokenizersPoolConfig.HFTokenizerConfig.HuggingFaceToken = hfToken
68+
} else {
69+
return nil, fmt.Errorf("environment variable %s is not set", huggingFaceTokenEnvVar)
5970
}
6071

61-
return config
62-
}
63-
64-
// NewKVCacheAwareScorer creates a new KVCacheAwareScorer instance.
65-
// It initializes the KVCacheIndexer with the provided configuration,
66-
// and runs it with the given context.
67-
//
68-
// If the configuration is nil, it uses the default configuration.
69-
func NewKVCacheAwareScorer(ctx context.Context) (types.Scorer, error) {
70-
kvCacheIndexer, err := kvcache.NewKVCacheIndexer(kvCacheIndexerConfigFromEnv())
72+
kvCacheIndexer, err := kvcache.NewKVCacheIndexer(config)
7173
if err != nil {
7274
return nil, fmt.Errorf("failed to create KVCacheIndexer: %w", err)
7375
}

0 commit comments

Comments
 (0)