issue #14891 upload rcs to testing repo
[arvados.git] / services / health / main.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package main
6
7 import (
8         "flag"
9         "fmt"
10         "net/http"
11
12         "git.curoverse.com/arvados.git/sdk/go/arvados"
13         "git.curoverse.com/arvados.git/sdk/go/health"
14         "git.curoverse.com/arvados.git/sdk/go/httpserver"
15         log "github.com/sirupsen/logrus"
16 )
17
18 var version = "dev"
19
20 func main() {
21         configFile := flag.String("config", arvados.DefaultConfigFile, "`path` to arvados configuration file")
22         getVersion := flag.Bool("version", false, "Print version information and exit.")
23         flag.Parse()
24
25         // Print version information if requested
26         if *getVersion {
27                 fmt.Printf("arvados-health %s\n", version)
28                 return
29         }
30
31         log.SetFormatter(&log.JSONFormatter{
32                 TimestampFormat: "2006-01-02T15:04:05.000000000Z07:00",
33         })
34         log.Printf("arvados-health %s started", version)
35
36         cfg, err := arvados.GetConfig(*configFile)
37         if err != nil {
38                 log.Fatal(err)
39         }
40         clusterCfg, err := cfg.GetCluster("")
41         if err != nil {
42                 log.Fatal(err)
43         }
44         nodeCfg, err := clusterCfg.GetNodeProfile("")
45         if err != nil {
46                 log.Fatal(err)
47         }
48
49         log := log.WithField("Service", "Health")
50         srv := &httpserver.Server{
51                 Addr: nodeCfg.Health.Listen,
52                 Server: http.Server{
53                         Handler: &health.Aggregator{
54                                 Config: cfg,
55                                 Log: func(req *http.Request, err error) {
56                                         log.WithField("RemoteAddr", req.RemoteAddr).
57                                                 WithField("Path", req.URL.Path).
58                                                 WithError(err).
59                                                 Info("HTTP request")
60                                 },
61                         },
62                 },
63         }
64         if err := srv.Start(); err != nil {
65                 log.Fatal(err)
66         }
67         log.WithField("Listen", srv.Addr).Info("listening")
68         if err := srv.Wait(); err != nil {
69                 log.Fatal(err)
70         }
71 }