Skip to content

Commit

Permalink
feat(api,ui): enable websocket for all (#5249)
Browse files Browse the repository at this point in the history
  • Loading branch information
sguiheux authored Jun 16, 2020
1 parent dbe51c2 commit 069cee4
Show file tree
Hide file tree
Showing 12 changed files with 8 additions and 1,328 deletions.
1 change: 0 additions & 1 deletion engine/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ type API struct {
SharedStorage objectstore.Driver
StartupTime time.Time
Maintenance bool
eventsBroker *eventsBroker
websocketBroker *websocketBroker
Cache cache.Store
Metrics struct {
Expand Down
11 changes: 0 additions & 11 deletions engine/api/api_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ func (api *API) InitRouter() {
r := api.Router

log.Info(api.Router.Background, "Initializing Events broker")
// Initialize event broker
api.eventsBroker = &eventsBroker{
router: api.Router,
cache: api.Cache,
clients: make(map[string]*eventsBrokerSubscribe),
dbFunc: api.DBConnectionFactory.GetDBMap,
messages: make(chan sdk.Event),
}
api.eventsBroker.Init(r.Background, api.PanicDump())

api.websocketBroker = &websocketBroker{
router: api.Router,
cache: api.Cache,
Expand Down Expand Up @@ -416,7 +406,6 @@ func (api *API) InitRouter() {
r.Handle("/workflow/hook/model/{model}", ScopeNone(), r.GET(api.getWorkflowHookModelHandler), r.POST(api.postWorkflowHookModelHandler, NeedAdmin(true)), r.PUT(api.putWorkflowHookModelHandler, NeedAdmin(true)))

// SSE
r.Handle("/events", ScopeNone(), r.GET(api.eventsBroker.ServeHTTP))
r.Handle("/ws", ScopeNone(), r.GET(api.websocketBroker.ServeHTTP))

// Feature
Expand Down
318 changes: 0 additions & 318 deletions engine/api/events.go

This file was deleted.

13 changes: 1 addition & 12 deletions engine/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ var (
onceMetrics sync.Once
Errors *stats.Int64Measure
Hits *stats.Int64Measure
SSEClients *stats.Int64Measure
SSEEvents *stats.Int64Measure
WebSocketClients *stats.Int64Measure
WebSocketEvents *stats.Int64Measure
ServerRequestCount *stats.Int64Measure
Expand Down Expand Up @@ -146,17 +144,8 @@ func (r *Router) recoverWrap(h http.HandlerFunc) http.HandlerFunc {
err = sdk.ErrUnknownError
}

// the SSE handler can panic, and it's the way gorilla/mux works :(
if strings.HasPrefix(req.URL.String(), "/events") {
msg := fmt.Sprintf("%v", err)
for _, s := range handledEventErrors {
if strings.Contains(msg, s) {
return
}
}
}
log.Error(context.TODO(), "[PANIC_RECOVERY] Panic occurred on %s:%s, recover %s", req.Method, req.URL.String(), err)

log.Error(req.Context(), "[PANIC_RECOVERY] Panic occurred on %s:%s", req.Method, req.URL.String())
trace := make([]byte, 4096)
count := runtime.Stack(trace, true)
log.Error(req.Context(), "[PANIC_RECOVERY] Stacktrace of %d bytes\n%s\n", count, trace)
Expand Down
Loading

0 comments on commit 069cee4

Please sign in to comment.