Skip to content

Commit

Permalink
Merge pull request kubernetes#5147 from a-robinson/func
Browse files Browse the repository at this point in the history
Re-add the defer statements around the monitor() calls in the apiserver.
  • Loading branch information
lavalamp committed Mar 6, 2015
2 parents a858c74 + 60f0e9d commit 05ea93f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
9 changes: 5 additions & 4 deletions pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,18 @@ func init() {

// monitor is a helper function for each HTTP request handler to use for
// instrumenting basic request counter and latency metrics.
func monitor(handler, verb, resource string, httpCode int, reqStart time.Time) {
requestCounter.WithLabelValues(handler, verb, resource, strconv.Itoa(httpCode)).Inc()
requestLatencies.WithLabelValues(handler, verb).Observe(float64((time.Since(reqStart)) / time.Microsecond))
func monitor(handler string, verb, resource *string, httpCode *int, reqStart time.Time) {
requestCounter.WithLabelValues(handler, *verb, *resource, strconv.Itoa(*httpCode)).Inc()
requestLatencies.WithLabelValues(handler, *verb).Observe(float64((time.Since(reqStart)) / time.Microsecond))
}

// monitorFilter creates a filter that reports the metrics for a given resource and action.
func monitorFilter(action, resource string) restful.FilterFunction {
return func(req *restful.Request, res *restful.Response, chain *restful.FilterChain) {
reqStart := time.Now()
chain.ProcessFilter(req, res)
monitor("rest", action, resource, res.StatusCode(), reqStart)
httpCode := res.StatusCode()
monitor("rest", &action, &resource, &httpCode, reqStart)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/apiserver/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (r *ProxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
var apiResource string
var httpCode int
reqStart := time.Now()
defer monitor("proxy", verb, apiResource, httpCode, reqStart)
defer monitor("proxy", &verb, &apiResource, &httpCode, reqStart)

requestInfo, err := r.apiRequestInfoResolver.GetAPIRequestInfo(req)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/apiserver/redirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (r *RedirectHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
var apiResource string
var httpCode int
reqStart := time.Now()
defer monitor("redirect", verb, apiResource, httpCode, reqStart)
defer monitor("redirect", &verb, &apiResource, &httpCode, reqStart)

requestInfo, err := r.apiRequestInfoResolver.GetAPIRequestInfo(req)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion pkg/apiserver/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ type ServerStatus struct {
}

func (v *validator) ServeHTTP(w http.ResponseWriter, r *http.Request) {
verb := "get"
apiResource := ""
var httpCode int
reqStart := time.Now()
defer monitor("validate", "get", "", httpCode, reqStart)
defer monitor("validate", &verb, &apiResource, &httpCode, reqStart)

reply := []ServerStatus{}
for name, server := range v.servers() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/apiserver/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (h *WatchHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
var apiResource string
var httpCode int
reqStart := time.Now()
defer monitor("watch", verb, apiResource, httpCode, reqStart)
defer monitor("watch", &verb, &apiResource, &httpCode, reqStart)

if req.Method != "GET" {
notFound(w, req)
Expand Down

0 comments on commit 05ea93f

Please sign in to comment.