feat: More logging for command stream
Chart Release / chart (push) Successful in 12s
Server Deploy / deploy (push) Successful in 1m24s
Agent Release / build (push) Successful in 10m37s
Agent Release / msi (push) Successful in 36s

This commit is contained in:
2026-07-31 17:20:35 +01:00
parent 1fb9bd827f
commit 17d97aaf52
2 changed files with 69 additions and 5 deletions
+24
View File
@@ -221,18 +221,37 @@ func (s *vantageServer) CommandStream(stream pb.Vantage_CommandStreamServer) err
ping := time.NewTicker(pingInterval)
defer ping.Stop()
// Beats are counted and reported periodically rather than logged one by
// one: at one every 20s per agent, a fleet of any size would drown every
// other line in the log. What is worth a line of its own is the first beat
// (it tells the operator this stream's watchdog is now armed on the agent
// side) and any failure to send one.
var beats int
summary := time.NewTicker(pingSummaryInterval)
defer summary.Stop()
ctx := stream.Context()
for {
select {
case <-ctx.Done():
return nil
case <-summary.C:
log.Printf("agent %s command stream healthy, %d beats in the last %s",
srv.ServerID, beats, pingSummaryInterval)
beats = 0
case <-ping.C:
// A failed send is the point: it is how this side learns the stream
// is gone, which runs the deferred release and frees the agent's
// presence claim for whichever pod it reconnects to.
if err := stream.Send(&pb.ServerCommand{Ping: &pb.PingCmd{}}); err != nil {
log.Printf("agent %s command stream beat failed after %d beats: %v",
srv.ServerID, beats, err)
return err
}
beats++
if beats == 1 {
log.Printf("agent %s command stream beating every %s", srv.ServerID, pingInterval)
}
case cmd, ok := <-ch:
if !ok {
return nil
@@ -249,6 +268,11 @@ func (s *vantageServer) CommandStream(stream pb.Vantage_CommandStreamServer) err
// reconnect.
const pingInterval = 20 * time.Second
// How often an otherwise silent healthy stream says so. Long enough that a
// large fleet does not fill the log, short enough that "this pod is still
// serving that agent" is answerable from the log rather than by inference.
const pingSummaryInterval = 5 * time.Minute
// StartGRPC serves the agent API until stop is called.
//
// It returns a stop function rather than serving forever because an abrupt exit