From f29717ee3f7e57b8708e85852021ef6a7b6410bd Mon Sep 17 00:00:00 2001 From: Andrzej Stencel Date: Wed, 4 Sep 2024 08:32:03 +0200 Subject: [PATCH] Add debug log for check-in miss (#5348) * Add debug log for check-in miss Logging the time details to debug flaky tests like https://github.com/elastic/elastic-agent/issues/4203. * fix errcheck linter * Log with `logp.Logger`'s `Debugf` function --- pkg/component/runtime/command.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/component/runtime/command.go b/pkg/component/runtime/command.go index 41917f31347..13bf49c07e6 100644 --- a/pkg/component/runtime/command.go +++ b/pkg/component/runtime/command.go @@ -67,6 +67,7 @@ type procState struct { // commandRuntime provides the command runtime for running a component as a subprocess. type commandRuntime struct { + log *logger.Logger logStd *logWriter logErr *logWriter @@ -108,6 +109,7 @@ type commandRuntime struct { // newCommandRuntime creates a new command runtime for the provided component. func newCommandRuntime(comp component.Component, log *logger.Logger, monitor MonitoringManager) (*commandRuntime, error) { c := &commandRuntime{ + log: log, current: comp, monitor: monitor, ch: make(chan ComponentState), @@ -238,6 +240,7 @@ func (c *commandRuntime) Run(ctx context.Context, comm Communicator) error { c.missedCheckins = 0 } else { c.missedCheckins++ + c.log.Debugf("Last check-in was: %s, now is: %s. The diff %s is higher than allowed %s.", c.lastCheckin.Format(time.RFC3339Nano), now.Format(time.RFC3339Nano), now.Sub(c.lastCheckin), checkinPeriod) } if c.missedCheckins == 0 { c.compState(client.UnitStateHealthy)