pbacsko commented on code in PR #533:
URL: https://github.com/apache/yunikorn-core/pull/533#discussion_r1409166784


##########
pkg/webservice/handlers.go:
##########
@@ -918,3 +918,61 @@ func getEvents(w http.ResponseWriter, r *http.Request) {
                buildJSONErrorResponse(w, err.Error(), 
http.StatusInternalServerError)
        }
 }
+
+func getStream(w http.ResponseWriter, r *http.Request) {
+       writeHeaders(w)
+       eventSystem := events.GetEventSystem()
+       if !eventSystem.IsEventTrackingEnabled() {
+               buildJSONErrorResponse(w, "Event tracking is disabled", 
http.StatusInternalServerError)
+               return
+       }
+
+       f, ok := w.(http.Flusher)
+       if !ok {
+               buildJSONErrorResponse(w, "Writer does not implement 
http.Flusher", http.StatusInternalServerError)
+               return
+       }
+
+       var count uint64
+       if countStr := r.URL.Query().Get("count"); countStr != "" {
+               var err error
+               count, err = strconv.ParseUint(countStr, 10, 64)
+               if err != nil {
+                       buildJSONErrorResponse(w, err.Error(), 
http.StatusBadRequest)
+                       return
+               }
+       }
+
+       enc := json.NewEncoder(w)
+       stream := eventSystem.CreateEventStream(r.Host, count)
+
+       // Reading events in an infinite loop until either the client 
disconnects or Yunikorn closes the channel.
+       // This results in a persistent HTTP connection where the message body 
is never closed.
+       // We don't use timeouts and since HTTP 1.1 clients are expected to 
handle persistent connections by default.

Review Comment:
   Change added. New code uses ResponseController.setWriteDeadline() before 
each send.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to