You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Knative Serving, specifically in the file pkg/queue/request_metric.go, within the function func (h *requestMetricsHandler) ServeHTTP(), how can I add a header to the response packet after h.next.ServeHTTP() is called? I attempted to add a header using the w parameter inside a deferred func(), but it didn't work.
func (h *requestMetricsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
rr := pkghttp.NewResponseRecorder(w, http.StatusOK)
startTime := time.Now()
defer func() {
// Filter probe requests for revision metrics.
if netheader.IsProbe(r) {
return
}
// If ServeHTTP panics, recover, record the failure and panic again.
err := recover()
latency := time.Since(startTime)
routeTag := GetRouteTagNameFromRequest(r)
if err != nil {
ctx := metrics.AugmentWithResponseAndRouteTag(h.statsCtx,
http.StatusInternalServerError, routeTag)
pkgmetrics.RecordBatch(ctx, requestCountM.M(1),
responseTimeInMsecM.M(float64(latency.Milliseconds())))
panic(err)
}
ctx := metrics.AugmentWithResponseAndRouteTag(h.statsCtx,
rr.ResponseCode, routeTag)
pkgmetrics.RecordBatch(ctx, requestCountM.M(1),
responseTimeInMsecM.M(float64(latency.Milliseconds())))
}()
h.next.ServeHTTP(rr, r)
}
Thanks so much for help.
The text was updated successfully, but these errors were encountered:
Hi everyone,
In Knative Serving, specifically in the file
pkg/queue/request_metric.go
, within the functionfunc (h *requestMetricsHandler) ServeHTTP()
, how can I add a header to the response packet afterh.next.ServeHTTP()
is called? I attempted to add a header using thew
parameter inside adeferred func()
, but it didn't work.Thanks so much for help.
The text was updated successfully, but these errors were encountered: