Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: tailnet debug logging#7260

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
spikecurtis merged 10 commits intomainfromspike/debug-tailnet
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from1 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
PrevPrevious commit
Clarify logs; remove unrelated changes
Signed-off-by: Spike Curtis <spike@coder.com>
  • Loading branch information
@spikecurtis
spikecurtis committedApr 27, 2023
commit96d43cbaa593366db352345df2afdf35122ea893
13 changes: 7 additions & 6 deletionsagent/agent.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1064,12 +1064,13 @@ func (a *agent) handleReconnectingPTY(ctx context.Context, logger slog.Logger, m
rpty.activeConnsMutex.Lock()
for cid, conn := range rpty.activeConns {
_, err = conn.Write(part)
logger.Debug(ctx,
"wrote to active conn",
slog.F("other_conn_id", cid),
slog.F("data", part),
slog.Error(err),
)
if err != nil {
logger.Debug(ctx,
"error writing to active conn",
slog.F("other_conn_id", cid),
slog.Error(err),
)
}
}
rpty.activeConnsMutex.Unlock()
}
Expand Down
2 changes: 1 addition & 1 deletionagent/agent_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -714,7 +714,7 @@ func TestAgent_UnixRemoteForwarding(t *testing.T) {
var err error
conn, err = net.Dial("unix", remoteSocketPath)
return err == nil
}, testutil.WaitShort, testutil.IntervalFast)
}, testutil.WaitLong, testutil.IntervalFast)
defer conn.Close()
_, err = conn.Write([]byte("test"))
require.NoError(t, err)
Expand Down
34 changes: 18 additions & 16 deletionstailnet/coordinator.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -113,7 +113,7 @@ func ServeCoordinator(conn net.Conn, updateNodes func(node []*Node) error) (func
}, errChan
}

constLoggerName = "coord"
constloggerName = "coord"

// NewCoordinator constructs a new in-memory connection coordinator. This
// coordinator is incompatible with multiple Coder replicas as all node data is
Expand All@@ -125,7 +125,7 @@ func NewCoordinator(logger slog.Logger) Coordinator {
}

