Skip to content

feat: in-process provisionerd connection #1568

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 6 commits into from
May 19, 2022

Conversation

spikecurtis
Copy link
Contributor

Switches provisionerd to use an in-process communication, rather than a remote-HTTP endpoint for provisionerds that are started in the same process as coderd.

First part of #1375

I'm not actually disabling the remote endpoint in this PR because we squash commits and I want to make it easy to revert later when we're ready to include auth.

Note there was one instance, in testing, where we did run a provisionerd in a separate process from coderd -- testing the coder server command. I've modified coder server --dev to start up echo provisioners for this testing to sidestep the need to start an echo provisioner in a separate process for now.

Signed-off-by: Spike Curtis <spike@coder.com>
@spikecurtis spikecurtis requested review from kylecarbs and a team May 18, 2022 19:01
Copy link
Member

@kylecarbs kylecarbs left a comment

Choose a reason for hiding this comment

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

We'll probably need IncludeProvisionerD to be ProvisionerDaemonCount instead. Right now, we have a CLI option on coder server to customize the amount, which defaults to 3.

With just one, it's possible to experience looong build times from even just a few users.

@spikecurtis
Copy link
Contributor Author

spikecurtis commented May 18, 2022

IncludeProvisionerD is only an option for coderdtest, and is just a convenience for testing so that you can write

client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true})

instead of

_, client, coderDaemon := coderdtest.NewMemoryCoderd(t, options)
coderdtest.NewProvisionerd(t, coderDaemon)

You can always add more provisionerds if you want

@spikecurtis
Copy link
Contributor Author

Lint is complaining about me passing the --dev flag to enable echo provisioners. Do we want a second flag, or should I just suppress it @kylecarbs ?

@spikecurtis
Copy link
Contributor Author

By the way, the reason builds take a long time with a few users is because provisionerd currently will only run one job at a time. We'll need to fix it up so that it can run multiple jobs in parallel (as long as they are for different workspaces).

@kylecarbs
Copy link
Member

Ahh my bad, I misread. I dislike that you cannot disable the provisioned daemon halfway through, I'm pretty sure we used that for some tests to ensure jobs would stay in progress, but I suppose maybe not.

@spikecurtis why do you feel daemons should run multiple jobs in parallel? We almost want to promote the idea of run once and exit style runners, especially because they perform arbitrary code.

@spikecurtis
Copy link
Contributor Author

I dislike that you cannot disable the provisioned daemon halfway through, I'm pretty sure we used that for some tests to ensure jobs would stay in progress, but I suppose maybe not.

No, you still can, and some tests do. You just have to use the more verbose form:

_, client, coderDaemon := coderdtest.NewMemoryCoderd(t, options)
provisionerD := coderdtest.NewProvisionerd(t, coderDaemon)
// do some stuff
provisionerD.Close()
// do some more stuff

Signed-off-by: Spike Curtis <spike@coder.com>
@kylecarbs
Copy link
Member

@spikecurtis how are you planning to handle that test-case when the HTTP endpoint goes away?

@spikecurtis
Copy link
Contributor Author

spikecurtis commented May 19, 2022

how are you planning to handle that test-case when the HTTP endpoint goes away?

All tests are moved to in-process communication with this PR. You can start and stop provisionerds at will. They just have to be in the same process as coderd. There was just one test case where we weren't doing it, testing the coder server CLI command, and the only reason we weren't is because previously the coder server --dev only started terraform, not echo. That's changed in this PR and now that test uses in-process provisionerds.

@spikecurtis spikecurtis requested a review from a team May 19, 2022 21:00
Copy link
Contributor

@dwahler dwahler left a comment

Choose a reason for hiding this comment

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

Other than the one comment I left, LGTM (for what that's worth).

If we're going to merge this, it makes sense to do so quickly so that we aren't constantly having to resolve conflicts.

ID: uuid.New(),
CreatedAt: database.Now(),
Name: namesgenerator.GetRandomName(1),
Provisioners: []database.ProvisionerType{database.ProvisionerTypeEcho, database.ProvisionerTypeTerraform},
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this isn't a new issue since this function is just a copy of the existing code in provisionerDaemonsListen, but should this list be derived from the keys in daemon.Provisioners? As is, when we're running in production mode, the echo provisioner won't be included in the map of provisioner implementations, but it will still be in this list.

No idea if that actually causes problems, but it seems sketchy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is copied from the existing code, and you've stumbled on a weakness in the design here: which is that there is no direct link between the provisioners that are actually started by a provisionerd and the provisioners that are registered.

On the coderd side, it's just hardcoded that there are echo and terraform provisioners, and on the provisionerd side we start one or other or both depending on the circumstances.

Really, we should have the provisionerd register the provisioners it is actually running when it connects. I'll create an issue to track #1605

@spikecurtis spikecurtis enabled auto-merge (squash) May 19, 2022 22:37
@spikecurtis spikecurtis merged commit 1871b09 into main May 19, 2022
@spikecurtis spikecurtis deleted the spike/1375_in_proc_provisionerd_comms branch May 19, 2022 22:47
@spikecurtis spikecurtis mentioned this pull request May 19, 2022
kylecarbs pushed a commit that referenced this pull request Jun 10, 2022
* in-process provisionerd connection

Signed-off-by: Spike Curtis <spike@coder.com>

* disable lint for server.go/newProvisionerDaemon

Signed-off-by: Spike Curtis <spike@coder.com>
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.

3 participants