Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
wip log sink
  • Loading branch information
ethanndickson committed Jul 2, 2024
commit 3b7f5b20f32240c2afff4192e7afaa60c41aaef8
16 changes: 14 additions & 2 deletions codersdk/workspacesdk/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ import (
"io"
"net/http"
"slices"
"strings"
"sync"
"sync/atomic"
"time"

"github.com/google/uuid"
"golang.org/x/xerrors"
"nhooyr.io/websocket"
"storj.io/drpc"
"storj.io/drpc/drpcerr"
"tailscale.com/tailcfg"

"cdr.dev/slog"
Expand Down Expand Up @@ -66,6 +70,10 @@ type tailnetAPIConnector struct {
connected chan error
isFirst bool
closed chan struct{}

// Set to true if we get a response from the server that it doesn't support
// network telemetry.
telemetryDisabled atomic.Bool
}

// Create a new tailnetAPIConnector without running it
Expand Down Expand Up @@ -269,12 +277,16 @@ func (tac *tailnetAPIConnector) SendTelemetryEvent(event *proto.TelemetryEvent)
// We hold the lock for the entire telemetry request, but this would only block
// a coordinate retry, and closing the connection.
defer tac.clientMu.RUnlock()
if tac.client == nil {
if tac.client == nil || tac.telemetryDisabled.Load() {
return
}
ctx, cancel := context.WithTimeout(tac.ctx, 5*time.Second)
defer cancel()
_, _ = tac.client.PostTelemetry(ctx, &proto.TelemetryRequest{
_, err := tac.client.PostTelemetry(ctx, &proto.TelemetryRequest{
Events: []*proto.TelemetryEvent{event},
})
if drpcerr.Code(err) == drpcerr.Unimplemented || drpc.ProtocolError.Has(err) && strings.Contains(err.Error(), "unknown rpc: ") {
tac.logger.Debug(tac.ctx, "attempted to send telemetry to a server that doesn't support it", slog.Error(err))
tac.telemetryDisabled.Store(true)
}
}
3 changes: 2 additions & 1 deletion codersdk/workspacesdk/connector_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ func TestTailnetAPIConnector_UplevelVersion(t *testing.T) {

fConn := newFakeTailnetConn()

uut := runTailnetAPIConnector(ctx, logger, agentID, svr.URL, &websocket.DialOptions{}, fConn)
uut := newTailnetAPIConnector(ctx, logger, agentID, svr.URL, &websocket.DialOptions{})
uut.runConnector(fConn)

err := testutil.RequireRecvCtx(ctx, t, uut.connected)
var sdkErr *codersdk.Error
Expand Down
4 changes: 2 additions & 2 deletions tailnet/configmaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ type configMaps struct {
peers map[uuid.UUID]*peerLifecycle
addresses []netip.Prefix
derpMap *tailcfg.DERPMap
logger slog.Logger
logger multiLogger
blockEndpoints bool

// for testing
clock clock.Clock
}

func newConfigMaps(logger slog.Logger, engine engineConfigurable, nodeID tailcfg.NodeID, nodeKey key.NodePrivate, discoKey key.DiscoPublic) *configMaps {
func newConfigMaps(logger multiLogger, engine engineConfigurable, nodeID tailcfg.NodeID, nodeKey key.NodePrivate, discoKey key.DiscoPublic) *configMaps {
pubKey := nodeKey.Public()
c := &configMaps{
phased: phased{Cond: *(sync.NewCond(&sync.Mutex{}))},
Expand Down
36 changes: 18 additions & 18 deletions tailnet/configmaps_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
func TestConfigMaps_setAddresses_different(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitShort)
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
logger := newMultiLogger(slogtest.Make(t, nil).Leveled(slog.LevelDebug))
fEng := newFakeEngineConfigurable()
nodePrivateKey := key.NewNode()
nodeID := tailcfg.NodeID(5)
Expand Down Expand Up @@ -87,7 +87,7 @@ func TestConfigMaps_setAddresses_different(t *testing.T) {
func TestConfigMaps_setAddresses_same(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitShort)
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
logger := newMultiLogger(slogtest.Make(t, nil).Leveled(slog.LevelDebug))
fEng := newFakeEngineConfigurable()
nodePrivateKey := key.NewNode()
nodeID := tailcfg.NodeID(5)
Expand Down Expand Up @@ -118,7 +118,7 @@ func TestConfigMaps_setAddresses_same(t *testing.T) {
func TestConfigMaps_updatePeers_new(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitShort)
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
logger := newMultiLogger(slogtest.Make(t, nil).Leveled(slog.LevelDebug))
fEng := newFakeEngineConfigurable()
nodePrivateKey := key.NewNode()
nodeID := tailcfg.NodeID(5)
Expand Down Expand Up @@ -188,7 +188,7 @@ func TestConfigMaps_updatePeers_new(t *testing.T) {
func TestConfigMaps_updatePeers_new_waitForHandshake_neverConfigures(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitShort)
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
logger := newMultiLogger(slogtest.Make(t, nil).Leveled(slog.LevelDebug))
fEng := newFakeEngineConfigurable()
nodePrivateKey := key.NewNode()
nodeID := tailcfg.NodeID(5)
Expand Down Expand Up @@ -232,7 +232,7 @@ func TestConfigMaps_updatePeers_new_waitForHandshake_neverConfigures(t *testing.
func TestConfigMaps_updatePeers_new_waitForHandshake_outOfOrder(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitShort)
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
logger := newMultiLogger(slogtest.Make(t, nil).Leveled(slog.LevelDebug))
fEng := newFakeEngineConfigurable()
nodePrivateKey := key.NewNode()
nodeID := tailcfg.NodeID(5)
Expand Down Expand Up @@ -303,7 +303,7 @@ func TestConfigMaps_updatePeers_new_waitForHandshake_outOfOrder(t *testing.T) {
func TestConfigMaps_updatePeers_new_waitForHandshake(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitShort)
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
logger := newMultiLogger(slogtest.Make(t, nil).Leveled(slog.LevelDebug))
fEng := newFakeEngineConfigurable()
nodePrivateKey := key.NewNode()
nodeID := tailcfg.NodeID(5)
Expand Down Expand Up @@ -374,7 +374,7 @@ func TestConfigMaps_updatePeers_new_waitForHandshake(t *testing.T) {
func TestConfigMaps_updatePeers_new_waitForHandshake_timeout(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitShort)
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
logger := newMultiLogger(slogtest.Make(t, nil).Leveled(slog.LevelDebug))
fEng := newFakeEngineConfigurable()
nodePrivateKey := key.NewNode()
nodeID := tailcfg.NodeID(5)
Expand Down Expand Up @@ -432,7 +432,7 @@ func TestConfigMaps_updatePeers_new_waitForHandshake_timeout(t *testing.T) {
func TestConfigMaps_updatePeers_same(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitShort)
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
logger := newMultiLogger(slogtest.Make(t, nil).Leveled(slog.LevelDebug))
fEng := newFakeEngineConfigurable()
nodePrivateKey := key.NewNode()
nodeID := tailcfg.NodeID(5)
Expand Down Expand Up @@ -491,7 +491,7 @@ func TestConfigMaps_updatePeers_same(t *testing.T) {
func TestConfigMaps_updatePeers_disconnect(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitShort)
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
logger := newMultiLogger(slogtest.Make(t, nil).Leveled(slog.LevelDebug))
fEng := newFakeEngineConfigurable()
nodePrivateKey := key.NewNode()
nodeID := tailcfg.NodeID(5)
Expand Down Expand Up @@ -559,7 +559,7 @@ func TestConfigMaps_updatePeers_disconnect(t *testing.T) {
func TestConfigMaps_updatePeers_lost(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitShort)
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
logger := newMultiLogger(slogtest.Make(t, nil).Leveled(slog.LevelDebug))
fEng := newFakeEngineConfigurable()
nodePrivateKey := key.NewNode()
nodeID := tailcfg.NodeID(5)
Expand Down Expand Up @@ -644,7 +644,7 @@ func TestConfigMaps_updatePeers_lost(t *testing.T) {
func TestConfigMaps_updatePeers_lost_and_found(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitShort)
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
logger := newMultiLogger(slogtest.Make(t, nil).Leveled(slog.LevelDebug))
fEng := newFakeEngineConfigurable()
nodePrivateKey := key.NewNode()
nodeID := tailcfg.NodeID(5)
Expand Down Expand Up @@ -729,7 +729,7 @@ func TestConfigMaps_updatePeers_lost_and_found(t *testing.T) {
func TestConfigMaps_setAllPeersLost(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitShort)
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
logger := newMultiLogger(slogtest.Make(t, nil).Leveled(slog.LevelDebug))
fEng := newFakeEngineConfigurable()
nodePrivateKey := key.NewNode()
nodeID := tailcfg.NodeID(5)
Expand Down Expand Up @@ -815,7 +815,7 @@ func TestConfigMaps_setAllPeersLost(t *testing.T) {
func TestConfigMaps_setBlockEndpoints_different(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitShort)
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
logger := newMultiLogger(slogtest.Make(t, nil).Leveled(slog.LevelDebug))
fEng := newFakeEngineConfigurable()
nodePrivateKey := key.NewNode()
nodeID := tailcfg.NodeID(5)
Expand Down Expand Up @@ -859,7 +859,7 @@ func TestConfigMaps_setBlockEndpoints_different(t *testing.T) {
func TestConfigMaps_setBlockEndpoints_same(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitShort)
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
logger := newMultiLogger(slogtest.Make(t, nil).Leveled(slog.LevelDebug))
fEng := newFakeEngineConfigurable()
nodePrivateKey := key.NewNode()
nodeID := tailcfg.NodeID(5)
Expand Down Expand Up @@ -902,7 +902,7 @@ func TestConfigMaps_setBlockEndpoints_same(t *testing.T) {
func TestConfigMaps_setDERPMap_different(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitShort)
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
logger := newMultiLogger(slogtest.Make(t, nil).Leveled(slog.LevelDebug))
fEng := newFakeEngineConfigurable()
nodePrivateKey := key.NewNode()
nodeID := tailcfg.NodeID(5)
Expand Down Expand Up @@ -943,7 +943,7 @@ func TestConfigMaps_setDERPMap_different(t *testing.T) {
func TestConfigMaps_setDERPMap_same(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitShort)
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
logger := newMultiLogger(slogtest.Make(t, nil).Leveled(slog.LevelDebug))
fEng := newFakeEngineConfigurable()
nodePrivateKey := key.NewNode()
nodeID := tailcfg.NodeID(5)
Expand Down Expand Up @@ -1012,7 +1012,7 @@ func TestConfigMaps_setDERPMap_same(t *testing.T) {
func TestConfigMaps_fillPeerDiagnostics(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitShort)
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
logger := newMultiLogger(slogtest.Make(t, nil).Leveled(slog.LevelDebug))
fEng := newFakeEngineConfigurable()
nodePrivateKey := key.NewNode()
nodeID := tailcfg.NodeID(5)
Expand Down Expand Up @@ -1120,7 +1120,7 @@ func TestConfigMaps_updatePeers_nonexist(t *testing.T) {
t.Run(k.String(), func(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitShort)
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
logger := newMultiLogger(slogtest.Make(t, nil).Leveled(slog.LevelDebug))
fEng := newFakeEngineConfigurable()
nodePrivateKey := key.NewNode()
nodeID := tailcfg.NodeID(5)
Expand Down
Loading