Skip to content

Commit 6b92abe

Browse files
authored
fix(tailnet): track agent names for http debug (#8744)
1 parent b5dec61 commit 6b92abe

File tree

5 files changed

+23
-18
lines changed

5 files changed

+23
-18
lines changed

enterprise/tailnet/coordinator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func (c *haCoordinator) ServeClient(conn net.Conn, id, agentID uuid.UUID) error
158158
defer cancel()
159159
logger := c.clientLogger(id, agentID)
160160

161-
tc := agpl.NewTrackedConn(ctx, cancel, conn, id, logger, 0)
161+
tc := agpl.NewTrackedConn(ctx, cancel, conn, id, logger, id.String(), 0)
162162
defer tc.Close()
163163

164164
c.addClient(id, tc)
@@ -301,7 +301,7 @@ func (c *haCoordinator) ServeAgent(conn net.Conn, id uuid.UUID, name string) err
301301
}
302302
// This uniquely identifies a connection that belongs to this goroutine.
303303
unique := uuid.New()
304-
tc := agpl.NewTrackedConn(ctx, cancel, conn, unique, logger, overwrites)
304+
tc := agpl.NewTrackedConn(ctx, cancel, conn, unique, logger, name, overwrites)
305305

306306
// Publish all nodes on this instance that want to connect to this agent.
307307
nodes := c.nodesSubscribedToAgent(id)

enterprise/tailnet/pgcoord.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,6 @@ func (c *pgCoord) ServeMultiAgent(id uuid.UUID) agpl.MultiAgentConn {
131131
panic("not implemented") // TODO: Implement
132132
}
133133

