diff --git a/pkg/agent/sysadvisor/plugin/inference/inference.go b/pkg/agent/sysadvisor/plugin/inference/inference.go index ac19c8b95..1248250af 100644 --- a/pkg/agent/sysadvisor/plugin/inference/inference.go +++ b/pkg/agent/sysadvisor/plugin/inference/inference.go @@ -86,6 +86,9 @@ func NewInferencePlugin(pluginName string, conf *config.Configuration, extraConf fetcher, err := initFn(fetcherName, conf, extraConf, emitterPool, metaServer, metaCache) if err != nil { return nil, fmt.Errorf("failed to start sysadvisor plugin %v: %v", pluginName, err) + } else if fetcher == nil { + general.Infof("fetcher: %s isn't enabled", fetcherName) + continue } inferencePlugin.modelsResultFetchers[fetcherName] = fetcher diff --git a/pkg/agent/sysadvisor/plugin/inference/inference_test.go b/pkg/agent/sysadvisor/plugin/inference/inference_test.go index a3435549b..85402469d 100644 --- a/pkg/agent/sysadvisor/plugin/inference/inference_test.go +++ b/pkg/agent/sysadvisor/plugin/inference/inference_test.go @@ -31,6 +31,12 @@ import ( metricspool "github.com/kubewharf/katalyst-core/pkg/metrics/metrics-pool" ) +func NewNilModelResultFetcher(fetcherName string, conf *config.Configuration, extraConf interface{}, + emitterPool metricspool.MetricsEmitterPool, metaServer *metaserver.MetaServer, + metaCache metacache.MetaCache) (modelresultfetcher.ModelResultFetcher, error) { + return nil, nil +} + func TestNewInferencePlugin(t *testing.T) { t.Parallel() type args struct { @@ -63,6 +69,8 @@ func TestNewInferencePlugin(t *testing.T) { modelresultfetcher.RegisterModelResultFetcherInitFunc(borweinfetcher.BorweinModelResultFetcherName, modelresultfetcher.NewDummyModelResultFetcher) + modelresultfetcher.RegisterModelResultFetcherInitFunc("test-nil-fetcher", + NewNilModelResultFetcher) for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/pkg/agent/sysadvisor/plugin/inference/modelresultfetcher/borwein/borwein.go b/pkg/agent/sysadvisor/plugin/inference/modelresultfetcher/borwein/borwein.go index 4fb59c7e0..98f900740 100644 --- a/pkg/agent/sysadvisor/plugin/inference/modelresultfetcher/borwein/borwein.go +++ b/pkg/agent/sysadvisor/plugin/inference/modelresultfetcher/borwein/borwein.go @@ -322,6 +322,8 @@ func NewBorweinModelResultFetcher(fetcherName string, conf *config.Configuration metaCache metacache.MetaCache) (modelresultfetcher.ModelResultFetcher, error) { if conf == nil || conf.BorweinConfiguration == nil { return nil, fmt.Errorf("nil conf") + } else if !conf.PolicyRama.EnableBorwein { + return nil, nil } else if metaServer == nil { return nil, fmt.Errorf("nil metaServer") } else if metaCache == nil { diff --git a/pkg/agent/sysadvisor/plugin/inference/modelresultfetcher/borwein/borwein_test.go b/pkg/agent/sysadvisor/plugin/inference/modelresultfetcher/borwein/borwein_test.go index a2449dffd..89b3a2047 100644 --- a/pkg/agent/sysadvisor/plugin/inference/modelresultfetcher/borwein/borwein_test.go +++ b/pkg/agent/sysadvisor/plugin/inference/modelresultfetcher/borwein/borwein_test.go @@ -683,6 +683,7 @@ func TestNewBorweinModelResultFetcher(t *testing.T) { type args struct { fetcherName string + enableBorwein bool conf *config.Configuration extraConf interface{} emitterPool metricspool.MetricsEmitterPool @@ -700,6 +701,7 @@ func TestNewBorweinModelResultFetcher(t *testing.T) { name: "test normal new borwein model result fetcher", args: args{ fetcherName: BorweinModelResultFetcherName, + enableBorwein: true, conf: conf, emitterPool: metricspool.DummyMetricsEmitterPool{}, metaServer: metaServer, @@ -711,11 +713,12 @@ func TestNewBorweinModelResultFetcher(t *testing.T) { { name: "test new borwein with nil conf", args: args{ - fetcherName: BorweinModelResultFetcherName, - conf: nil, - emitterPool: metricspool.DummyMetricsEmitterPool{}, - metaServer: metaServer, - metaCache: mc, + fetcherName: BorweinModelResultFetcherName, + enableBorwein: true, + conf: nil, + emitterPool: metricspool.DummyMetricsEmitterPool{}, + metaServer: metaServer, + metaCache: mc, }, wantErr: true, }, @@ -723,6 +726,7 @@ func TestNewBorweinModelResultFetcher(t *testing.T) { name: "test new borwein with nil metaServer", args: args{ fetcherName: BorweinModelResultFetcherName, + enableBorwein: true, conf: conf, emitterPool: metricspool.DummyMetricsEmitterPool{}, metaServer: nil, @@ -735,6 +739,7 @@ func TestNewBorweinModelResultFetcher(t *testing.T) { name: "test new borwein with nil metacache", args: args{ fetcherName: BorweinModelResultFetcherName, + enableBorwein: true, conf: conf, emitterPool: metricspool.DummyMetricsEmitterPool{}, metaServer: metaServer, @@ -743,9 +748,25 @@ func TestNewBorweinModelResultFetcher(t *testing.T) { }, wantErr: true, }, + { + name: "test new borwein fetcher with enableBorwein false", + args: args{ + fetcherName: BorweinModelResultFetcherName, + enableBorwein: false, + conf: conf, + emitterPool: metricspool.DummyMetricsEmitterPool{}, + metaServer: metaServer, + metaCache: nil, + inferenceServiceSocketAbsPath: path.Join(sockDir, "test.sock"), + }, + wantErr: false, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + if tt.args.conf != nil { + tt.args.conf.PolicyRama.EnableBorwein = tt.args.enableBorwein + } var svr *grpc.Server if tt.args.inferenceServiceSocketAbsPath != "" { @@ -754,9 +775,18 @@ func TestNewBorweinModelResultFetcher(t *testing.T) { conf.BorweinConfiguration.InferenceServiceSocketAbsPath = tt.args.inferenceServiceSocketAbsPath } - _, err := NewBorweinModelResultFetcher(tt.args.fetcherName, tt.args.conf, tt.args.extraConf, tt.args.emitterPool, tt.args.metaServer, tt.args.metaCache) + fetcher, err := NewBorweinModelResultFetcher(tt.args.fetcherName, tt.args.conf, tt.args.extraConf, tt.args.emitterPool, tt.args.metaServer, tt.args.metaCache) if (err != nil) != tt.wantErr { t.Errorf("NewBorweinModelResultFetcher() error = %v, wantErr %v", err, tt.wantErr) + if svr != nil { + svr.Stop() + } + return + } else if !tt.args.enableBorwein { + require.Nil(t, fetcher) + if svr != nil { + svr.Stop() + } return }