projects
/
arvados.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
15654: Update nokogiri
[arvados.git]
/
services
/
keep-balance
/
server.go
diff --git
a/services/keep-balance/server.go
b/services/keep-balance/server.go
index c47305aefcc6e04152bbc926dab12c478b5ee60c..e2f13a425ed8dfabc729649d98aa7e4ed977899a 100644
(file)
--- a/
services/keep-balance/server.go
+++ b/
services/keep-balance/server.go
@@
-5,6
+5,7
@@
package main
import (
package main
import (
+ "context"
"fmt"
"net/http"
"os"
"fmt"
"net/http"
"os"
@@
-13,8
+14,10
@@
import (
"time"
"git.curoverse.com/arvados.git/sdk/go/arvados"
"time"
"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"
"git.curoverse.com/arvados.git/sdk/go/httpserver"
- "github.com/
S
irupsen/logrus"
+ "github.com/
s
irupsen/logrus"
)
var version = "dev"
)
var version = "dev"
@@
-40,6
+43,9
@@
type Config struct {
// address, address:port, or :port for management interface
Listen string
// address, address:port, or :port for management interface
Listen string
+ // token for management APIs
+ ManagementToken string
+
// How often to check
RunPeriod arvados.Duration
// How often to check
RunPeriod arvados.Duration
@@
-53,6
+59,10
@@
type Config struct {
// Timeout for outgoing http request/response cycle.
RequestTimeout arvados.Duration
// 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
}
// RunOptions controls runtime behavior. The flags/options that belong
@@
-66,8
+76,8
@@
type RunOptions struct {
Once bool
CommitPulls bool
CommitTrash bool
Once bool
CommitPulls bool
CommitTrash bool
- Logger
*logrus.
Logger
- Dumper
*logrus.
Logger
+ Logger
logrus.Field
Logger
+ Dumper
logrus.Field
Logger
// SafeRendezvousState from the most recent balance operation,
// or "" if unknown. If this changes from one run to the next,
// SafeRendezvousState from the most recent balance operation,
// or "" if unknown. If this changes from one run to the next,
@@
-82,8
+92,8
@@
type Server struct {
metrics *metrics
listening string // for tests
metrics *metrics
listening string // for tests
- Logger
*logrus.
Logger
- Dumper
*logrus.
Logger
+ Logger
logrus.Field
Logger
+ Dumper
logrus.Field
Logger
}
// NewServer returns a new Server that runs Balancers using the given
}
// NewServer returns a new Server that runs Balancers using the given
@@
-119,9
+129,13
@@
func (srv *Server) start() error {
if srv.config.Listen == "" {
return nil
}
if srv.config.Listen == "" {
return nil
}
+ ctx := ctxlog.Context(context.Background(), srv.Logger)
server := &httpserver.Server{
Server: http.Server{
server := &httpserver.Server{
Server: http.Server{
- Handler: httpserver.LogRequests(srv.Logger, 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,
}
},
Addr: srv.config.Listen,
}
@@
-136,9
+150,10
@@
func (srv *Server) start() error {
func (srv *Server) Run() (*Balancer, error) {
bal := &Balancer{
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)
}
var err error
srv.runOptions, err = bal.Run(srv.config, srv.runOptions)