[ARVADOS] created: 1af8267a0d11ad9f986aec5ec7853299f3cfeb0e
Git user
git at public.curoverse.com
Wed Jul 26 12:28:11 EDT 2017
at 1af8267a0d11ad9f986aec5ec7853299f3cfeb0e (commit)
commit 1af8267a0d11ad9f986aec5ec7853299f3cfeb0e
Author: radhika <radhika at curoverse.com>
Date: Wed Jul 26 12:26:56 2017 -0400
11906: add /_health/ping to keep-web
Arvados-DCO-1.1-Signed-off-by: Radhika Chippada <radhika at curoverse.com>
diff --git a/services/keep-web/handler.go b/services/keep-web/handler.go
index 769c2f5..5648449 100644
--- a/services/keep-web/handler.go
+++ b/services/keep-web/handler.go
@@ -21,6 +21,7 @@ import (
"git.curoverse.com/arvados.git/sdk/go/arvados"
"git.curoverse.com/arvados.git/sdk/go/arvadosclient"
"git.curoverse.com/arvados.git/sdk/go/auth"
+ "git.curoverse.com/arvados.git/sdk/go/health"
"git.curoverse.com/arvados.git/sdk/go/httpserver"
"git.curoverse.com/arvados.git/sdk/go/keepclient"
)
@@ -29,6 +30,7 @@ type handler struct {
Config *Config
clientPool *arvadosclient.ClientPool
setupOnce sync.Once
+ hmux *http.ServeMux
}
// parseCollectionIDFromDNSName returns a UUID or PDH if s begins with
@@ -70,7 +72,14 @@ func parseCollectionIDFromURL(s string) string {
func (h *handler) setup() {
h.clientPool = arvadosclient.MakeClientPool()
+
keepclient.RefreshServiceDiscoveryOnSIGHUP()
+
+ h.hmux = http.NewServeMux()
+ h.hmux.Handle("/_health/", &health.Handler{
+ Token: h.Config.ManagementToken,
+ Prefix: "/_health/",
+ })
}
func (h *handler) serveStatus(w http.ResponseWriter, r *http.Request) {
@@ -82,6 +91,10 @@ func (h *handler) serveStatus(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(status)
}
+func (h *handler) healthCheck(w http.ResponseWriter, r *http.Request) {
+ h.hmux.ServeHTTP(w, r)
+}
+
// ServeHTTP implements http.Handler.
func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
h.setupOnce.Do(h.setup)
@@ -110,6 +123,11 @@ func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
httpserver.Log(remoteAddr, statusCode, statusText, w.WroteBodyBytes(), r.Method, r.Host, r.URL.Path, r.URL.RawQuery)
}()
+ if strings.HasPrefix(r.URL.Path, "/_health/") && r.Method == "GET" {
+ h.healthCheck(w, r)
+ return
+ }
+
if r.Method == "OPTIONS" {
method := r.Header.Get("Access-Control-Request-Method")
if method != "GET" && method != "POST" {
diff --git a/services/keep-web/handler_test.go b/services/keep-web/handler_test.go
index 1d03b90..0485959 100644
--- a/services/keep-web/handler_test.go
+++ b/services/keep-web/handler_test.go
@@ -589,3 +589,24 @@ func (s *IntegrationSuite) TestDirectoryListing(c *check.C) {
}
}
}
+
+func (s *IntegrationSuite) TestHealthCheckPing(c *check.C) {
+ s.testServer.Config.ManagementToken = arvadostest.ManagementToken
+ authHeader := http.Header{
+ "Authorization": {"Bearer " + arvadostest.ManagementToken},
+ }
+
+ resp := httptest.NewRecorder()
+ u := mustParseURL("http://download.example.com/_health/ping")
+ req := &http.Request{
+ Method: "GET",
+ Host: u.Host,
+ URL: u,
+ RequestURI: u.RequestURI(),
+ Header: authHeader,
+ }
+ s.testServer.Handler.ServeHTTP(resp, req)
+
+ c.Check(resp.Code, check.Equals, http.StatusOK)
+ c.Check(resp.Body.String(), check.Matches, `{"health":"OK"}\n`)
+}
diff --git a/services/keep-web/main.go b/services/keep-web/main.go
index c4103f4..585dab1 100644
--- a/services/keep-web/main.go
+++ b/services/keep-web/main.go
@@ -34,6 +34,9 @@ type Config struct {
// Hack to support old command line flag, which is a bool
// meaning "get actual token from environment".
deprecatedAllowAnonymous bool
+
+ //Authorization token to be included in all health check requests.
+ ManagementToken string
}
// DefaultConfig returns the default configuration.
@@ -76,6 +79,9 @@ func main() {
"Only serve attachments at the given `host:port`"+deprecated)
flag.BoolVar(&cfg.TrustAllContent, "trust-all-content", false,
"Serve non-public content from a single origin. Dangerous: read docs before using!"+deprecated)
+ flag.StringVar(&cfg.ManagementToken, "management-token", "",
+ "Authorization token to be included in all health check requests.")
+
dumpConfig := flag.Bool("dump-config", false,
"write current configuration to stdout and exit")
flag.Usage = usage
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list