From 7b0ff73524653e738cbb3e7ad70587e6ae0b13df Mon Sep 17 00:00:00 2001 From: L4B0MB4 Date: Sun, 1 Dec 2024 20:40:29 +0100 Subject: [PATCH 1/6] Add debug logging for received authentication requests in WebSocket connection --- pkg/query/websocket/websocket_connection.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/query/websocket/websocket_connection.go b/pkg/query/websocket/websocket_connection.go index 3c10ace..0f34768 100644 --- a/pkg/query/websocket/websocket_connection.go +++ b/pkg/query/websocket/websocket_connection.go @@ -45,6 +45,7 @@ func (wC *WebsocketConnection) ReadForDisconnect() { wC.IsConnected = false break } else { + log.Debug().Interface("authReq", authRequest).Msg("Received auth request") _, err = auth.VerifyToken(authRequest.Token) if err != nil { log.Debug().Err(err).Msg("Error while verifying token") From 1924b66743841055e43a98e000ed2d30606545e8 Mon Sep 17 00:00:00 2001 From: L4B0MB4 Date: Sun, 1 Dec 2024 21:36:05 +0100 Subject: [PATCH 2/6] Add debug logging for event handling in PostEventHandler --- pkg/query/eventhandling/post.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/query/eventhandling/post.go b/pkg/query/eventhandling/post.go index e255d1b..88aadbc 100644 --- a/pkg/query/eventhandling/post.go +++ b/pkg/query/eventhandling/post.go @@ -41,17 +41,21 @@ func removeDisconnectedSockets(slice []*ws.WebsocketConnection) []*ws.WebsocketC } func (eh *PostEventHandler) HandleEvent(event models.Event) error { + log.Debug().Msg("Handling event") if event.AggregateType == "post" { + log.Debug().Msg("Handling post event") ua, err := aggregates.NewPostAggregate(uuid.MustParse(event.AggregateId)) if err != nil { return err } p := aggregates.GetPostModelFromAggregate(ua) + log.Debug().Msg("About to add Post to repository") err = eh.postRepo.AddOrReplacePost(p) if err != nil { log.Err(err).Msg("Error while processing user event") return err } + log.Debug().Msg("Post added to repository") for _, conn := range eh.wsConnections { if !conn.IsAuthenticated { continue From f28a19920638ff02c2fc84cd7a6cdf650352619b Mon Sep 17 00:00:00 2001 From: L4B0MB4 Date: Sun, 1 Dec 2024 21:42:45 +0100 Subject: [PATCH 3/6] Add debug logging for completion of new event reception in main --- cmd/queryer/main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/queryer/main.go b/cmd/queryer/main.go index e5bca0f..23232fa 100644 --- a/cmd/queryer/main.go +++ b/cmd/queryer/main.go @@ -59,6 +59,7 @@ func main() { log.Info().Msgf("Received event: %s", event) eventPolling.PollEventsUntilEmpty() } + log.Debug().Msg("New event received finished") } }() h.Start() From 094e6986ff3af5c4270979ba44fb98a925790a92 Mon Sep 17 00:00:00 2001 From: L4B0MB4 Date: Sun, 1 Dec 2024 21:46:55 +0100 Subject: [PATCH 4/6] Refactor event handling loop to simplify structure and improve readability --- cmd/queryer/main.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/cmd/queryer/main.go b/cmd/queryer/main.go index 23232fa..1b07857 100644 --- a/cmd/queryer/main.go +++ b/cmd/queryer/main.go @@ -53,12 +53,9 @@ func main() { eventPolling.PollEventsUntilEmpty() go func() { - for { - select { - case event := <-channel: - log.Info().Msgf("Received event: %s", event) - eventPolling.PollEventsUntilEmpty() - } + for event := range channel { + log.Info().Msgf("Received event: %s", event) + eventPolling.PollEventsUntilEmpty() log.Debug().Msg("New event received finished") } }() From bf10116f3e2e78f7dc756d07d092ffe32ec3fdbb Mon Sep 17 00:00:00 2001 From: L4B0MB4 Date: Sun, 1 Dec 2024 22:24:09 +0100 Subject: [PATCH 5/6] Update EVTSRC dependency to version v0.5.4 in go.mod and go.sum --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index f421eaf..8313942 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/PRYVT/posting go 1.23.1 require ( - github.com/L4B0MB4/EVTSRC v0.5.2 // indirect + github.com/L4B0MB4/EVTSRC v0.5.4 // indirect github.com/PRYVT/utils v0.3.0-rc // indirect github.com/bytedance/sonic v1.12.2 // indirect github.com/bytedance/sonic/loader v0.2.0 // indirect diff --git a/go.sum b/go.sum index d54126c..efacb0d 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ github.com/L4B0MB4/EVTSRC v0.5.1 h1:EB/lK0FTWtepToOtRFJdUhBf6tlb1L0bIRbRTMwArsQ= github.com/L4B0MB4/EVTSRC v0.5.1/go.mod h1:hpyNdNWqikZ6dcm8dhZAXgnAXZQNGAfXgRw902zjby0= github.com/L4B0MB4/EVTSRC v0.5.2 h1:bAOYlUmcZ2bg8rWIKnHLnxZPgXrPYyrQbtlz49BKlp4= github.com/L4B0MB4/EVTSRC v0.5.2/go.mod h1:hpyNdNWqikZ6dcm8dhZAXgnAXZQNGAfXgRw902zjby0= +github.com/L4B0MB4/EVTSRC v0.5.4 h1:bTg1PS78YzWb+dt3JJRFFVNMubIAiKJlO3Ivdy7jagc= +github.com/L4B0MB4/EVTSRC v0.5.4/go.mod h1:hpyNdNWqikZ6dcm8dhZAXgnAXZQNGAfXgRw902zjby0= github.com/PRYVT/utils v0.1.2 h1:U9qhq+18iIblQDrM4I0fmJkvlZ+BCY+DIjjKI4ebtlk= github.com/PRYVT/utils v0.1.2/go.mod h1:b7zk2FAGwJ8BPJx2JQ8qd+bA59g5EY7Y1vZQPWZHK3s= github.com/PRYVT/utils v0.2.0 h1:hWdHchXlGOYlJ1nfMmGffq/EjFn3ncvzTgsGCLUpiEE= From cb3db95b12a043e9c7d81a31e9ea864d77b10459 Mon Sep 17 00:00:00 2001 From: L4B0MB4 Date: Mon, 2 Dec 2024 19:12:05 +0100 Subject: [PATCH 6/6] Remove redundant debug logs and add trace logging for active WebSocket connections --- pkg/query/eventhandling/post.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkg/query/eventhandling/post.go b/pkg/query/eventhandling/post.go index 88aadbc..4485767 100644 --- a/pkg/query/eventhandling/post.go +++ b/pkg/query/eventhandling/post.go @@ -49,13 +49,11 @@ func (eh *PostEventHandler) HandleEvent(event models.Event) error { return err } p := aggregates.GetPostModelFromAggregate(ua) - log.Debug().Msg("About to add Post to repository") err = eh.postRepo.AddOrReplacePost(p) if err != nil { log.Err(err).Msg("Error while processing user event") return err } - log.Debug().Msg("Post added to repository") for _, conn := range eh.wsConnections { if !conn.IsAuthenticated { continue @@ -68,7 +66,7 @@ func (eh *PostEventHandler) HandleEvent(event models.Event) error { eh.mu.Lock() defer eh.mu.Unlock() eh.wsConnections = removeDisconnectedSockets(eh.wsConnections) - + log.Trace().Msgf("Number of active connections: %d", len(eh.wsConnections)) } return nil }