Skip to content

Commit

Permalink
improve agent logs
Browse files Browse the repository at this point in the history
  • Loading branch information
henrod committed Oct 23, 2019
1 parent 26e1c39 commit e6fe458
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (a *Agent) RemoteAddr() net.Addr {

// String, implementation for Stringer interface
func (a *Agent) String() string {
return fmt.Sprintf("Remote=%s, LastTime=%d", a.conn.RemoteAddr().String(), atomic.LoadInt64(&a.lastAt))
return fmt.Sprintf("Remote=%s, LastTime=%d, ID=%d", a.conn.RemoteAddr().String(), atomic.LoadInt64(&a.lastAt), a.Session.ID())
}

// GetStatus gets the status
Expand Down Expand Up @@ -304,15 +304,17 @@ func (a *Agent) heartbeat() {
case <-ticker.C:
deadline := time.Now().Add(-2 * a.heartbeatTimeout).Unix()
if atomic.LoadInt64(&a.lastAt) < deadline {
logger.Log.Debugf("Session heartbeat timeout, LastTime=%d, Deadline=%d", atomic.LoadInt64(&a.lastAt), deadline)
logger.Log.Debugf("Session heartbeat timeout, LastTime=%d, Deadline=%d, ID=%d", atomic.LoadInt64(&a.lastAt), deadline, a.Session.ID())
return
}
if _, err := a.conn.Write(hbd); err != nil {
logger.Log.Errorf("Failed to send heartbeat, ID=%d", a.Session.ID())
return
}
case <-a.chDie:
return
case <-a.chStopHeartbeat:
logger.Log.Debugf("Stopping session heartbeat, ID=%d", a.Session.ID())
return
}
}
Expand Down
2 changes: 1 addition & 1 deletion agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ func TestAgentString(t *testing.T) {
assert.NotNil(t, ag)

mockConn.EXPECT().RemoteAddr().Return(&mockAddr{})
expected := fmt.Sprintf("Remote=remote-string, LastTime=%d", ag.lastAt)
expected := fmt.Sprintf("Remote=remote-string, LastTime=%d, ID=%d", ag.lastAt, ag.Session.ID())
str := ag.String()
assert.Equal(t, expected, str)
}
Expand Down

0 comments on commit e6fe458

Please sign in to comment.