From 6d2375b396a3f94208451a945b4c5c34ba9ecd20 Mon Sep 17 00:00:00 2001 From: Piper Pentagram Date: Fri, 8 Nov 2024 14:53:12 -0800 Subject: [PATCH] Fill out logging TODOs in state package This change adds logging where requested via TODOs in state.go. --- internal/state/state.go | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/internal/state/state.go b/internal/state/state.go index df80bbb..d2e93dd 100644 --- a/internal/state/state.go +++ b/internal/state/state.go @@ -8,11 +8,13 @@ package state */ import ( + "fmt" "slices" "sync" "time" "github.com/bwmarrin/discordgo" + "gitlab.com/whom/bingobot/internal/logging" ) /* Event interface is meant to encapsulate a general interface @@ -165,14 +167,29 @@ func PublishEvent(e Event) error { eventMutex.Unlock() eventMutex.RLock() defer eventMutex.RUnlock() + + blocking := false + for _, c := range eventSubscriptionCache[e.Type()] { if float32(len(c)) > (float32(eventChannelBufferSize) * 0.25) { if len(c) == eventChannelBufferSize { - // TODO: log that this publish is blocking - // on a full channel + logging.Warn( + "PublishEvent() blocking -- event channel full", + // log the event time to provide blockage timing information + // in the logs + "eventTime", + e.Time(), + ) + blocking = true } } c <- e + + if blocking { + logging.Info("PublishEvent() no longer blocking") + blocking = false + } + } return nil @@ -259,9 +276,13 @@ func (ve VoteEvent) Time() time.Time { t, e := time.Parse(time.RFC3339, ve[VoteCreatedKey]) if e != nil { // we have a corrupted event - // TODO: log first // return old time so that this event gets // pruned from cache + logging.Warn( + "pruning corrupted vote event", + "event", + fmt.Sprintf("%+v", ve), + ) tooOld, _ := time.Parse( time.RFC3339, VeryOldVote, @@ -343,9 +364,14 @@ func (ue UserEvent) Validate() error { _, err := DiscordSession.User(ue.uid) return err } else { - // TODO: Log validation failure // I would love to know how to actually fail here // and still have unit testable code. + + logging.Error( + "can't validate UserEvent: nil discord session", + "event", + fmt.Sprintf("%+v", ue), + ) return nil } }