From feb2aa23abad43e16ebc7c5f9b14d662c2aaf6cd Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Mon, 15 Apr 2024 23:11:45 +0200 Subject: [PATCH] Improve logging for up/down changes Signed-off-by: Knut Ahlers --- pkg/servicemonitor/monitor.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/pkg/servicemonitor/monitor.go b/pkg/servicemonitor/monitor.go index e3a6721..49e62a1 100644 --- a/pkg/servicemonitor/monitor.go +++ b/pkg/servicemonitor/monitor.go @@ -76,14 +76,24 @@ func (m Monitor) updateRoutingTargets(checker healthcheck.Checker) (err error) { } if err := checker.Check(m.svc.HealthCheck.Settings, t); err != nil { - logger.WithError(err).Debug("detected target down") - changed = changed || m.ipt.UnregisterServiceTarget(m.svc.Name, tgt) + if m.ipt.UnregisterServiceTarget(m.svc.Name, tgt) { + logger.WithError(err).Warn("detected target down") + changed = true + } else { + logger.WithError(err).Debug("detected target down") + } + down = append(down, t.String()) return } - logger.Debug("target up") - changed = changed || m.ipt.RegisterServiceTarget(m.svc.Name, tgt) + if m.ipt.RegisterServiceTarget(m.svc.Name, tgt) { + logger.Info("target up") + changed = true + } else { + logger.Debug("target up") + } + up = append(up, t.String()) }() }