Skip to content

chore: rename client Listen to ConnectRPC #11916

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 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type Options struct {
}

type Client interface {
Listen(ctx context.Context) (drpc.Conn, error)
ConnectRPC(ctx context.Context) (drpc.Conn, error)
ReportStats(ctx context.Context, log slog.Logger, statsChan <-chan *agentsdk.Stats, setInterval func(time.Duration)) (io.Closer, error)
PostLifecycle(ctx context.Context, state agentsdk.PostLifecycleRequest) error
PostMetadata(ctx context.Context, req agentsdk.PostMetadataRequest) error
Expand Down Expand Up @@ -691,8 +691,8 @@ func (a *agent) run(ctx context.Context) error {
}
a.sessionToken.Store(&sessionToken)

// Listen returns the dRPC connection we use for the Agent v2+ API
conn, err := a.client.Listen(ctx)
// ConnectRPC returns the dRPC connection we use for the Agent and Tailnet v2+ APIs
conn, err := a.client.ConnectRPC(ctx)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion agent/agenttest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (c *Client) Close() {
c.derpMapOnce.Do(func() { close(c.derpMapUpdates) })
}

func (c *Client) Listen(ctx context.Context) (drpc.Conn, error) {
func (c *Client) ConnectRPC(ctx context.Context) (drpc.Conn, error) {
conn, lis := drpcsdk.MemTransportPipe()
c.LastWorkspaceAgent = func() {
_ = conn.Close()
Expand Down
14 changes: 7 additions & 7 deletions coderd/workspaceagents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func TestWorkspaceAgentLogs(t *testing.T) {
})
}

func TestWorkspaceAgentListen(t *testing.T) {
func TestWorkspaceAgentConnectRPC(t *testing.T) {
t.Parallel()

t.Run("Connect", func(t *testing.T) {
Expand Down Expand Up @@ -400,7 +400,7 @@ func TestWorkspaceAgentListen(t *testing.T) {
agentClient := agentsdk.New(client.URL)
agentClient.SetSessionToken(authToken)

_, err = agentClient.Listen(ctx)
_, err = agentClient.ConnectRPC(ctx)
require.Error(t, err)
var sdkErr *codersdk.Error
require.ErrorAs(t, err, &sdkErr)
Expand Down Expand Up @@ -500,7 +500,7 @@ func TestWorkspaceAgentTailnetDirectDisabled(t *testing.T) {
// Verify that the manifest has DisableDirectConnections set to true.
agentClient := agentsdk.New(client.URL)
agentClient.SetSessionToken(r.AgentToken)
rpc, err := agentClient.Listen(ctx)
rpc, err := agentClient.ConnectRPC(ctx)
require.NoError(t, err)
defer func() {
cErr := rpc.Close()
Expand Down Expand Up @@ -830,7 +830,7 @@ func TestWorkspaceAgentAppHealth(t *testing.T) {

agentClient := agentsdk.New(client.URL)
agentClient.SetSessionToken(r.AgentToken)
conn, err := agentClient.Listen(ctx)
conn, err := agentClient.ConnectRPC(ctx)
require.NoError(t, err)
defer func() {
cErr := conn.Close()
Expand Down Expand Up @@ -1129,7 +1129,7 @@ func TestWorkspaceAgent_Metadata(t *testing.T) {
agentClient.SetSessionToken(r.AgentToken)

ctx := testutil.Context(t, testutil.WaitMedium)
conn, err := agentClient.Listen(ctx)
conn, err := agentClient.ConnectRPC(ctx)
require.NoError(t, err)
defer func() {
cErr := conn.Close()
Expand Down Expand Up @@ -1307,7 +1307,7 @@ func TestWorkspaceAgent_Metadata_CatchMemoryLeak(t *testing.T) {
agentClient.SetSessionToken(r.AgentToken)

ctx, cancel := context.WithCancel(testutil.Context(t, testutil.WaitSuperLong))
conn, err := agentClient.Listen(ctx)
conn, err := agentClient.ConnectRPC(ctx)
require.NoError(t, err)
defer func() {
cErr := conn.Close()
Expand Down Expand Up @@ -1669,7 +1669,7 @@ func requireGetManifest(ctx context.Context, t testing.TB, aAPI agentproto.DRPCA
}

func postStartup(ctx context.Context, t testing.TB, client agent.Client, startup *agentproto.Startup) error {
conn, err := client.Listen(ctx)
conn, err := client.ConnectRPC(ctx)
require.NoError(t, err)
defer func() {
cErr := conn.Close()
Expand Down
2 changes: 1 addition & 1 deletion coderd/workspaceapps/apptest/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ func createWorkspaceWithApps(t *testing.T, client *codersdk.Client, orgID uuid.U
primaryAppHost, err := client.AppHost(appHostCtx)
require.NoError(t, err)
if primaryAppHost.Host != "" {
rpcConn, err := agentClient.Listen(appHostCtx)
rpcConn, err := agentClient.ConnectRPC(appHostCtx)
require.NoError(t, err)
aAPI := agentproto.NewDRPCAgentClient(rpcConn)
manifest, err := aAPI.GetManifest(appHostCtx, &agentproto.GetManifestRequest{})
Expand Down
7 changes: 3 additions & 4 deletions codersdk/agentsdk/agentsdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,8 @@ func (c *Client) RewriteDERPMap(derpMap *tailcfg.DERPMap) {
}
}

// Listen connects to the workspace agent API WebSocket
// that handles connection negotiation.
func (c *Client) Listen(ctx context.Context) (drpc.Conn, error) {
// ConnectRPC connects to the workspace agent API and tailnet API
func (c *Client) ConnectRPC(ctx context.Context) (drpc.Conn, error) {
rpcURL, err := c.SDK.URL.Parse("/api/v2/workspaceagents/me/rpc")
if err != nil {
return nil, xerrors.Errorf("parse url: %w", err)
Expand Down Expand Up @@ -210,7 +209,7 @@ func (c *Client) Listen(ctx context.Context) (drpc.Conn, error) {
netConn := &closeNetConn{
Conn: wsNetConn,
closeFunc: func() {
_ = conn.Close(websocket.StatusGoingAway, "Listen closed")
_ = conn.Close(websocket.StatusGoingAway, "ConnectRPC closed")
},
}
config := yamux.DefaultConfig()
Expand Down
2 changes: 1 addition & 1 deletion enterprise/coderd/appearance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func TestServiceBanners(t *testing.T) {
}

func requireGetServiceBanner(ctx context.Context, t *testing.T, client *agentsdk.Client) codersdk.ServiceBannerConfig {
cc, err := client.Listen(ctx)
cc, err := client.ConnectRPC(ctx)
require.NoError(t, err)
defer func() {
_ = cc.Close()
Expand Down