X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/e65fffb60a5697ce1991ceb01a15001eb7adb101..1f9e34a95ed8eefdab52b105a38582eb1533e47a:/services/keepstore/handlers.go?ds=sidebyside diff --git a/services/keepstore/handlers.go b/services/keepstore/handlers.go index 101f42c20c..2d90aba14e 100644 --- a/services/keepstore/handlers.go +++ b/services/keepstore/handlers.go @@ -29,6 +29,7 @@ import ( "github.com/gorilla/mux" + "git.curoverse.com/arvados.git/sdk/go/health" "git.curoverse.com/arvados.git/sdk/go/httpserver" log "github.com/Sirupsen/logrus" ) @@ -78,8 +79,10 @@ func MakeRESTRouter() *router { // Untrash moves blocks from trash back into store rest.HandleFunc(`/untrash/{hash:[0-9a-f]{32}}`, UntrashHandler).Methods("PUT") - // Health check ping - rest.HandleFunc(`/_health/ping`, HealthCheckPingHandler).Methods("GET") + rest.Handle("/_health/{check}", &health.Handler{ + Token: theConfig.ManagementToken, + Prefix: "/_health/", + }).Methods("GET") // Any request which does not match any of these routes gets // 400 Bad Request. @@ -288,7 +291,7 @@ func (rtr *router) MountsHandler(resp http.ResponseWriter, req *http.Request) { // PoolStatus struct type PoolStatus struct { - Alloc uint64 `json:"BytesAllocated"` + Alloc uint64 `json:"BytesAllocatedCumulative"` Cap int `json:"BuffersMax"` Len int `json:"BuffersInUse"` } @@ -620,45 +623,6 @@ func UntrashHandler(resp http.ResponseWriter, req *http.Request) { } } -// HealthCheckPingHandler processes "GET /_health/ping" requests -func HealthCheckPingHandler(resp http.ResponseWriter, req *http.Request) { - fn := func() interface{} { - return map[string]string{"health": "OK"} - } - - healthCheckDo(resp, req, fn) -} - -// Any health check handlers can pass this "func" which returns json to healthCheckDo -type healthCheckFunc func() interface{} - -func healthCheckDo(resp http.ResponseWriter, req *http.Request, fn healthCheckFunc) { - msg, code := healthCheckAuth(resp, req) - if msg != "" { - http.Error(resp, msg, code) - return - } - - ok, err := json.Marshal(fn()) - if err != nil { - http.Error(resp, err.Error(), 500) - return - } - - resp.Write(ok) -} - -func healthCheckAuth(resp http.ResponseWriter, req *http.Request) (string, int) { - if theConfig.ManagementToken == "" { - return "disabled", http.StatusNotFound - } else if h := req.Header.Get("Authorization"); h == "" { - return "authorization required", http.StatusUnauthorized - } else if h != "Bearer "+theConfig.ManagementToken { - return "authorization error", http.StatusForbidden - } - return "", 0 -} - // GetBlock and PutBlock implement lower-level code for handling // blocks by rooting through volumes connected to the local machine. // Once the handler has determined that system policy permits the