fix: improve workbench kafka publish handling
This commit is contained in:
+13
-3
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user