Skip to content

feat: add logging to client tailnet yamux #11908

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
Jan 30, 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
2 changes: 1 addition & 1 deletion coderd/agentapi/servicebanner_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"sync/atomic"
"testing"

"github.com/stretchr/testify/require"
"golang.org/x/xerrors"

agentproto "github.com/coder/coder/v2/agent/proto"
"github.com/coder/coder/v2/coderd/appearance"
"github.com/coder/coder/v2/codersdk"
"github.com/stretchr/testify/require"
)

func TestGetServiceBanner(t *testing.T) {
Expand Down
5 changes: 4 additions & 1 deletion codersdk/workspaceagents.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,10 @@ func (tac *tailnetAPIConnector) dial() (proto.DRPCTailnetClient, error) {
}
return nil, err
}
client, err := tailnet.NewDRPCClient(websocket.NetConn(tac.ctx, ws, websocket.MessageBinary))
client, err := tailnet.NewDRPCClient(
websocket.NetConn(tac.ctx, ws, websocket.MessageBinary),
tac.logger,
)
if err != nil {
tac.logger.Debug(tac.ctx, "failed to create DRPCClient", slog.Error(err))
_ = ws.Close(websocket.StatusInternalError, "")
Expand Down
6 changes: 4 additions & 2 deletions enterprise/wsproxy/wsproxysdk/wsproxysdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ func (c *Client) DialCoordinator(ctx context.Context) (agpl.MultiAgentConn, erro
go httpapi.HeartbeatClose(ctx, logger, cancel, conn)

nc := websocket.NetConn(ctx, conn, websocket.MessageBinary)
client, err := agpl.NewDRPCClient(nc)
client, err := agpl.NewDRPCClient(nc, logger)
if err != nil {
logger.Debug(ctx, "failed to create DRPCClient", slog.Error(err))
_ = conn.Close(websocket.StatusInternalError, "")
Expand Down Expand Up @@ -493,7 +493,9 @@ func (c *Client) DialCoordinator(ctx context.Context) (agpl.MultiAgentConn, erro

go func() {
<-ctx.Done()
ma.Close()
_ = ma.Close()
_ = client.DRPCConn().Close()
<-client.DRPCConn().Closed()
_ = conn.Close(websocket.StatusGoingAway, "closed")
}()

Expand Down
8 changes: 5 additions & 3 deletions tailnet/client.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package tailnet

import (
"io"
"context"
"net"

"github.com/hashicorp/yamux"
"golang.org/x/xerrors"

"cdr.dev/slog"
"github.com/coder/coder/v2/codersdk/drpc"
"github.com/coder/coder/v2/tailnet/proto"
)

func NewDRPCClient(conn net.Conn) (proto.DRPCTailnetClient, error) {
func NewDRPCClient(conn net.Conn, logger slog.Logger) (proto.DRPCTailnetClient, error) {
config := yamux.DefaultConfig()
config.LogOutput = io.Discard
config.LogOutput = nil
config.Logger = slog.Stdlib(context.Background(), logger, slog.LevelInfo)
session, err := yamux.Client(conn, config)
if err != nil {
return nil, xerrors.Errorf("multiplex client: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion tailnet/coordinator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ func TestRemoteCoordination(t *testing.T) {
serveErr <- err
}()

client, err := tailnet.NewDRPCClient(cC)
client, err := tailnet.NewDRPCClient(cC, logger)
require.NoError(t, err)
protocol, err := client.Coordinate(ctx)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion tailnet/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestClientService_ServeClient_V2(t *testing.T) {
errCh <- err
}()

client, err := tailnet.NewDRPCClient(c)
client, err := tailnet.NewDRPCClient(c, logger)
require.NoError(t, err)

// Coordinate
Expand Down