Skip to content

Commit

Permalink
Add specific traffic metric entry for event streaming (#501)
Browse files Browse the repository at this point in the history
Add traffic metric for event streaming
  • Loading branch information
DnlLrssn authored Sep 12, 2024
1 parent ab309cc commit f302501
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions session/resthandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ func (handler *RestHandler) QueueRequestWithCallback(actionState *action.State,
failRequest(errors.WithStack(err))
return
}
doTs := time.Now()
request.response, errRequest = handler.Client.Do(req)
if errRequest != nil {
WarnOrError(actionState, logEntry, failOnError, errors.Wrap(errRequest, "HTTP request fail"))
Expand All @@ -648,6 +649,10 @@ func (handler *RestHandler) QueueRequestWithCallback(actionState *action.State,
request.ResponseStatusCode = request.response.StatusCode
request.ResponseHeaders = request.response.Header
request.ResponseBody, errRequest = io.ReadAll(request.response.Body)
// When content type is a stream normal metric log will be time to response without starting to stream the body. Thus this will log response time to stream end
if logEntry.ShouldLogTrafficMetrics() && strings.HasPrefix(request.response.Header.Get("Content-Type"), "text/event-stream") {
logEntry.LogTrafficMetric(time.Since(doTs).Nanoseconds(), 0, uint64(len(request.ResponseBody)), -1, req.URL.Path, "", "STREAM", "")
}
}
}()
}
Expand Down

0 comments on commit f302501

Please sign in to comment.