From a19b40fb0f907523bc5e46a7de9c854a57300f42 Mon Sep 17 00:00:00 2001 From: Colin Adler Date: Wed, 25 Jan 2023 18:04:23 -0600 Subject: [PATCH 1/2] fix: ensure coordinator debug output is always sorted They were being read from a map so the output danced all over the place when refreshing often. --- tailnet/coordinator.go | 138 +++++++++++++++++++++++++++-------------- 1 file changed, 93 insertions(+), 45 deletions(-) diff --git a/tailnet/coordinator.go b/tailnet/coordinator.go index 1373b370a5def..d3f0aee57b99e 100644 --- a/tailnet/coordinator.go +++ b/tailnet/coordinator.go @@ -14,6 +14,7 @@ import ( "time" "github.com/google/uuid" + "golang.org/x/exp/slices" "golang.org/x/xerrors" "tailscale.com/tailcfg" "tailscale.com/types/key" @@ -444,62 +445,109 @@ func (c *coordinator) ServeHTTPDebug(w http.ResponseWriter, _ *http.Request) { defer c.mutex.RUnlock() fmt.Fprintln(w, "

in-memory wireguard coordinator debug

") - fmt.Fprintf(w, "

# agents: total %d

\n", len(c.agentSockets)) - fmt.Fprintln(w, "") - missingAgents := map[uuid.UUID]map[uuid.UUID]*trackedConn{} - for agentID, conns := range c.agentToConnectionSockets { - if len(conns) == 0 { - continue + { + fmt.Fprintf(w, "

# agents: total %d

\n", len(c.agentSockets)) + fmt.Fprintln(w, "") } - fmt.Fprintf(w, "

# missing agents: total %d

\n", len(missingAgents)) - fmt.Fprintln(w, "") } From 63a425b6f4df4b410afee3cbfa7a265c0ccdc6bb Mon Sep 17 00:00:00 2001 From: Colin Adler Date: Wed, 25 Jan 2023 18:19:16 -0600 Subject: [PATCH 2/2] better formatting --- tailnet/coordinator.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tailnet/coordinator.go b/tailnet/coordinator.go index d3f0aee57b99e..cd5e0e41d6def 100644 --- a/tailnet/coordinator.go +++ b/tailnet/coordinator.go @@ -465,7 +465,7 @@ func (c *coordinator) ServeHTTPDebug(w http.ResponseWriter, _ *http.Request) { }) for _, agent := range agentSockets { - fmt.Fprintf(w, "
  • %s (%s): created %v ago, write %v ago, overwrites %d
  • \n", + fmt.Fprintf(w, "
  • %s (%s): created %v ago, write %v ago, overwrites %d
  • \n", agent.conn.name, agent.id.String(), now.Sub(time.Unix(agent.conn.start, 0)).Round(time.Second), @@ -474,7 +474,7 @@ func (c *coordinator) ServeHTTPDebug(w http.ResponseWriter, _ *http.Request) { ) if conns := c.agentToConnectionSockets[agent.id]; len(conns) > 0 { - fmt.Fprintf(w, "

    connections: total %d

    \n", len(conns)) + fmt.Fprintf(w, "

    connections: total %d

    \n", len(conns)) connSockets := make([]idConn, 0, len(conns)) for id, conn := range conns { @@ -486,7 +486,7 @@ func (c *coordinator) ServeHTTPDebug(w http.ResponseWriter, _ *http.Request) { fmt.Fprintln(w, "