-
Kubernetes Submit Queue authored
Merge pull request #37477 from bruceauyeung/k8s-branch-fix-metrics-monitor-always-get-zero-value-http-code-in-ServeHTTP Automatic merge from submit-queue fix incorrect parameter pass to metrics.Monitor method call in ServeHTTP **What this PR does / why we need it**: before this PR: 1. `httpCode` is evaluated when defer statement executes, so all later assignments to `httpCode` is actually ineffectual. this obviously is not the design purpose. 2. `w.Header().Get("Content-Type")` is evaluated when defer statement executes, so all later `w.Header().Set("Content-Type",xxx)` ( in `writeNegotiated` ) is ineffectual to `metrics.Monitor`, i think this also is not the design purpose. after this PR: 1. `httpCode` and `w.Header().Get("Content-Type")` is evaluated when the defered anonymous function executes, so `metrics.Monitor` will get correct `httpCode` and `Content-Type` field value. 2. in `ServeHTTP` method there is not any modification to `req` parameter, so it's safe to defer its evaluation. Signed-off-by:bruceauyeung <ouyang.qinhua@zte.com.cn>
2bd077df