11906: add /_health/ping to arv-git-httpd
authorradhika <radhika@curoverse.com>
Wed, 26 Jul 2017 20:30:14 +0000 (16:30 -0400)
committerradhika <radhika@curoverse.com>
Wed, 26 Jul 2017 20:30:14 +0000 (16:30 -0400)
Arvados-DCO-1.1-Signed-off-by: Radhika Chippada <radhika@curoverse.com>

services/arv-git-httpd/integration_test.go
services/arv-git-httpd/main.go
services/arv-git-httpd/server.go
services/arv-git-httpd/server_test.go

index 6a2b6401b5e0b293664e4ff0803c9ea285b331ad..10c69eedd3bf2e2c81cb51ea7c92961d108f1204 100644 (file)
@@ -77,9 +77,10 @@ func (s *IntegrationSuite) SetUpTest(c *check.C) {
                                APIHost:  arvadostest.APIHost(),
                                Insecure: true,
                        },
-                       Listen:     ":0",
-                       GitCommand: "/usr/bin/git",
-                       RepoRoot:   s.tmpRepoRoot,
+                       Listen:          ":0",
+                       GitCommand:      "/usr/bin/git",
+                       RepoRoot:        s.tmpRepoRoot,
+                       ManagementToken: arvadostest.ManagementToken,
                }
        }
 
index bee02693ae62745be83a0ac80a3430cfb3cf804e..79a3eb3f7b85de9667c04fe1b24f2a5217db5772 100644 (file)
@@ -18,11 +18,12 @@ import (
 
 // Server configuration
 type Config struct {
-       Client       arvados.Client
-       Listen       string
-       GitCommand   string
-       RepoRoot     string
-       GitoliteHome string
+       Client          arvados.Client
+       Listen          string
+       GitCommand      string
+       RepoRoot        string
+       GitoliteHome    string
+       ManagementToken string
 }
 
 var theConfig = defaultConfig()
@@ -49,6 +50,10 @@ func main() {
 
        cfgPath := flag.String("config", defaultCfgPath, "Configuration file `path`.")
        dumpConfig := flag.Bool("dump-config", false, "write current configuration to stdout and exit (useful for migrating from command line flags to config file)")
+
+       flag.StringVar(&theConfig.ManagementToken, "management-token", theConfig.ManagementToken,
+               "Authorization token to be included in all health check requests.")
+
        flag.Usage = usage
        flag.Parse()
 
index 8a7819a2a6133099d99f6058f01d94e36edb6018..8f0d90f89e29cad0a0d8d590b66e412b02195ad2 100644 (file)
@@ -7,6 +7,7 @@ package main
 import (
        "net/http"
 
+       "git.curoverse.com/arvados.git/sdk/go/health"
        "git.curoverse.com/arvados.git/sdk/go/httpserver"
 )
 
@@ -17,6 +18,10 @@ type server struct {
 func (srv *server) Start() error {
        mux := http.NewServeMux()
        mux.Handle("/", &authHandler{handler: newGitHandler()})
+       mux.Handle("/_health/", &health.Handler{
+               Token:  theConfig.ManagementToken,
+               Prefix: "/_health/",
+       })
        srv.Handler = mux
        srv.Addr = theConfig.Listen
        return srv.Server.Start()
index 45336010a1397b06954e09b52fb66a312dd76fdd..b4fc532e8f1a2000e070c86131b60ae143a0edf7 100644 (file)
@@ -5,9 +5,13 @@
 package main
 
 import (
+       "net/http"
+       "net/http/httptest"
        "os"
        "os/exec"
 
+       "git.curoverse.com/arvados.git/sdk/go/arvadostest"
+
        check "gopkg.in/check.v1"
 )
 
@@ -104,3 +108,16 @@ func (s *GitSuite) makeArvadosRepo(c *check.C) {
        c.Log(string(msg))
        c.Assert(err, check.Equals, nil)
 }
+
+func (s *GitSuite) TestHealthCheckPing(c *check.C) {
+       req, err := http.NewRequest("GET",
+               "http://"+s.testServer.Addr+"/_health/ping",
+               nil)
+       c.Assert(err, check.Equals, nil)
+       req.Header.Set("Authorization", "Bearer "+arvadostest.ManagementToken)
+
+       resp := httptest.NewRecorder()
+       s.testServer.Handler.ServeHTTP(resp, req)
+       c.Check(resp.Code, check.Equals, 200)
+       c.Check(resp.Body.String(), check.Matches, `{"health":"OK"}\n`)
+}