Skip to content

fix(provisioner): handle multiple agents, apps, scripts and envs #13741

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

Merged
merged 11 commits into from
Jul 3, 2024

Conversation

mtojek
Copy link
Member

@mtojek mtojek commented Jul 1, 2024

Fixes: #12949

This PR adjusts provisioner logic to properly handle apps, scripts, and envs assigned to different agent. Without this PR every app/script/env is assigned to every agent. Unfortunately, there isn't an easy way to achieve it, and we need to snoop the dependency information from the graph.

Note: I added a couple of .tf tests, which blew up the PR size. The code change itself is relatively small.

@mtojek mtojek self-assigned this Jul 1, 2024
@mtojek mtojek changed the title fix: multiple agents, independent apps fix(provisioner): handle multiple agents, apps, scripts and envs Jul 3, 2024
@mtojek mtojek requested a review from johnstcn July 3, 2024 11:52
@mtojek mtojek marked this pull request as ready for review July 3, 2024 11:52
Comment on lines 756 to 757
appNodeSuffix := fmt.Sprintf(`] %s.%s (expand)"`, resource.Type, resource.Name)
agentNodeSuffix := fmt.Sprintf(`] coder_agent.%s (expand)"`, agent.Name)
Copy link
Member

Choose a reason for hiding this comment

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

It's unfortunate that we need to match this :(

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I agree. It is the biggest drawback of this PR, and we need to preserve the format.

Comment on lines 760 to 771
for _, dst := range graph.Edges.SrcToDsts {
for _, edges := range dst {
for _, edge := range edges {
if strings.HasSuffix(edge.Src, appNodeSuffix) &&
strings.HasSuffix(edge.Dst, agentNodeSuffix) {
return true
}
}
}
}
return false
}
Copy link
Member

Choose a reason for hiding this comment

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

My main concern is that we are traversing this graph multiple times in a tight loop.
Could we instead traverse the graph once, build a shallow map of agent -> resource, and use that to determine the agent-resource dependency?

Copy link
Member Author

Choose a reason for hiding this comment

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

The main reason I'm hesitant to do this, it would be another cache/state used only to prevent this problem. Considering we have 1 agent on average, 2 in total, it may not introduce a heavy performance impact.

Anyway, if you think this is a must-do, I will improve the loop 👍 I admit, I focused mostly on fixing the problem.

Copy link
Member

Choose a reason for hiding this comment

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

That's fair. Let's make it work correctly first, and then see about benchmarking / speeding it up.

@mtojek mtojek merged commit 07d4171 into main Jul 3, 2024
28 checks passed
@mtojek mtojek deleted the 12949-apps branch July 3, 2024 12:55
@github-actions github-actions bot locked and limited conversation to collaborators Jul 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

coder_app: When adding multiple coder_agents gets duplicated coder_app
2 participants