Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: Integrate workspace agent into coderd #398

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

Closed
wants to merge 5 commits into from
Closed

Conversation

kylecarbs
Copy link
Member

@kylecarbs kylecarbs commented Mar 3, 2022

A lot of this code is kinda crummy. I'd like to refactor some of the API handler names for resources, but that can come in a later PR.

@kylecarbs kylecarbs requested a review from bryphe-coder March 3, 2022 16:43
@kylecarbs kylecarbs self-assigned this Mar 3, 2022
Comment on lines +17 to +19
// This command isn't useful for users, and seems
// more likely to confuse.
Hidden: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense to me 👍

@codecov
Copy link

codecov bot commented Mar 3, 2022

Codecov Report

Merging #398 (9895965) into main (73cb452) will decrease coverage by 1.76%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #398      +/-   ##
==========================================
- Coverage   67.87%   66.10%   -1.77%     
==========================================
  Files         150       71      -79     
  Lines        8482      773    -7709     
  Branches       72       72              
==========================================
- Hits         5757      511    -5246     
+ Misses       2148      248    -1900     
+ Partials      577       14     -563     
Flag Coverage Δ
unittest-go-macos-latest ?
unittest-go-ubuntu-latest ?
unittest-go-windows-2022 ?
unittest-js 66.10% <ø> (ø)
Impacted Files Coverage Δ
agent/agent.go
cli/projectcreate.go
cli/root.go
cli/workspaces.go
coderd/cmd/root.go
coderd/coderd.go
coderd/coderdtest/coderdtest.go
coderd/projectimport.go
coderd/provisionerdaemons.go
coderd/provisionerjobs.go
... and 69 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 73cb452...9895965. Read the comment docs.

@kylecarbs kylecarbs marked this pull request as ready for review March 4, 2022 01:35

func workspaceAgent() *cobra.Command {
return &cobra.Command{
Use: "agent",
Copy link
Contributor

Choose a reason for hiding this comment

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

Having the coder agent command is a huge step!

Comment on lines +22 to +23
api.websocketWaitGroup.Add(1)
defer api.websocketWaitGroup.Done()
Copy link
Contributor

Choose a reason for hiding this comment

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

Glad we have this to hook into now to ensure that the websockets get cleaned up properly

return r(req)
}

// Create's a new Google metadata client to authenticate.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Create's a new Google metadata client to authenticate.
// Creates a new Google metadata client to authenticate.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just noticed this extra apostrophe!

})
}

// Create's a signed JWT with a randomly generated private key.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Create's a signed JWT with a randomly generated private key.
// Creates a signed JWT with a randomly generated private key.

return signedKey, keyID, privateKey
}

// Create's a validator that verifies against the provided private key.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Create's a validator that verifies against the provided private key.
// Creates a validator that verifies against the provided private key.


type workspaceResourceParamContextKey struct{}

// ProvisionerJobParam returns the project from the ExtractProjectParam handler.
Copy link
Contributor

@bryphe-coder bryphe-coder Mar 4, 2022

Choose a reason for hiding this comment

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

Suggested change
// ProvisionerJobParam returns the project from the ExtractProjectParam handler.
// WorkspaceResourceParam returns the provisioner job resource from the handler.

job := coderdtest.CreateProjectImportJob(t, client, user.Organization, &echo.Responses{
Parse: echo.ParseComplete,
Parse: echo.ParseComplete,
ProvisionDryRun: echo.ProvisionComplete,
Copy link
Contributor

Choose a reason for hiding this comment

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

Neat 👍

@@ -94,11 +94,9 @@ func TestAgent(t *testing.T) {

func setup(t *testing.T) proto.DRPCPeerBrokerClient {
client, server := provisionersdk.TransportPipe()
closer := agent.New(func(ctx context.Context) (*peerbroker.Listener, error) {
return peerbroker.Listen(server, &peer.ConnOptions{
Logger: slogtest.Make(t, nil),
Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand correctly, it seems like the log level for this has changed - I wonder if that could be related to the test failure here: https://github.com/coder/coder/runs/5416391323?check_suite_focus=true#step:7:168

(thinking maybe this change increases the verbosity of logs, and one of those more-verbose logs is what gets emitted after the test is complete).

@bryphe-coder
Copy link
Contributor

Unfortunately I saw this error in the CI run:

==================
panic: Log in goroutine after TestAgent/SessionTTY has completed: 2022-03-04 01:41:53.577 [DEBUG]	<conn.go:557>	closing conn with error ...
"error": recv:
             github.com/coder/coder/peerbroker.(*peerBrokerService).NegotiateConnection
                 /home/runner/work/coder/coder/peerbroker/listen.go:158
           - context canceled

https://github.com/coder/coder/runs/5416391323?check_suite_focus=true#step:7:168

I was thinking maybe one of two possibilities:

  1. A change in loglevel in agent_test.go introduces logs that weren't emitted before, but now are after the test has finished
  2. It might be an intermittent issue - it seems like the session might need to be closed as well?

We currently wait for the session, ie:

err = session.Wait()
require.NoError(t, err)

But wondering if it needs to be closed too as part of cleanup:

err = session.Wait()
require.NoError(t, err)
err = session.Close()
require.NoError(t, err)

Copy link
Contributor

@bryphe-coder bryphe-coder left a comment

Choose a reason for hiding this comment

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

Looks good to me - just some minor nits on the comments, and was thinking around the test failure I observed in the latest commit.

Congrats on getting the agent integrated into coderd 🍾

@kylecarbs
Copy link
Member Author

Superseded by #401

@kylecarbs kylecarbs closed this Mar 7, 2022
@kylecarbs kylecarbs deleted the agentlink branch March 7, 2022 01:36
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