17244: Refactor crunchstat to use cgroup unified/hybrid modes.
[arvados.git] / cmd / arvados-server / cmd.go
index 27c53eb5cb6393623f4e596e610006448e4d786a..c02b8fb57cf90cc318604d0d24063751c7da90d1 100644 (file)
@@ -11,6 +11,9 @@ import (
        "io"
        "net/http"
        "os"
+       "path"
+       "path/filepath"
+       "strings"
 
        "git.arvados.org/arvados.git/lib/boot"
        "git.arvados.org/arvados.git/lib/cloud/cloudtest"
@@ -18,6 +21,7 @@ import (
        "git.arvados.org/arvados.git/lib/config"
        "git.arvados.org/arvados.git/lib/controller"
        "git.arvados.org/arvados.git/lib/crunchrun"
+       "git.arvados.org/arvados.git/lib/crunchstat"
        "git.arvados.org/arvados.git/lib/dispatchcloud"
        "git.arvados.org/arvados.git/lib/install"
        "git.arvados.org/arvados.git/lib/lsf"
@@ -25,6 +29,7 @@ import (
        "git.arvados.org/arvados.git/lib/service"
        "git.arvados.org/arvados.git/sdk/go/arvados"
        "git.arvados.org/arvados.git/sdk/go/health"
+       dispatchslurm "git.arvados.org/arvados.git/services/crunch-dispatch-slurm"
        "git.arvados.org/arvados.git/services/githttpd"
        keepbalance "git.arvados.org/arvados.git/services/keep-balance"
        keepweb "git.arvados.org/arvados.git/services/keep-web"
@@ -48,8 +53,10 @@ var (
                "config-dump":        config.DumpCommand,
                "controller":         controller.Command,
                "crunch-run":         crunchrun.Command,
+               "crunchstat":         crunchstat.Command,
                "dispatch-cloud":     dispatchcloud.Command,
                "dispatch-lsf":       lsf.DispatchCommand,
+               "dispatch-slurm":     dispatchslurm.Command,
                "git-httpd":          githttpd.Command,
                "health":             healthCommand,
                "install":            install.Command,
@@ -80,8 +87,21 @@ func (wb2command) RunCommand(prog string, args []string, stdin io.Reader, stdout
                fmt.Fprintf(stderr, "json.Marshal: %s\n", err)
                return 1
        }
+       servefs := http.FileServer(http.Dir(args[2]))
        mux := http.NewServeMux()
-       mux.Handle("/", http.FileServer(http.Dir(args[2])))
+       mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
+               for _, ent := range strings.Split(req.URL.Path, "/") {
+                       if ent == ".." {
+                               http.Error(w, "invalid URL path", http.StatusBadRequest)
+                               return
+                       }
+               }
+               fnm := filepath.Join(args[2], filepath.FromSlash(path.Clean("/"+req.URL.Path)))
+               if _, err := os.Stat(fnm); os.IsNotExist(err) {
+                       req.URL.Path = "/"
+               }
+               servefs.ServeHTTP(w, req)
+       }))
        mux.HandleFunc("/config.json", func(w http.ResponseWriter, _ *http.Request) {
                w.Write(configJSON)
        })
@@ -96,6 +116,16 @@ func (wb2command) RunCommand(prog string, args []string, stdin io.Reader, stdout
        return 0
 }
 
-var healthCommand cmd.Handler = service.Command(arvados.ServiceNameHealth, func(ctx context.Context, cluster *arvados.Cluster, _ string, _ *prometheus.Registry) service.Handler {
-       return &health.Aggregator{Cluster: cluster}
+var healthCommand cmd.Handler = service.Command(arvados.ServiceNameHealth, func(ctx context.Context, cluster *arvados.Cluster, _ string, reg *prometheus.Registry) service.Handler {
+       mClockSkew := prometheus.NewGauge(prometheus.GaugeOpts{
+               Namespace: "arvados",
+               Subsystem: "health",
+               Name:      "clock_skew_seconds",
+               Help:      "Clock skew observed in most recent health check",
+       })
+       reg.MustRegister(mClockSkew)
+       return &health.Aggregator{
+               Cluster:         cluster,
+               MetricClockSkew: mClockSkew,
+       }
 })