From 271c0baff7921842bac0e273c959c28fc044180b Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Tue, 16 Apr 2024 16:17:00 +0200 Subject: [PATCH] Streamline `zap.*` log context keys --- internal/config/runtime.go | 4 ++-- internal/icinga2/client.go | 4 ++-- internal/icinga2/client_api.go | 4 ++-- internal/icinga2/launcher.go | 6 +++--- internal/listener/listener.go | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/config/runtime.go b/internal/config/runtime.go index b079fe142..0d4899a17 100644 --- a/internal/config/runtime.go +++ b/internal/config/runtime.go @@ -166,12 +166,12 @@ func (r *RuntimeConfig) GetSourceFromCredentials(user, pass string, logger *logg sourceIdRaw, sourceIdOk := strings.CutPrefix(user, "source-") if !sourceIdOk { - logger.Debugw("Cannot extract source ID from HTTP basic auth username", zap.String("user-input", user)) + logger.Debugw("Cannot extract source ID from HTTP basic auth username", zap.String("user_input", user)) return nil } sourceId, err := strconv.ParseInt(sourceIdRaw, 10, 64) if err != nil { - logger.Debugw("Cannot convert extracted source Id to int", zap.String("user-input", user), zap.Error(err)) + logger.Debugw("Cannot convert extracted source Id to int", zap.String("user_input", user), zap.Error(err)) return nil } diff --git a/internal/icinga2/client.go b/internal/icinga2/client.go index 62dc0d3ae..609ac473d 100644 --- a/internal/icinga2/client.go +++ b/internal/icinga2/client.go @@ -230,7 +230,7 @@ func (client *Client) startCatchupWorkers(delay time.Duration) (chan *catchupEve if err != nil && !errors.Is(err, context.Canceled) { client.Logger.Debugw("Catch-up-phase event worker failed", zap.Stringer("worker", workerId), - zap.String("object type", objType), + zap.String("object_type", objType), zap.Error(err)) } return err @@ -364,7 +364,7 @@ func (client *Client) worker() { client.Logger.Debugw("Event to be replayed is not in cache", zap.Stringer("event", ev)) } else if ev.Time.Before(ts) { client.Logger.Debugw("Skip replaying outdated Event Stream event", zap.Stringer("event", ev), - zap.Time("event timestamp", ev.Time), zap.Time("cache timestamp", ts)) + zap.Time("event_timestamp", ev.Time), zap.Time("cache_timestamp", ts)) break } diff --git a/internal/icinga2/client_api.go b/internal/icinga2/client_api.go index 33fc67e27..39e3f02b6 100644 --- a/internal/icinga2/client_api.go +++ b/internal/icinga2/client_api.go @@ -211,8 +211,8 @@ func (client *Client) checkMissedChanges(ctx context.Context, objType string, ca var stateChangeEvents, acknowledgementEvents int defer func() { client.Logger.Debugw("Querying API emitted events", - zap.String("object type", objType), - zap.Int("state changes", stateChangeEvents), + zap.String("object_type", objType), + zap.Int("state_changes", stateChangeEvents), zap.Int("acknowledgements", acknowledgementEvents)) }() diff --git a/internal/icinga2/launcher.go b/internal/icinga2/launcher.go index 346ae8b55..1a52b8072 100644 --- a/internal/icinga2/launcher.go +++ b/internal/icinga2/launcher.go @@ -40,7 +40,7 @@ func (launcher *Launcher) Launch(src *config.Source) { if !launcher.isReady { launcher.Logs.GetChildLogger("icinga2"). - With(zap.Int64("source-id", src.ID)). + With(zap.Int64("source_id", src.ID)). Debug("Postponing Event Stream Client Launch as Launcher is not ready yet") launcher.waitingSources = append(launcher.waitingSources, src) return @@ -57,7 +57,7 @@ func (launcher *Launcher) Ready() { launcher.isReady = true for _, src := range launcher.waitingSources { launcher.Logs.GetChildLogger("icinga2"). - With(zap.Int64("source-id", src.ID)). + With(zap.Int64("source_id", src.ID)). Debug("Launching postponed Event Stream Client") launcher.launch(src) } @@ -66,7 +66,7 @@ func (launcher *Launcher) Ready() { // launch a new Icinga 2 Event Stream API Client based on the config.Source configuration. func (launcher *Launcher) launch(src *config.Source) { - logger := launcher.Logs.GetChildLogger("icinga2").With(zap.Int64("source-id", src.ID)) + logger := launcher.Logs.GetChildLogger("icinga2").With(zap.Int64("source_id", src.ID)) if src.Type != config.SourceTypeIcinga2 || !src.Icinga2BaseURL.Valid || diff --git a/internal/listener/listener.go b/internal/listener/listener.go index adebd2ef0..e28c55183 100644 --- a/internal/listener/listener.go +++ b/internal/listener/listener.go @@ -85,7 +85,7 @@ func (l *Listener) ProcessEvent(w http.ResponseWriter, req *http.Request) { msg = fmt.Sprintf(format, a...) } - logger := l.logger.With(zap.Int("status-code", statusCode), zap.String("msg", msg)) + logger := l.logger.With(zap.Int("status_code", statusCode), zap.String("msg", msg)) if ev != nil { logger = logger.With(zap.Stringer("event", ev)) }