Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions cmd/plugins/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func main() {
remoteTokenizerEnabled := utils.LoadEnvBool(constants.EnvPrefixCacheUseRemoteTokenizer, false)

cache.InitWithOptions(config, stopCh, cache.InitOptions{
IsGateway: true,
EnableKVSync: kvSyncEnabled && remoteTokenizerEnabled,
RedisClient: redisClient,
ModelRouterProvider: routing.ModelRouterFactory,
Expand Down
24 changes: 16 additions & 8 deletions pkg/cache/cache_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ var (

// InitOptions configures the cache initialization behavior
type InitOptions struct {
// IsGateway marks the caller as the gateway-plugins service.
IsGateway bool

// EnableKVSync configures whether to start the ZMQ KV event sync
EnableKVSync bool

Expand Down Expand Up @@ -325,14 +328,7 @@ func InitForTest() *Store {
func InitWithOptions(config *rest.Config, stopCh <-chan struct{}, opts InitOptions) *Store {
once.Do(func() {
// Log initialization based on configuration
var service string
if opts.EnableKVSync {
service = "gateway"
} else if opts.RedisClient != nil {
service = "metadata"
} else {
service = "controllers"
}
service := serviceIdentity(opts)

klog.InfoS("initialize cache",
"service", service,
Expand Down Expand Up @@ -394,6 +390,18 @@ func InitWithOptions(config *rest.Config, stopCh <-chan struct{}, opts InitOptio
return store
}

// serviceIdentity returns the component identity implied by opts.
func serviceIdentity(opts InitOptions) string {
switch {
case opts.IsGateway:
return "gateway"
case opts.RedisClient != nil:
return "metadata"
default:
return "controllers"
}
}

// initMetricsCache initializes metrics cache update loop
// Parameters:
//
Expand Down
51 changes: 51 additions & 0 deletions pkg/cache/cache_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,54 @@ func TestInitWithOptions_KVSyncBehavior(t *testing.T) {
})
}
}

func TestServiceIdentity(t *testing.T) {
scenarios := []struct {
name string
opts InitOptions
expected string
}{
{
name: "gateway without redis",
opts: InitOptions{
IsGateway: true,
},
expected: "gateway",
},
{
name: "gateway with KV sync disabled is still the gateway",
opts: InitOptions{
IsGateway: true,
EnableKVSync: false,
RedisClient: &redis.Client{},
},
expected: "gateway",
},
{
name: "metadata service",
opts: InitOptions{
RedisClient: &redis.Client{},
},
expected: "metadata",
},
{
name: "EnableKVSync alone does not imply gateway",
opts: InitOptions{
EnableKVSync: true,
RedisClient: &redis.Client{},
},
expected: "metadata",
},
{
name: "controllers",
opts: InitOptions{},
expected: "controllers",
},
}

for _, sc := range scenarios {
t.Run(sc.name, func(t *testing.T) {
assert.Equal(t, sc.expected, serviceIdentity(sc.opts))
})
}
}