10666: Replaced 'version' package with 'version' var
[arvados.git] / services / health / main.go
index 3e089fa5a229966dd79f410bbc3e56605f26b4bd..4b553659ed4c467b9f87c7713237789e6fb3046c 100644 (file)
@@ -1,7 +1,10 @@
 package main
 
 import (
+       "flag"
+       "fmt"
        "net/http"
+       "os"
 
        "git.curoverse.com/arvados.git/sdk/go/arvados"
        "git.curoverse.com/arvados.git/sdk/go/health"
@@ -9,11 +12,25 @@ import (
        log "github.com/Sirupsen/logrus"
 )
 
+var version = "dev"
+
 func main() {
+       configFile := flag.String("config", arvados.DefaultConfigFile, "`path` to arvados configuration file")
+       getVersion := flag.Bool("version", false, "Print version information and exit.")
+       flag.Parse()
+
+       // Print version information if requested
+       if *getVersion {
+               fmt.Printf("Version: %s\n", version)
+               os.Exit(0)
+       }
+
        log.SetFormatter(&log.JSONFormatter{
                TimestampFormat: "2006-01-02T15:04:05.000000000Z07:00",
        })
-       cfg, err := arvados.GetConfig()
+       log.Printf("arvados health %q started", version)
+
+       cfg, err := arvados.GetConfig(*configFile)
        if err != nil {
                log.Fatal(err)
        }
@@ -26,11 +43,18 @@ func main() {
                log.Fatal(err)
        }
 
+       log := log.WithField("Service", "Health")
        srv := &httpserver.Server{
                Addr: nodeCfg.Health.Listen,
                Server: http.Server{
                        Handler: &health.Aggregator{
                                Config: cfg,
+                               Log: func(req *http.Request, err error) {
+                                       log.WithField("RemoteAddr", req.RemoteAddr).
+                                               WithField("Path", req.URL.Path).
+                                               WithError(err).
+                                               Info("HTTP request")
+                               },
                        },
                },
        }