Add monitoring instrumentation for the remaining HTTP handlers in the apiserver.

This commit is contained in:
Alex Robinson
2015-02-10 23:19:49 +00:00
parent 535502ead6
commit ab62b689a5
3 changed files with 42 additions and 6 deletions

View File

@@ -23,6 +23,7 @@ import (
"net"
"net/http"
"strconv"
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/probe"
)
@@ -72,6 +73,10 @@ type ServerStatus struct {
}
func (v *validator) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var httpCode int
reqStart := time.Now()
defer func() { monitor("validate", "get", "", httpCode, reqStart) }()
reply := []ServerStatus{}
for name, server := range v.servers() {
status, msg, err := server.check(v.client)
@@ -85,11 +90,13 @@ func (v *validator) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
data, err := json.MarshalIndent(reply, "", " ")
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
httpCode = http.StatusInternalServerError
w.WriteHeader(httpCode)
w.Write([]byte(err.Error()))
return
}
w.WriteHeader(http.StatusOK)
httpCode = http.StatusOK
w.WriteHeader(httpCode)
w.Write(data)
}