From e4ece18b0f9f93c4dd2423155ead0b68f785cd29 Mon Sep 17 00:00:00 2001 From: Future-Outlier Date: Wed, 4 Oct 2023 12:24:13 +0800 Subject: [PATCH] Revert "Add supportTaskTypes for agentservice without write it in config twice. (#398)" (#412) This reverts commit 2598c96063b07bc70e0d11ba954905fbe77949d8. Signed-off-by: Future Outlier --- go/tasks/plugins/webapi/agent/config.go | 4 ++++ go/tasks/plugins/webapi/agent/integration_test.go | 2 +- go/tasks/plugins/webapi/agent/plugin.go | 12 ++++-------- go/tasks/plugins/webapi/agent/plugin_test.go | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/go/tasks/plugins/webapi/agent/config.go b/go/tasks/plugins/webapi/agent/config.go index fb369b380..58355c5ee 100644 --- a/go/tasks/plugins/webapi/agent/config.go +++ b/go/tasks/plugins/webapi/agent/config.go @@ -44,6 +44,7 @@ var ( Insecure: true, DefaultTimeout: config.Duration{Duration: 10 * time.Second}, }, + SupportedTaskTypes: []string{"task_type_1", "task_type_2"}, } configSection = pluginsConfig.MustRegisterSubSection("agent-service", &defaultConfig) @@ -65,6 +66,9 @@ type Config struct { // Maps task types to their agents. {TaskType: AgentId} AgentForTaskTypes map[string]string `json:"agentForTaskTypes" pflag:"-,"` + + // SupportedTaskTypes is a list of task types that are supported by this plugin. + SupportedTaskTypes []string `json:"supportedTaskTypes" pflag:"-,Defines a list of task types that are supported by this plugin."` } type Agent struct { diff --git a/go/tasks/plugins/webapi/agent/integration_test.go b/go/tasks/plugins/webapi/agent/integration_test.go index 8cf64f478..f66c5f733 100644 --- a/go/tasks/plugins/webapi/agent/integration_test.go +++ b/go/tasks/plugins/webapi/agent/integration_test.go @@ -161,7 +161,7 @@ func TestEndToEnd(t *testing.T) { tr.OnRead(context.Background()).Return(nil, fmt.Errorf("read fail")) tCtx.OnTaskReader().Return(tr) - agentPlugin := newAgentPlugin(SupportedTaskTypes{}) + agentPlugin := newAgentPlugin() pluginEntry := pluginmachinery.CreateRemotePlugin(agentPlugin) plugin, err := pluginEntry.LoadPlugin(context.TODO(), newFakeSetupContext("test3")) assert.NoError(t, err) diff --git a/go/tasks/plugins/webapi/agent/plugin.go b/go/tasks/plugins/webapi/agent/plugin.go index 9e663319e..0153d9dc1 100644 --- a/go/tasks/plugins/webapi/agent/plugin.go +++ b/go/tasks/plugins/webapi/agent/plugin.go @@ -29,8 +29,6 @@ import ( type GetClientFunc func(ctx context.Context, agent *Agent, connectionCache map[*Agent]*grpc.ClientConn) (service.AsyncAgentServiceClient, error) -type TaskType = string -type SupportedTaskTypes []TaskType type Plugin struct { metricScope promutils.Scope cfg *Config @@ -298,10 +296,8 @@ func getFinalContext(ctx context.Context, operation string, agent *Agent) (conte return context.WithTimeout(ctx, timeout) } -func newAgentPlugin(supportedTaskTypes SupportedTaskTypes) webapi.PluginEntry { - if len(supportedTaskTypes) == 0 { - supportedTaskTypes = SupportedTaskTypes{"default_supported_task_type"} - } +func newAgentPlugin() webapi.PluginEntry { + supportedTaskTypes := GetConfig().SupportedTaskTypes return webapi.PluginEntry{ ID: "agent-service", @@ -317,9 +313,9 @@ func newAgentPlugin(supportedTaskTypes SupportedTaskTypes) webapi.PluginEntry { } } -func RegisterAgentPlugin(supportedTaskTypes SupportedTaskTypes) { +func RegisterAgentPlugin() { gob.Register(ResourceMetaWrapper{}) gob.Register(ResourceWrapper{}) - pluginmachinery.PluginRegistry().RegisterRemotePlugin(newAgentPlugin(supportedTaskTypes)) + pluginmachinery.PluginRegistry().RegisterRemotePlugin(newAgentPlugin()) } diff --git a/go/tasks/plugins/webapi/agent/plugin_test.go b/go/tasks/plugins/webapi/agent/plugin_test.go index 3c413bf37..bf9e25e20 100644 --- a/go/tasks/plugins/webapi/agent/plugin_test.go +++ b/go/tasks/plugins/webapi/agent/plugin_test.go @@ -43,7 +43,7 @@ func TestPlugin(t *testing.T) { }) t.Run("test newAgentPlugin", func(t *testing.T) { - p := newAgentPlugin(SupportedTaskTypes{}) + p := newAgentPlugin() assert.NotNil(t, p) assert.Equal(t, "agent-service", p.ID) assert.NotNil(t, p.PluginLoader)