134-
func (*pgCoord) ServeHTTPDebug(w http.ResponseWriter, _ *http.Request) {
135-
// TODO(spikecurtis) I'd like to hold off implementing this until after the rest of this is code reviewed.
136-
w.WriteHeader(http.StatusOK)
137-
_, _ = w.Write([]byte("Coder Enterprise PostgreSQL distributed tailnet coordinator"))
138-
}
139-
140134
func (c *pgCoord) Node(id uuid.UUID) *agpl.Node {
141135
// In production, we only ever get this request for an agent.
142136
// We're going to directly query the database, since we would only have the agent mapping stored locally if we had
@@ -167,7 +161,7 @@ func (c *pgCoord) ServeClient(conn net.Conn, id uuid.UUID, agent uuid.UUID) erro
167161
slog.Error(err))
168162
}
169163
}()
170-
cIO := newConnIO(c.ctx, c.logger, c.bindings, conn, id, agent)
164+
cIO := newConnIO(c.ctx, c.logger, c.bindings, conn, id, agent, id.String())
171165
if err := sendCtx(c.ctx, c.newConnections, cIO); err != nil {
172166
// can only be a context error, no need to log here.
173167
return err
@@ -186,7 +180,7 @@ func (c *pgCoord) ServeAgent(conn net.Conn, id uuid.UUID, name string) error {
186180
}
187181
}()
188182
logger := c.logger.With(slog.F("name", name))
189-
cIO := newConnIO(c.ctx, logger, c.bindings, conn, uuid.Nil, id)
183+
cIO := newConnIO(c.ctx, logger, c.bindings, conn, uuid.Nil, id, name)
190184
if err := sendCtx(c.ctx, c.newConnections, cIO); err != nil {
191185
// can only be a context error, no need to log here.
192186
return err
@@ -217,8 +211,12 @@ type connIO struct {
217211
bindings chan<- binding
218212
}
219213

220-
func newConnIO(
221-
pCtx context.Context, logger slog.Logger, bindings chan<- binding, conn net.Conn, client, agent uuid.UUID,
214+
func newConnIO(pCtx context.Context,
215+
logger slog.Logger,
216+
bindings chan<- binding,
217+
conn net.Conn,
218+
client, agent uuid.UUID,
219+
name string,
222220
) *connIO {
223221
ctx, cancel := context.WithCancel(pCtx)
224222
id := agent
@@ -235,7 +233,7 @@ func newConnIO(
235233
client: client,
236234
agent: agent,
237235
decoder: json.NewDecoder(conn),
238-
updates: agpl.NewTrackedConn(ctx, cancel, conn, id, logger, 0),
236+
updates: agpl.NewTrackedConn(ctx, cancel, conn, id, logger, name, 0),
239237
bindings: bindings,
240238
}
241239
go c.recvLoop()
@@ -1291,3 +1289,9 @@ func (h *heartbeats) cleanup() {
12911289
}
12921290
h.logger.Debug(h.ctx, "cleaned up old coordinators")
12931291
}
1292+
1293+
func (*pgCoord) ServeHTTPDebug(w http.ResponseWriter, _ *http.Request) {
1294+
// TODO(spikecurtis) I'd like to hold off implementing this until after the rest of this is code reviewed.
1295+
w.WriteHeader(http.StatusOK)
1296+
_, _ = w.Write([]byte("Coder Enterprise PostgreSQL distributed tailnet coordinator"))
1297+
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ require (
9191
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf
9292
github.com/creack/pty v1.1.18
9393
github.com/dave/dst v0.27.2
94+
github.com/davecgh/go-spew v1.1.1
9495
github.com/elastic/go-sysinfo v1.11.0
9596
github.com/fatih/color v1.15.0
9697
github.com/fatih/structs v1.1.0
@@ -187,6 +188,7 @@ require (
187188
nhooyr.io/websocket v1.8.7
188189
storj.io/drpc v0.0.33-0.20230420154621-9716137f6037
189190
tailscale.com v1.32.3
191+
golang.org/x/net v0.12.0
190192
)
191193

192194
require (
@@ -222,7 +224,6 @@ require (
222224
github.com/containerd/console v1.0.3 // indirect
223225
github.com/containerd/continuity v0.3.0 // indirect
224226
github.com/coreos/go-iptables v0.6.0 // indirect
225-
github.com/davecgh/go-spew v1.1.1 // indirect
226227
github.com/dlclark/regexp2 v1.10.0 // indirect
227228
github.com/docker/cli v20.10.17+incompatible // indirect
228229
github.com/docker/docker v23.0.3+incompatible // indirect
@@ -355,7 +356,6 @@ require (
355356
go.opentelemetry.io/otel/metric v1.16.0 // indirect
356357
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
357358
go4.org/mem v0.0.0-20210711025021-927187094b94 // indirect
358-
golang.org/x/net v0.12.0
359359
golang.org/x/text v0.11.0 // indirect
360360
golang.org/x/time v0.3.0 // indirect
361361
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect

tailnet/coordinator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func (c *coordinator) ServeClient(conn net.Conn, id, agentID uuid.UUID) error {
262262
logger := c.core.clientLogger(id, agentID)
263263
logger.Debug(ctx, "coordinating client")
264264

265-
tc := NewTrackedConn(ctx, cancel, conn, id, logger, 0)
265+
tc := NewTrackedConn(ctx, cancel, conn, id, logger, id.String(), 0)
266266
defer tc.Close()
267267

268268
c.core.addClient(id, tc)
@@ -507,7 +507,7 @@ func (c *core) initAndTrackAgent(ctx context.Context, cancel func(), conn net.Co
507507
overwrites = oldAgentSocket.Overwrites() + 1
508508
_ = oldAgentSocket.Close()
509509
}
510-
tc := NewTrackedConn(ctx, cancel, conn, unique, logger, overwrites)
510+
tc := NewTrackedConn(ctx, cancel, conn, unique, logger, name, overwrites)
511511
c.agentNameCache.Add(id, name)
512512

513513
sockets, ok := c.agentToConnectionSockets[id]

tailnet/trackedconn.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type TrackedConn struct {
3535
overwrites int64
3636
}
3737

38-
func NewTrackedConn(ctx context.Context, cancel func(), conn net.Conn, id uuid.UUID, logger slog.Logger, overwrites int64) *TrackedConn {
38+
func NewTrackedConn(ctx context.Context, cancel func(), conn net.Conn, id uuid.UUID, logger slog.Logger, name string, overwrites int64) *TrackedConn {
3939
// buffer updates so they don't block, since we hold the
4040
// coordinator mutex while queuing. Node updates don't
4141
// come quickly, so 512 should be plenty for all but
@@ -51,6 +51,7 @@ func NewTrackedConn(ctx context.Context, cancel func(), conn net.Conn, id uuid.U
5151
id: id,
5252
start: now,
5353
lastWrite: now,
54+
name: name,
5455
overwrites: overwrites,
5556
}
5657
}

0 commit comments

Comments
 (0)