From edb9a6b2bbd6acbf0f61ece0bacefd6709cb09e5 Mon Sep 17 00:00:00 2001 From: richjohnrambo Date: Tue, 15 Sep 2026 09:46:26 +0800 Subject: [PATCH] fix: improve workbench kafka publish handling --- internal/httpapi/api.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/internal/httpapi/api.go b/internal/httpapi/api.go index 95262d0..cc9d740 100644 --- a/internal/httpapi/api.go +++ b/internal/httpapi/api.go @@ -6,6 +6,7 @@ import ( "encoding/base64" "encoding/json" "fmt" + "log" "net/http" "strconv" "strings" @@ -22,6 +23,8 @@ type API struct { events events.Publisher } +const workbenchEventPublishTimeout = 15 * time.Second + func New(st *store.Store, authenticator *auth.Authenticator, publisher events.Publisher) *API { if publisher == nil { publisher = events.NoopPublisher{} @@ -863,11 +866,18 @@ func (a *API) publishWorkbenchEvent(w http.ResponseWriter, r *http.Request, p *a if a.events == nil { return true } - ctx, cancel := context.WithTimeout(r.Context(), 5*time.Second) - defer cancel() event := events.NewWorkbenchEvent(p, requestID(r), module, action, resourceID, targets, title, summary, data) + start := time.Now() + ctx, cancel := context.WithTimeout(r.Context(), workbenchEventPublishTimeout) + defer cancel() if err := a.events.Publish(ctx, event); err != nil { - writeError(w, r, http.StatusInternalServerError, 90000, reasonInternal, "workbench event publish failed", map[string]any{"event": action}) + log.Printf("workbench event publish failed: event_id=%s module=%s action=%s resource_id=%s trace_id=%s elapsed=%s err=%v", + event.EventID, module, action, resourceID, event.TraceID, time.Since(start).Round(time.Millisecond), err) + writeError(w, r, http.StatusInternalServerError, 90000, reasonInternal, "workbench event publish failed", map[string]any{ + "event_id": event.EventID, + "module": module, + "event": action, + }) return false } return true