Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Commit 2598c96

Browse files
Future-OutlierFuture Outlier
andauthored
Add supportTaskTypes for agentservice without write it in config twice. (#398)
Signed-off-by: Future Outlier <[email protected]> Co-authored-by: Future Outlier <[email protected]>
1 parent 08dd79b commit 2598c96

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

go/tasks/plugins/webapi/agent/config.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ var (
4444
Insecure: true,
4545
DefaultTimeout: config.Duration{Duration: 10 * time.Second},
4646
},
47-
SupportedTaskTypes: []string{"task_type_1", "task_type_2"},
4847
}
4948

5049
configSection = pluginsConfig.MustRegisterSubSection("agent-service", &defaultConfig)
@@ -66,9 +65,6 @@ type Config struct {
6665

6766
// Maps task types to their agents. {TaskType: AgentId}
6867
AgentForTaskTypes map[string]string `json:"agentForTaskTypes" pflag:"-,"`
69-
70-
// SupportedTaskTypes is a list of task types that are supported by this plugin.
71-
SupportedTaskTypes []string `json:"supportedTaskTypes" pflag:"-,Defines a list of task types that are supported by this plugin."`
7268
}
7369

7470
type Agent struct {

go/tasks/plugins/webapi/agent/integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func TestEndToEnd(t *testing.T) {
161161
tr.OnRead(context.Background()).Return(nil, fmt.Errorf("read fail"))
162162
tCtx.OnTaskReader().Return(tr)
163163

164-
agentPlugin := newAgentPlugin()
164+
agentPlugin := newAgentPlugin(SupportedTaskTypes{})
165165
pluginEntry := pluginmachinery.CreateRemotePlugin(agentPlugin)
166166
plugin, err := pluginEntry.LoadPlugin(context.TODO(), newFakeSetupContext("test3"))
167167
assert.NoError(t, err)

go/tasks/plugins/webapi/agent/plugin.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import (
2929

3030
type GetClientFunc func(ctx context.Context, agent *Agent, connectionCache map[*Agent]*grpc.ClientConn) (service.AsyncAgentServiceClient, error)
3131

32+
type TaskType = string
33+
type SupportedTaskTypes []TaskType
3234
type Plugin struct {
3335
metricScope promutils.Scope
3436
cfg *Config
@@ -296,8 +298,10 @@ func getFinalContext(ctx context.Context, operation string, agent *Agent) (conte
296298
return context.WithTimeout(ctx, timeout)
297299
}
298300

299-
func newAgentPlugin() webapi.PluginEntry {
300-
supportedTaskTypes := GetConfig().SupportedTaskTypes
301+
func newAgentPlugin(supportedTaskTypes SupportedTaskTypes) webapi.PluginEntry {
302+
if len(supportedTaskTypes) == 0 {
303+
supportedTaskTypes = SupportedTaskTypes{"default_supported_task_type"}
304+
}
301305

302306
return webapi.PluginEntry{
303307
ID: "agent-service",
@@ -313,9 +317,9 @@ func newAgentPlugin() webapi.PluginEntry {
313317
}
314318
}
315319

316-
func RegisterAgentPlugin() {
320+
func RegisterAgentPlugin(supportedTaskTypes SupportedTaskTypes) {
317321
gob.Register(ResourceMetaWrapper{})
318322
gob.Register(ResourceWrapper{})
319323

320-
pluginmachinery.PluginRegistry().RegisterRemotePlugin(newAgentPlugin())
324+
pluginmachinery.PluginRegistry().RegisterRemotePlugin(newAgentPlugin(supportedTaskTypes))
321325
}

go/tasks/plugins/webapi/agent/plugin_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestPlugin(t *testing.T) {
4343
})
4444

4545
t.Run("test newAgentPlugin", func(t *testing.T) {
46-
p := newAgentPlugin()
46+
p := newAgentPlugin(SupportedTaskTypes{})
4747
assert.NotNil(t, p)
4848
assert.Equal(t, "agent-service", p.ID)
4949
assert.NotNil(t, p.PluginLoader)

0 commit comments

Comments
 (0)