Skip to content

Commit

Permalink
Streamline log messages in icinga2 package
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Apr 16, 2024
1 parent 6941afd commit f4058f2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
25 changes: 12 additions & 13 deletions internal/icinga2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (client *Client) startCatchupWorkers(delay time.Duration) (chan *catchupEve
startTime := time.Now()
catchupEventCh := make(chan *catchupEventMsg)

client.Logger.Debugw("Catch-up-phase worker has started",
client.Logger.Debugw("Starting catch-up-phase worker",
zap.Stringer("worker", workerId),
zap.Duration("delay", delay))

Expand All @@ -228,7 +228,7 @@ func (client *Client) startCatchupWorkers(delay time.Duration) (chan *catchupEve

err := client.checkMissedChanges(groupCtx, objType, catchupEventCh)
if err != nil && !errors.Is(err, context.Canceled) {
client.Logger.Debugw("Catch-up-phase event worker failed",
client.Logger.Debugw("Failed to processes catch-up-phase event streams",
zap.Stringer("worker", workerId),
zap.String("object_type", objType),
zap.Error(err))
Expand All @@ -240,21 +240,21 @@ func (client *Client) startCatchupWorkers(delay time.Duration) (chan *catchupEve
go func() {
err := group.Wait()
if err == nil {
client.Logger.Debugw("Catching up the API has finished",
client.Logger.Debugw("Finished catching up the API event streams",
zap.Stringer("worker", workerId),
zap.Duration("duration", time.Since(startTime)))
} else if errors.Is(err, context.Canceled) {
// The context is either canceled when the Client got canceled or, more likely, when another catch-up-worker
// was requested. In the first case, the already sent messages will be discarded as the worker's main loop
// was left. In the other case, the message buffers will be reset to an empty state.
client.Logger.Debugw("Catching up the API was interrupted",
client.Logger.Debugw("Interrupted catching up the API event streams",
zap.Stringer("worker", workerId),
zap.Duration("duration", time.Since(startTime)))
} else {
client.Logger.Debugw("Catching up the API failed",
client.Logger.Debugw("Failed to catchup up the API event streams",
zap.Stringer("worker", workerId),
zap.Error(err),
zap.Duration("duration", time.Since(startTime)))
zap.Duration("duration", time.Since(startTime)),
zap.Error(err))

select {
case <-ctx.Done():
Expand Down Expand Up @@ -311,7 +311,7 @@ func (client *Client) worker() {
// catchupWorkerStart starts a catch-up-phase worker and stops already running workers, if necessary.
catchupWorkerStart := func() {
if catchupEventCh != nil {
client.Logger.Debug("Switching to catch-up-phase was requested while still catching up, stopping old worker")
client.Logger.Debug("Received request to switch to catch-up-phase while still catching up, stopping old worker")
catchupCancel()
}

Expand Down Expand Up @@ -345,9 +345,8 @@ func (client *Client) worker() {
catchupWorkerDelay = min(3*time.Minute, 2*catchupWorkerDelay)
}

client.Logger.Warnw("Catch-up-phase was interrupted by an error, another attempt will be made",
zap.Error(catchupMsg.error),
zap.Duration("delay", catchupWorkerDelay))
client.Logger.Warnw("Interrupted catch-up-phase due to an error, another attempt will be made",
zap.Duration("delay", catchupWorkerDelay), zap.Error(catchupMsg.error))

catchupWorkerStart()
break
Expand Down Expand Up @@ -403,9 +402,9 @@ func (client *Client) Process() {
for client.Ctx.Err() == nil {
err := client.listenEventStream()
if err != nil {
client.Logger.Errorw("Event Stream processing was interrupted", zap.Error(err))
client.Logger.Errorw("Interrupted event stream processing", zap.Error(err))
} else {
client.Logger.Errorw("Event Stream processing was closed")
client.Logger.Errorw("Closed event stream processing unexpectedly")
}
}
}
7 changes: 3 additions & 4 deletions internal/icinga2/client_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,12 @@ func (client *Client) connectEventStream(esTypes []string) (io.ReadCloser, error
go func() {
defer close(resCh)

client.Logger.Debug("Try to establish an Event Stream API connection")
client.Logger.Debug("Trying to establish an Event Stream API connection")
httpClient := &http.Client{Transport: client.ApiHttpTransport}
res, err := httpClient.Do(req)
if err != nil {
client.Logger.Warnw("Establishing an Event Stream API connection failed, will be retried",
zap.Error(err),
zap.Duration("delay", retryDelay))
client.Logger.Warnw("Failed to establish an Event Stream API connection, retrying",
zap.Duration("delay", retryDelay), zap.Error(err))
return
}

Expand Down

0 comments on commit f4058f2

Please sign in to comment.