Merge branch '15654-wb-gem-update' refs #15654
[arvados.git] / services / keep-balance / server.go
index c867d7b10de240d7a584c258c9cc19aa0dfe3922..e2f13a425ed8dfabc729649d98aa7e4ed977899a 100644 (file)
@@ -5,6 +5,7 @@
 package main
 
 import (
+       "context"
        "fmt"
        "net/http"
        "os"
@@ -14,6 +15,7 @@ import (
 
        "git.curoverse.com/arvados.git/sdk/go/arvados"
        "git.curoverse.com/arvados.git/sdk/go/auth"
+       "git.curoverse.com/arvados.git/sdk/go/ctxlog"
        "git.curoverse.com/arvados.git/sdk/go/httpserver"
        "github.com/sirupsen/logrus"
 )
@@ -57,6 +59,10 @@ type Config struct {
 
        // Timeout for outgoing http request/response cycle.
        RequestTimeout arvados.Duration
+
+       // Destination filename for the list of lost block hashes, one
+       // per line. Updated atomically during each successful run.
+       LostBlocksFile string
 }
 
 // RunOptions controls runtime behavior. The flags/options that belong
@@ -123,11 +129,13 @@ func (srv *Server) start() error {
        if srv.config.Listen == "" {
                return nil
        }
+       ctx := ctxlog.Context(context.Background(), srv.Logger)
        server := &httpserver.Server{
                Server: http.Server{
-                       Handler: httpserver.LogRequests(srv.Logger,
-                               auth.RequireLiteralToken(srv.config.ManagementToken,
-                                       srv.metrics.Handler(srv.Logger))),
+                       Handler: httpserver.HandlerWithContext(ctx,
+                               httpserver.LogRequests(
+                                       auth.RequireLiteralToken(srv.config.ManagementToken,
+                                               srv.metrics.Handler(srv.Logger)))),
                },
                Addr: srv.config.Listen,
        }
@@ -142,9 +150,10 @@ func (srv *Server) start() error {
 
 func (srv *Server) Run() (*Balancer, error) {
        bal := &Balancer{
-               Logger:  srv.Logger,
-               Dumper:  srv.Dumper,
-               Metrics: srv.metrics,
+               Logger:         srv.Logger,
+               Dumper:         srv.Dumper,
+               Metrics:        srv.metrics,
+               LostBlocksFile: srv.config.LostBlocksFile,
        }
        var err error
        srv.runOptions, err = bal.Run(srv.config, srv.runOptions)