return &coordinator{
logger: logger.Named(LoggerName),
logger: logger.Named(loggerName),
closed: false,
nodes: map[uuid.UUID]*Node{},
agentSockets: map[uuid.UUID]*TrackedConn{},
Expand DownExpand Up@@ -201,7 +201,7 @@ func (c *coordinator) AgentCount() int {
// with the specified ID.
func (c *coordinator) ServeClient(conn net.Conn, id uuid.UUID, agent uuid.UUID) error {
logger := c.logger.With(slog.F("client_id", id), slog.F("agent_id", agent))
logger.Debug(context.TODO(), "coordinating client")
logger.Debug(context.Background(), "coordinating client")
c.mutex.Lock()
if c.closed {
c.mutex.Unlock()
Expand All@@ -218,7 +218,7 @@ func (c *coordinator) ServeClient(conn net.Conn, id uuid.UUID, agent uuid.UUID)
return xerrors.Errorf("marshal node: %w", err)
}
_, err = conn.Write(data)
logger.Debug(context.TODO(), "wrote initial node")
logger.Debug(context.Background(), "wrote initial node")
if err != nil {
return xerrors.Errorf("write nodes: %w", err)
}
Expand All@@ -239,22 +239,24 @@ func (c *coordinator) ServeClient(conn net.Conn, id uuid.UUID, agent uuid.UUID)
LastWrite: now,
}
c.mutex.Unlock()
logger.Debug(context.TODO(), "added tracked connection")
logger.Debug(context.Background(), "added tracked connection")
defer func() {
logger.Debug(context.TODO(), "deleting tracked connection")
c.mutex.Lock()
defer c.mutex.Unlock()
// Clean all traces of this connection from the map.
delete(c.nodes, id)
logger.Debug(context.Background(), "deleted client node")
connectionSockets, ok := c.agentToConnectionSockets[agent]
if !ok {
return
}
delete(connectionSockets, id)
logger.Debug(context.Background(), "deleted client connectionSocket from map")
if len(connectionSockets) != 0 {
return
}
delete(c.agentToConnectionSockets, agent)
logger.Debug(context.Background(), "deleted last client connectionSocket from map")
}()

decoder := json.NewDecoder(conn)
Expand All@@ -276,7 +278,7 @@ func (c *coordinator) handleNextClientMessage(id, agent uuid.UUID, decoder *json
if err != nil {
return xerrors.Errorf("read json: %w", err)
}
logger.Debug(context.TODO(), "got client node update", slog.F("node", node))
logger.Debug(context.Background(), "got client node update", slog.F("node", node))

c.mutex.Lock()
// Update the node of this client in our in-memory map. If an agent entirely
Expand All@@ -287,7 +289,7 @@ func (c *coordinator) handleNextClientMessage(id, agent uuid.UUID, decoder *json
agentSocket, ok := c.agentSockets[agent]
if !ok {
c.mutex.Unlock()
logger.Debug(context.TODO(), "no agent socket")
logger.Debug(context.Background(), "no agent socket, unable to send node")
return nil
}
c.mutex.Unlock()
Expand All@@ -305,7 +307,7 @@ func (c *coordinator) handleNextClientMessage(id, agent uuid.UUID, decoder *json
}
return xerrors.Errorf("write json: %w", err)
}
logger.Debug(context.TODO(), "sent client node to agent")
logger.Debug(context.Background(), "sent client node to agent")

return nil
}
Expand All@@ -314,7 +316,7 @@ func (c *coordinator) handleNextClientMessage(id, agent uuid.UUID, decoder *json
// listens to incoming connections and publishes node updates.
func (c *coordinator) ServeAgent(conn net.Conn, id uuid.UUID, name string) error {
logger := c.logger.With(slog.F("agent_id", id))
logger.Debug(context.TODO(), "coordinating agent")
logger.Debug(context.Background(), "coordinating agent")
c.mutex.Lock()
if c.closed {
c.mutex.Unlock()
Expand All@@ -341,7 +343,7 @@ func (c *coordinator) ServeAgent(conn net.Conn, id uuid.UUID, name string) error
return xerrors.Errorf("marshal json: %w", err)
}
_, err = conn.Write(data)
logger.Debug(context.TODO(), "wrote initial client(s) to agent", slog.F("nodes", nodes))
logger.Debug(context.Background(), "wrote initial client(s) to agent", slog.F("nodes", nodes))
if err != nil {
return xerrors.Errorf("write nodes: %w", err)
}
Expand DownExpand Up@@ -374,7 +376,7 @@ func (c *coordinator) ServeAgent(conn net.Conn, id uuid.UUID, name string) error
}

c.mutex.Unlock()
logger.Debug(context.TODO(), "added agent socket")
logger.Debug(context.Background(), "added agent socket")
defer func() {
c.mutex.Lock()
defer c.mutex.Unlock()
Expand All@@ -384,7 +386,7 @@ func (c *coordinator) ServeAgent(conn net.Conn, id uuid.UUID, name string) error
if idConn, ok := c.agentSockets[id]; ok && idConn.ID == unique {
delete(c.agentSockets, id)
delete(c.nodes, id)
logger.Debug(context.TODO(), "deleted agent socket")
logger.Debug(context.Background(), "deleted agent socket")
}
}()

Expand All@@ -407,14 +409,14 @@ func (c *coordinator) handleNextAgentMessage(id uuid.UUID, decoder *json.Decoder
if err != nil {
return xerrors.Errorf("read json: %w", err)
}
logger.Debug(context.TODO(), "decoded agent node", slog.F("node", node))
logger.Debug(context.Background(), "decoded agent node", slog.F("node", node))

c.mutex.Lock()
c.nodes[id] = &node
connectionSockets, ok := c.agentToConnectionSockets[id]
if !ok {
c.mutex.Unlock()
logger.Debug(context.TODO(), "no client sockets")
logger.Debug(context.Background(), "no client sockets; unable to send node")
return nil
}
data, err := json.Marshal([]*Node{&node})
Expand All@@ -432,7 +434,7 @@ func (c *coordinator) handleNextAgentMessage(id uuid.UUID, decoder *json.Decoder
go func() {
_ = connectionSocket.SetWriteDeadline(time.Now().Add(5 * time.Second))
_, err := connectionSocket.Write(data)
logger.Debug(context.TODO(), "sent agent node to client",
logger.Debug(context.Background(), "sent agent node to client",
slog.F("client_id", clientID), slog.Error(err))
wg.Done()
}()
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp