From 51317bb788a9de2ba0ab29fb71d54231be615acc Mon Sep 17 00:00:00 2001 From: Colin Adler Date: Wed, 26 Jul 2023 17:55:35 +0000 Subject: [PATCH 1/3] fix(tailnet): track agent names for http debug These were previously not passed through. --- enterprise/tailnet/coordinator.go | 4 ++-- enterprise/tailnet/pgcoord.go | 26 +++++++++++++++----------- go.mod | 4 ++-- tailnet/coordinator.go | 4 ++-- tailnet/trackedconn.go | 2 +- 5 files changed, 22 insertions(+), 18 deletions(-) diff --git a/enterprise/tailnet/coordinator.go b/enterprise/tailnet/coordinator.go index 672095eb3a989..f8c8ccdc921dd 100644 --- a/enterprise/tailnet/coordinator.go +++ b/enterprise/tailnet/coordinator.go @@ -158,7 +158,7 @@ func (c *haCoordinator) ServeClient(conn net.Conn, id, agentID uuid.UUID) error defer cancel() logger := c.clientLogger(id, agentID) - tc := agpl.NewTrackedConn(ctx, cancel, conn, id, logger, 0) + tc := agpl.NewTrackedConn(ctx, cancel, conn, id, logger, "", 0) defer tc.Close() c.addClient(id, tc) @@ -301,7 +301,7 @@ func (c *haCoordinator) ServeAgent(conn net.Conn, id uuid.UUID, name string) err } // This uniquely identifies a connection that belongs to this goroutine. unique := uuid.New() - tc := agpl.NewTrackedConn(ctx, cancel, conn, unique, logger, overwrites) + tc := agpl.NewTrackedConn(ctx, cancel, conn, unique, logger, name, overwrites) // Publish all nodes on this instance that want to connect to this agent. nodes := c.nodesSubscribedToAgent(id) diff --git a/enterprise/tailnet/pgcoord.go b/enterprise/tailnet/pgcoord.go index e73c3e29bf56e..a5bc31d0ed025 100644 --- a/enterprise/tailnet/pgcoord.go +++ b/enterprise/tailnet/pgcoord.go @@ -131,12 +131,6 @@ func (c *pgCoord) ServeMultiAgent(id uuid.UUID) agpl.MultiAgentConn { panic("not implemented") // TODO: Implement } -func (*pgCoord) ServeHTTPDebug(w http.ResponseWriter, _ *http.Request) { - // TODO(spikecurtis) I'd like to hold off implementing this until after the rest of this is code reviewed. - w.WriteHeader(http.StatusOK) - _, _ = w.Write([]byte("Coder Enterprise PostgreSQL distributed tailnet coordinator")) -} - func (c *pgCoord) Node(id uuid.UUID) *agpl.Node { // In production, we only ever get this request for an agent. // 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 slog.Error(err)) } }() - cIO := newConnIO(c.ctx, c.logger, c.bindings, conn, id, agent) + cIO := newConnIO(c.ctx, c.logger, c.bindings, conn, id, agent, "") if err := sendCtx(c.ctx, c.newConnections, cIO); err != nil { // can only be a context error, no need to log here. return err @@ -186,7 +180,7 @@ func (c *pgCoord) ServeAgent(conn net.Conn, id uuid.UUID, name string) error { } }() logger := c.logger.With(slog.F("name", name)) - cIO := newConnIO(c.ctx, logger, c.bindings, conn, uuid.Nil, id) + cIO := newConnIO(c.ctx, logger, c.bindings, conn, uuid.Nil, id, name) if err := sendCtx(c.ctx, c.newConnections, cIO); err != nil { // can only be a context error, no need to log here. return err @@ -217,8 +211,12 @@ type connIO struct { bindings chan<- binding } -func newConnIO( - pCtx context.Context, logger slog.Logger, bindings chan<- binding, conn net.Conn, client, agent uuid.UUID, +func newConnIO(pCtx context.Context, + logger slog.Logger, + bindings chan<- binding, + conn net.Conn, + client, agent uuid.UUID, + name string, ) *connIO { ctx, cancel := context.WithCancel(pCtx) id := agent @@ -235,7 +233,7 @@ func newConnIO( client: client, agent: agent, decoder: json.NewDecoder(conn), - updates: agpl.NewTrackedConn(ctx, cancel, conn, id, logger, 0), + updates: agpl.NewTrackedConn(ctx, cancel, conn, id, logger, name, 0), bindings: bindings, } go c.recvLoop() @@ -1291,3 +1289,9 @@ func (h *heartbeats) cleanup() { } h.logger.Debug(h.ctx, "cleaned up old coordinators") } + +func (*pgCoord) ServeHTTPDebug(w http.ResponseWriter, _ *http.Request) { + // TODO(spikecurtis) I'd like to hold off implementing this until after the rest of this is code reviewed. + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte("Coder Enterprise PostgreSQL distributed tailnet coordinator")) +} diff --git a/go.mod b/go.mod index c62fc6b535427..a6343f1ef6391 100644 --- a/go.mod +++ b/go.mod @@ -91,6 +91,7 @@ require ( github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf github.com/creack/pty v1.1.18 github.com/dave/dst v0.27.2 + github.com/davecgh/go-spew v1.1.1 github.com/elastic/go-sysinfo v1.11.0 github.com/fatih/color v1.15.0 github.com/fatih/structs v1.1.0 @@ -187,6 +188,7 @@ require ( nhooyr.io/websocket v1.8.7 storj.io/drpc v0.0.33-0.20230420154621-9716137f6037 tailscale.com v1.32.3 + golang.org/x/net v0.12.0 ) require ( @@ -222,7 +224,6 @@ require ( github.com/containerd/console v1.0.3 // indirect github.com/containerd/continuity v0.3.0 // indirect github.com/coreos/go-iptables v0.6.0 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect github.com/dlclark/regexp2 v1.10.0 // indirect github.com/docker/cli v20.10.17+incompatible // indirect github.com/docker/docker v23.0.3+incompatible // indirect @@ -355,7 +356,6 @@ require ( go.opentelemetry.io/otel/metric v1.16.0 // indirect go.opentelemetry.io/proto/otlp v0.19.0 // indirect go4.org/mem v0.0.0-20210711025021-927187094b94 // indirect - golang.org/x/net v0.12.0 golang.org/x/text v0.11.0 // indirect golang.org/x/time v0.3.0 // indirect golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect diff --git a/tailnet/coordinator.go b/tailnet/coordinator.go index 51c95aca4d2e6..0557f2a6350b2 100644 --- a/tailnet/coordinator.go +++ b/tailnet/coordinator.go @@ -262,7 +262,7 @@ func (c *coordinator) ServeClient(conn net.Conn, id, agentID uuid.UUID) error { logger := c.core.clientLogger(id, agentID) logger.Debug(ctx, "coordinating client") - tc := NewTrackedConn(ctx, cancel, conn, id, logger, 0) + tc := NewTrackedConn(ctx, cancel, conn, id, logger, "", 0) defer tc.Close() c.core.addClient(id, tc) @@ -507,7 +507,7 @@ func (c *core) initAndTrackAgent(ctx context.Context, cancel func(), conn net.Co overwrites = oldAgentSocket.Overwrites() + 1 _ = oldAgentSocket.Close() } - tc := NewTrackedConn(ctx, cancel, conn, unique, logger, overwrites) + tc := NewTrackedConn(ctx, cancel, conn, unique, logger, name, overwrites) c.agentNameCache.Add(id, name) sockets, ok := c.agentToConnectionSockets[id] diff --git a/tailnet/trackedconn.go b/tailnet/trackedconn.go index cedd6e37dbc8d..ad92c05b032c4 100644 --- a/tailnet/trackedconn.go +++ b/tailnet/trackedconn.go @@ -35,7 +35,7 @@ type TrackedConn struct { overwrites int64 } -func NewTrackedConn(ctx context.Context, cancel func(), conn net.Conn, id uuid.UUID, logger slog.Logger, overwrites int64) *TrackedConn { +func NewTrackedConn(ctx context.Context, cancel func(), conn net.Conn, id uuid.UUID, logger slog.Logger, name string, overwrites int64) *TrackedConn { // buffer updates so they don't block, since we hold the // coordinator mutex while queuing. Node updates don't // come quickly, so 512 should be plenty for all but From 7f39ef2ebcdbb2fcea5ac55304c0e0402d7cfa38 Mon Sep 17 00:00:00 2001 From: Colin Adler Date: Wed, 26 Jul 2023 18:22:11 +0000 Subject: [PATCH 2/3] fixup! fix(tailnet): track agent names for http debug --- tailnet/trackedconn.go | 1 + 1 file changed, 1 insertion(+) diff --git a/tailnet/trackedconn.go b/tailnet/trackedconn.go index ad92c05b032c4..0ec19695ba29f 100644 --- a/tailnet/trackedconn.go +++ b/tailnet/trackedconn.go @@ -51,6 +51,7 @@ func NewTrackedConn(ctx context.Context, cancel func(), conn net.Conn, id uuid.U id: id, start: now, lastWrite: now, + name: name, overwrites: overwrites, } } From 3f454926e6a9731ed24ef3c66d824a6dedef8393 Mon Sep 17 00:00:00 2001 From: Colin Adler Date: Wed, 26 Jul 2023 18:29:06 +0000 Subject: [PATCH 3/3] fixup! fix(tailnet): track agent names for http debug --- enterprise/tailnet/coordinator.go | 2 +- enterprise/tailnet/pgcoord.go | 2 +- tailnet/coordinator.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/enterprise/tailnet/coordinator.go b/enterprise/tailnet/coordinator.go index f8c8ccdc921dd..12c3d3ad38bd8 100644 --- a/enterprise/tailnet/coordinator.go +++ b/enterprise/tailnet/coordinator.go @@ -158,7 +158,7 @@ func (c *haCoordinator) ServeClient(conn net.Conn, id, agentID uuid.UUID) error defer cancel() logger := c.clientLogger(id, agentID) - tc := agpl.NewTrackedConn(ctx, cancel, conn, id, logger, "", 0) + tc := agpl.NewTrackedConn(ctx, cancel, conn, id, logger, id.String(), 0) defer tc.Close() c.addClient(id, tc) diff --git a/enterprise/tailnet/pgcoord.go b/enterprise/tailnet/pgcoord.go index a5bc31d0ed025..cb577fe271354 100644 --- a/enterprise/tailnet/pgcoord.go +++ b/enterprise/tailnet/pgcoord.go @@ -161,7 +161,7 @@ func (c *pgCoord) ServeClient(conn net.Conn, id uuid.UUID, agent uuid.UUID) erro slog.Error(err)) } }() - cIO := newConnIO(c.ctx, c.logger, c.bindings, conn, id, agent, "") + cIO := newConnIO(c.ctx, c.logger, c.bindings, conn, id, agent, id.String()) if err := sendCtx(c.ctx, c.newConnections, cIO); err != nil { // can only be a context error, no need to log here. return err diff --git a/tailnet/coordinator.go b/tailnet/coordinator.go index 0557f2a6350b2..23e3bad99fc65 100644 --- a/tailnet/coordinator.go +++ b/tailnet/coordinator.go @@ -262,7 +262,7 @@ func (c *coordinator) ServeClient(conn net.Conn, id, agentID uuid.UUID) error { logger := c.core.clientLogger(id, agentID) logger.Debug(ctx, "coordinating client") - tc := NewTrackedConn(ctx, cancel, conn, id, logger, "", 0) + tc := NewTrackedConn(ctx, cancel, conn, id, logger, id.String(), 0) defer tc.Close() c.core.addClient(id, tc) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy