-
Notifications
You must be signed in to change notification settings - Fork 696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[flyteagent] Add agents
and agentForTaskTypes
in helm chart
#6239
base: master
Are you sure you want to change the base?
Changes from all commits
59b8eab
73afbee
b81fe4d
8ab4419
a9816d9
a490251
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,12 +1,24 @@ | ||||||||
package agent | ||||||||
|
||||||||
import ( | ||||||||
"context" | ||||||||
"testing" | ||||||||
"time" | ||||||||
|
||||||||
"github.com/stretchr/testify/assert" | ||||||||
"github.com/stretchr/testify/mock" | ||||||||
|
||||||||
agentMocks "github.com/flyteorg/flyte/flyteidl/clients/go/admin/mocks" | ||||||||
"github.com/flyteorg/flyte/flyteidl/clients/go/coreutils" | ||||||||
"github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" | ||||||||
flyteIdlCore "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/core" | ||||||||
"github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/service" | ||||||||
"github.com/flyteorg/flyte/flyteplugins/go/tasks/pluginmachinery" | ||||||||
pluginCoreMocks "github.com/flyteorg/flyte/flyteplugins/go/tasks/pluginmachinery/core/mocks" | ||||||||
ioMocks "github.com/flyteorg/flyte/flyteplugins/go/tasks/pluginmachinery/io/mocks" | ||||||||
"github.com/flyteorg/flyte/flyteplugins/go/tasks/pluginmachinery/webapi" | ||||||||
"github.com/flyteorg/flyte/flytestdlib/config" | ||||||||
"github.com/flyteorg/flyte/flytestdlib/storage" | ||||||||
) | ||||||||
|
||||||||
func TestGetAndSetConfig(t *testing.T) { | ||||||||
|
@@ -53,9 +65,80 @@ func TestDefaultAgentConfig(t *testing.T) { | |||||||
expectedTaskTypes := []string{"task_type_1", "task_type_2"} | ||||||||
assert.Equal(t, expectedTaskTypes, cfg.SupportedTaskTypes) | ||||||||
|
||||||||
assert.Empty(t, cfg.AgentDeployments) | ||||||||
assert.Contains(t, cfg.AgentDeployments, "agent_1") | ||||||||
|
||||||||
assert.Empty(t, cfg.AgentForTaskTypes) | ||||||||
agent1 := cfg.AgentDeployments["agent_1"] | ||||||||
assert.Equal(t, "", agent1.Endpoint) | ||||||||
assert.True(t, agent1.Insecure) | ||||||||
assert.Equal(t, 300*time.Second, agent1.DefaultTimeout.Duration) | ||||||||
assert.Equal(t, 300*time.Second, agent1.Timeouts["ExecuteTaskSync"].Duration) | ||||||||
assert.Equal(t, 100*time.Second, agent1.Timeouts["GetTask"].Duration) | ||||||||
|
||||||||
assert.Equal(t, "agent_1", cfg.AgentForTaskTypes["task_type_1"]) | ||||||||
|
||||||||
assert.Equal(t, 10*time.Second, cfg.PollInterval.Duration) | ||||||||
} | ||||||||
|
||||||||
func TestTaskWithExpectedAgent(t *testing.T) { | ||||||||
// Set up the base configuration | ||||||||
cfg := defaultConfig | ||||||||
cfg.AgentDeployments["agent_1"].Endpoint = defaultAgentEndpoint | ||||||||
err := SetConfig(&cfg) | ||||||||
assert.NoError(t, err) | ||||||||
|
||||||||
// Create mock agent client agent_1 | ||||||||
agent1Client := new(agentMocks.AsyncAgentServiceClient) | ||||||||
agent1Client.On("CreateTask", mock.Anything, mock.Anything).Return(&admin.CreateTaskResponse{}, nil) | ||||||||
|
||||||||
// Create a plugin instance using our mock clients | ||||||||
agentPlugin := webapi.PluginEntry{ | ||||||||
ID: "agent", | ||||||||
SupportedTaskTypes: []string{"task_type_1"}, | ||||||||
PluginLoader: func(ctx context.Context, iCtx webapi.PluginSetupContext) (webapi.AsyncPlugin, error) { | ||||||||
return &Plugin{ | ||||||||
metricScope: iCtx.MetricsScope(), | ||||||||
cfg: &cfg, | ||||||||
cs: &ClientSet{ | ||||||||
asyncAgentClients: map[string]service.AsyncAgentServiceClient{ | ||||||||
defaultAgentEndpoint: agent1Client, | ||||||||
}, | ||||||||
}, | ||||||||
registry: Registry{ | ||||||||
"task_type_1": {defaultTaskTypeVersion: {AgentDeployment: cfg.AgentDeployments["agent_1"], IsSync: false}}, | ||||||||
}, | ||||||||
}, nil | ||||||||
}, | ||||||||
} | ||||||||
|
||||||||
// Create task template and input | ||||||||
template := flyteIdlCore.TaskTemplate{ | ||||||||
Type: "task_type_1", // Should route to agent_1 | ||||||||
Target: &flyteIdlCore.TaskTemplate_Container{}, | ||||||||
} | ||||||||
|
||||||||
pluginEntry := pluginmachinery.CreateRemotePlugin(agentPlugin) | ||||||||
plugin, err := pluginEntry.LoadPlugin(context.TODO(), newFakeSetupContext("test")) | ||||||||
assert.NoError(t, err) | ||||||||
|
||||||||
inputs, err := coreutils.MakeLiteralMap(map[string]interface{}{"input": "test"}) | ||||||||
assert.NoError(t, err) | ||||||||
|
||||||||
// Run task type 1 (should use agent_1) | ||||||||
tCtx := getTaskContext(t) | ||||||||
tr := &pluginCoreMocks.TaskReader{} | ||||||||
tr.OnRead(context.Background()).Return(&template, nil) | ||||||||
tCtx.OnTaskReader().Return(tr) | ||||||||
inputReader := &ioMocks.InputReader{} | ||||||||
inputReader.OnGetMatch(mock.Anything).Return(inputs, nil) | ||||||||
inputReader.OnGetInputPath().Return(storage.DataReference("fake://input/path")) | ||||||||
inputReader.OnGetInputPrefixPath().Return(storage.DataReference("fake://input/prefix")) | ||||||||
tCtx.OnInputReader().Return(inputReader) | ||||||||
|
||||||||
result, err := plugin.Handle(context.Background(), tCtx) | ||||||||
assert.NoError(t, err) | ||||||||
assert.NotNil(t, result) | ||||||||
|
||||||||
// Verify agent_1 was called (failed) | ||||||||
// agent1Client.AssertCalled(t, "CreateTask", mock.Anything, mock.Anything) | ||||||||
Comment on lines
+141
to
+142
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider enabling mock assertion check
The commented out assertion Code suggestionCheck the AI-generated fix before applying
Suggested change
Code Review Run #5f1d05 Is this a valid issue, or was it incorrectly flagged by the Agent?
|
||||||||
|
||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding task types to the
supportedTaskTypes
array as an empty array may prevent the agent from handling any tasks. You might want to specify the task types this agent should support.Code suggestion
Code Review Run #5f1d05
Is this a valid issue, or was it incorrectly flagged by the Agent?