From 9bfb53a7f6c1dea17e2e6f15c021038711ed3b41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 1 Mar 2024 22:19:47 +0100 Subject: [PATCH] Manager: log error when an event doesn't have a SocketIO event type SocketIO has 'rooms' and 'event types'. The 'event type' is set via reflection of the OpenAPI type of the event payload. This has to be set up in a mapping, though, and if that mapping is incomplete, an error will now be logged. --- internal/manager/eventbus/socketio.go | 13 ++++++++++++- internal/manager/eventbus/topics.go | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/internal/manager/eventbus/socketio.go b/internal/manager/eventbus/socketio.go index d86c97a4..1ff4e190 100644 --- a/internal/manager/eventbus/socketio.go +++ b/internal/manager/eventbus/socketio.go @@ -14,6 +14,7 @@ import ( "github.com/rs/zerolog/log" "projects.blender.org/studio/flamenco/internal/uuid" "projects.blender.org/studio/flamenco/pkg/api" + "projects.blender.org/studio/flamenco/pkg/website" ) type SocketIOEventType string @@ -59,7 +60,17 @@ func (s *SocketIOForwarder) Broadcast(topic EventTopic, payload interface{}) { // SocketIO has a concept of 'event types'. MQTT doesn't have this, and thus the Flamenco event // system doesn't rely on it. We use the payload type name as event type. payloadType := reflect.TypeOf(payload).Name() - eventType := socketIOEventTypes[payloadType] + + eventType, ok := socketIOEventTypes[payloadType] + if !ok { + log.Error(). + Str("topic", string(topic)). + Str("payloadType", payloadType). + Interface("event", payload). + Msgf("socketIO: payload type does not have an event type, please copy-paste this message into a bug report at %s", website.BugReportURL) + return + } + log.Debug(). Str("topic", string(topic)). Str("eventType", eventType). diff --git a/internal/manager/eventbus/topics.go b/internal/manager/eventbus/topics.go index 1e0678f8..4f00407d 100644 --- a/internal/manager/eventbus/topics.go +++ b/internal/manager/eventbus/topics.go @@ -6,6 +6,7 @@ import "fmt" const ( // Topics on which events are published. + // NOTE: when adding here, also add to socketIOEventTypes in socketio.go. TopicLifeCycle EventTopic = "/lifecycle" // sends api.EventLifeCycle TopicFarmStatus EventTopic = "/status" // sends api.EventFarmStatus TopicJobUpdate EventTopic = "/jobs" // sends api.EventJobUpdate