X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/6e38822705235d01fbb7d51626b073174a65e46e..93cfe7c262708fb09eda5aad1839c832816d4591:/services/keepstore/config.go diff --git a/services/keepstore/config.go b/services/keepstore/config.go index 83dd84ecc0..43a2191111 100644 --- a/services/keepstore/config.go +++ b/services/keepstore/config.go @@ -1,3 +1,7 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + package main import ( @@ -9,7 +13,8 @@ import ( "time" "git.curoverse.com/arvados.git/sdk/go/arvados" - log "github.com/Sirupsen/logrus" + "github.com/prometheus/client_golang/prometheus" + "github.com/sirupsen/logrus" ) type Config struct { @@ -30,15 +35,34 @@ type Config struct { EnableDelete bool TrashLifetime arvados.Duration TrashCheckInterval arvados.Duration + PullWorkers int + TrashWorkers int + EmptyTrashWorkers int + TLSCertificateFile string + TLSKeyFile string Volumes VolumeList blobSigningKey []byte systemAuthToken string debugLogf func(string, ...interface{}) + + ManagementToken string } -var theConfig = DefaultConfig() +var ( + theConfig = DefaultConfig() + formatter = map[string]logrus.Formatter{ + "text": &logrus.TextFormatter{ + FullTimestamp: true, + TimestampFormat: rfc3339NanoFixed, + }, + "json": &logrus.JSONFormatter{ + TimestampFormat: rfc3339NanoFixed, + }, + } + log = logrus.StandardLogger() +) const rfc3339NanoFixed = "2006-01-02T15:04:05.000000000Z07:00" @@ -58,28 +82,21 @@ func DefaultConfig() *Config { // Start should be called exactly once: after setting all public // fields, and before using the config. -func (cfg *Config) Start() error { +func (cfg *Config) Start(reg *prometheus.Registry) error { if cfg.Debug { - log.SetLevel(log.DebugLevel) + log.Level = logrus.DebugLevel cfg.debugLogf = log.Printf cfg.debugLogf("debugging enabled") } else { + log.Level = logrus.InfoLevel cfg.debugLogf = func(string, ...interface{}) {} } - switch strings.ToLower(cfg.LogFormat) { - case "text": - log.SetFormatter(&log.TextFormatter{ - FullTimestamp: true, - TimestampFormat: rfc3339NanoFixed, - }) - case "json": - log.SetFormatter(&log.JSONFormatter{ - TimestampFormat: rfc3339NanoFixed, - }) - default: + f := formatter[strings.ToLower(cfg.LogFormat)] + if f == nil { return fmt.Errorf(`unsupported log format %q (try "text" or "json")`, cfg.LogFormat) } + log.Formatter = f if cfg.MaxBuffers < 0 { return fmt.Errorf("MaxBuffers must be greater than zero") @@ -127,8 +144,9 @@ func (cfg *Config) Start() error { return fmt.Errorf("no volumes found") } } + vm := newVolumeMetricsVecs(reg) for _, v := range cfg.Volumes { - if err := v.Start(); err != nil { + if err := v.Start(vm); err != nil { return fmt.Errorf("volume %s: %s", v, err) } log.Printf("Using volume %v (writable=%v)", v, v.Writable()) @@ -142,14 +160,14 @@ var VolumeTypes = []func() VolumeWithExamples{} type VolumeList []Volume -// UnmarshalJSON, given an array of objects, deserializes each object -// as the volume type indicated by the object's Type field. -func (vols *VolumeList) UnmarshalJSON(data []byte) error { +// UnmarshalJSON -- given an array of objects -- deserializes each +// object as the volume type indicated by the object's Type field. +func (vl *VolumeList) UnmarshalJSON(data []byte) error { typeMap := map[string]func() VolumeWithExamples{} for _, factory := range VolumeTypes { t := factory().Type() if _, ok := typeMap[t]; ok { - log.Fatal("volume type %+q is claimed by multiple VolumeTypes") + log.Fatalf("volume type %+q is claimed by multiple VolumeTypes", t) } typeMap[t] = factory } @@ -177,7 +195,7 @@ func (vols *VolumeList) UnmarshalJSON(data []byte) error { if err != nil { return err } - *vols = append(*vols, vol) + *vl = append(*vl, vol) } return nil }