From 88be4566ba684dc76267680989f6c40741930a8b Mon Sep 17 00:00:00 2001 From: Future Outlier Date: Sat, 2 Sep 2023 19:44:11 +0800 Subject: [PATCH 1/3] Add supportTaskTypes for agentservice without write 2 times 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 58355c5ee..fb369b380 100644 --- a/go/tasks/plugins/webapi/agent/config.go +++ b/go/tasks/plugins/webapi/agent/config.go @@ -44,7 +44,6 @@ var ( Insecure: true, DefaultTimeout: config.Duration{Duration: 10 * time.Second}, }, - SupportedTaskTypes: []string{"task_type_1", "task_type_2"}, } configSection = pluginsConfig.MustRegisterSubSection("agent-service", &defaultConfig) @@ -66,9 +65,6 @@ 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 0aeed67f5..146989dc8 100644 --- a/go/tasks/plugins/webapi/agent/integration_test.go +++ b/go/tasks/plugins/webapi/agent/integration_test.go @@ -153,7 +153,7 @@ func TestEndToEnd(t *testing.T) { tr.OnRead(context.Background()).Return(nil, fmt.Errorf("read fail")) tCtx.OnTaskReader().Return(tr) - agentPlugin := newAgentPlugin() + agentPlugin := newAgentPlugin(SupportedTaskTypes{}) 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 128753b74..c5b7b5160 100644 --- a/go/tasks/plugins/webapi/agent/plugin.go +++ b/go/tasks/plugins/webapi/agent/plugin.go @@ -27,6 +27,8 @@ 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 @@ -266,8 +268,10 @@ func getFinalContext(ctx context.Context, operation string, agent *Agent) (conte return context.WithTimeout(ctx, timeout) } -func newAgentPlugin() webapi.PluginEntry { - supportedTaskTypes := GetConfig().SupportedTaskTypes +func newAgentPlugin(supportedTaskTypes SupportedTaskTypes) webapi.PluginEntry { + if len(supportedTaskTypes) == 0 { + supportedTaskTypes = SupportedTaskTypes{"default_supported_task_type"} + } return webapi.PluginEntry{ ID: "agent-service", @@ -283,9 +287,9 @@ func newAgentPlugin() webapi.PluginEntry { } } -func RegisterAgentPlugin() { +func RegisterAgentPlugin(supportedTaskTypes SupportedTaskTypes) { gob.Register(ResourceMetaWrapper{}) gob.Register(ResourceWrapper{}) - pluginmachinery.PluginRegistry().RegisterRemotePlugin(newAgentPlugin()) + pluginmachinery.PluginRegistry().RegisterRemotePlugin(newAgentPlugin(supportedTaskTypes)) } diff --git a/go/tasks/plugins/webapi/agent/plugin_test.go b/go/tasks/plugins/webapi/agent/plugin_test.go index 180a0d6e6..abd10d2d8 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("tet newAgentPlugin", func(t *testing.T) { - p := newAgentPlugin() + p := newAgentPlugin(SupportedTaskTypes{}) assert.NotNil(t, p) assert.Equal(t, "agent-service", p.ID) assert.NotNil(t, p.PluginLoader) From 147e92905601dbd3db1eea2bfb6e7bf9abbfd027 Mon Sep 17 00:00:00 2001 From: Future Outlier Date: Thu, 21 Sep 2023 06:54:34 +0800 Subject: [PATCH 2/3] fix conflict Signed-off-by: Future Outlier --- go/tasks/plugins/webapi/agent/plugin_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/tasks/plugins/webapi/agent/plugin_test.go b/go/tasks/plugins/webapi/agent/plugin_test.go index 180a0d6e6..abd10d2d8 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("tet newAgentPlugin", func(t *testing.T) { - p := newAgentPlugin() + p := newAgentPlugin(SupportedTaskTypes{}) assert.NotNil(t, p) assert.Equal(t, "agent-service", p.ID) assert.NotNil(t, p.PluginLoader) From e8e320aeae773995e4fd1aa0085c1a3c9b3d32e2 Mon Sep 17 00:00:00 2001 From: Future Outlier Date: Thu, 21 Sep 2023 06:55:48 +0800 Subject: [PATCH 3/3] spell Signed-off-by: Future Outlier --- go/tasks/plugins/webapi/agent/plugin_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/tasks/plugins/webapi/agent/plugin_test.go b/go/tasks/plugins/webapi/agent/plugin_test.go index abd10d2d8..3c413bf37 100644 --- a/go/tasks/plugins/webapi/agent/plugin_test.go +++ b/go/tasks/plugins/webapi/agent/plugin_test.go @@ -42,7 +42,7 @@ func TestPlugin(t *testing.T) { assert.Equal(t, plugin.cfg.ResourceConstraints, constraints) }) - t.Run("tet newAgentPlugin", func(t *testing.T) { + t.Run("test newAgentPlugin", func(t *testing.T) { p := newAgentPlugin(SupportedTaskTypes{}) assert.NotNil(t, p) assert.Equal(t, "agent-service", p.ID)