Skip to content
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

DEVPROD-13572 Update agent to end after running single task host task #8789

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bynn
Copy link
Contributor

@bynn bynn commented Mar 5, 2025

DEVPROD-13572

Description

agent exits after looping once if the task is a single task distro task
it does not currently exit if the task is a single host task but does not fully handle the single host task group case which will be covered later

Testing

added a unit test for agent ending the loop

will do a full end to end test with some logging next ticket

@bynn bynn requested a review from a team March 5, 2025 19:33
@bynn bynn force-pushed the DEVPROD-13572real branch from caf0119 to a49b2d3 Compare March 5, 2025 20:27
@@ -185,6 +186,15 @@ func Agent() cli.Command {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

h, err := host.FindOneId(ctx, opts.HostID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do this here? I'm not familiar with the agent command, but I don't think it has a database connection to get a host- so I think this would stop agents from starting

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yeah, this is my bad
made a new agent method for this

defer cancel()

// The loop should exit after one execution because it is on a single host distro
s.NoError(s.a.loop(ctx))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we test if it only looped once somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so

there isnt a super good test for the agents working in general 😂 because most of them checks that we break under certain conditions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I thought so. I had some ideas of having it run a command and the command modifies a test variable but we don't have anything like that setup and it's non-trivial to do. I'm honestly surprised we haven't had a test command like this yet. This tests looks good to me then!

@bynn bynn requested a review from ZackarySantana March 6, 2025 20:40
@@ -59,6 +59,10 @@ type SharedCommunicator interface {
GetDistroView(context.Context, TaskData) (*apimodels.DistroView, error)
// GetDistroAMI gets the AMI for the given distro/region
GetDistroAMI(context.Context, string, string, TaskData) (string, error)
// GetDistroByName returns a distro given a distro ID.
GetDistroByName(context.Context, string) (*restmodel.APIDistro, error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this function get it by name or id (the comment above says id but the name says name)

EDIT: I see that the method was already implemented and it gets it by id rather than name like the name suggests. Could you rename it to say GetDistroByDistroID maybe? Or GetDistroByID (if it makes sense that the ID in question is the Distro's)?

@@ -223,6 +225,13 @@ func (a *Agent) Start(ctx context.Context) error {
a.tryCleanupDirectory(a.opts.WorkingDirectory)
}

distro, err := a.comm.GetDistroByHostID(ctx, a.opts.HostID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a route, would it make more sense to add it as a flag in the command here? I found an example of doing this here

It passes in the data here and it looks like the Distro data is already loaded and ready to be passed (I haven't done testing)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants