From 43a26229a5daebe6f24dc908b9f2d32da3a362f6 Mon Sep 17 00:00:00 2001 From: "Jonathan A. Sternberg" Date: Fri, 27 Oct 2017 12:27:01 -0500 Subject: [PATCH] Update the zap logger dependency The previous sha was taken from a revision on a devel branch that I thought would continue staying in the tree after it was merged. That revision was rebased away and the API was changed for the logger. This updates the usage of the logger and adds a simple package for constructing the base logger. --- Godeps | 5 +++-- LICENSE_OF_DEPENDENCIES.md | 5 +++-- cmd/influx_inspect/inmem2tsi/inmem2tsi.go | 18 +++++++---------- cmd/influxd/main.go | 10 ++++------ cmd/influxd/run/command.go | 6 +++--- cmd/influxd/run/server.go | 14 ++++++------- cmd/store/main.go | 10 ++++------ cmd/store/query/query.go | 10 ++++------ coordinator/points_writer.go | 8 ++++---- coordinator/statement_executor_test.go | 7 ++----- internal/tsdb_store.go | 6 +++--- logger/logger.go | 21 ++++++++++++++++++++ monitor/service.go | 8 ++++---- query/query_executor.go | 12 ++++------- query/task_manager.go | 6 +++--- services/collectd/service.go | 8 ++++---- services/collectd/service_test.go | 12 +++-------- services/continuous_querier/service.go | 8 ++++---- services/continuous_querier/service_test.go | 7 ++----- services/graphite/service.go | 8 ++++---- services/graphite/service_test.go | 7 ++----- services/httpd/handler.go | 6 +++--- services/httpd/service.go | 8 ++++---- services/meta/client.go | 8 ++++---- services/opentsdb/handler.go | 4 ++-- services/opentsdb/service.go | 8 ++++---- services/opentsdb/service_test.go | 7 ++----- services/precreator/service.go | 8 ++++---- services/retention/service.go | 8 ++++---- services/retention/service_test.go | 9 ++------- services/snapshotter/service.go | 8 ++++---- services/storage/rpc_service.go | 4 ++-- services/storage/service.go | 8 ++++---- services/storage/store.go | 8 ++++---- services/storage/yarpc_server.go | 4 ++-- services/subscriber/service.go | 10 +++++----- services/udp/service.go | 8 ++++---- services/udp/service_test.go | 7 ++----- tsdb/engine.go | 4 ++-- tsdb/engine/tsm1/cache.go | 8 ++++---- tsdb/engine/tsm1/engine.go | 12 +++++------ tsdb/engine/tsm1/file_store.go | 12 +++++------ tsdb/engine/tsm1/file_store_test.go | 7 ++----- tsdb/engine/tsm1/iterator.gen.go | 22 ++++++++++----------- tsdb/engine/tsm1/iterator.gen.go.tmpl | 6 +++--- tsdb/engine/tsm1/iterator.go | 6 +++--- tsdb/engine/tsm1/wal.go | 10 +++++----- tsdb/index.go | 4 ++-- tsdb/index/inmem/inmem.go | 4 ++-- tsdb/index/tsi1/index.go | 8 ++++---- tsdb/shard.go | 10 +++++----- tsdb/store.go | 10 +++++----- tsdb/store_test.go | 7 ++----- 53 files changed, 212 insertions(+), 237 deletions(-) create mode 100644 logger/logger.go diff --git a/Godeps b/Godeps index 45fa2fdd8bb..28924bc0a46 100644 --- a/Godeps +++ b/Godeps @@ -21,9 +21,10 @@ github.com/philhofer/fwd 1612a298117663d7bc9a760ae20d383413859798 github.com/retailnext/hllpp 38a7bb71b483e855d35010808143beaf05b67f9d github.com/spaolacci/murmur3 0d12bf811670bf6a1a63828dfbd003eded177fce github.com/tinylib/msgp ad0ff2e232ad2e37faf67087fb24bf8d04a8ce20 -github.com/uber-go/atomic 74ca5ec650841aee9f289dce76e928313a37cbc6 -github.com/uber-go/zap fbae0281ffd546fa6d1959fec6075ac5da7fb577 github.com/xlab/treeprint 06dfc6fa17cdde904617990a0c2d89e3e332dbb3 +go.uber.org/atomic 54f72d32435d760d5604f17a82e2435b28dc4ba5 +go.uber.org/multierr fb7d312c2c04c34f0ad621048bbb953b168f9ff6 +go.uber.org/zap 35aad584952c3e7020db7b839f6b102de6271f89 golang.org/x/crypto 9477e0b78b9ac3d0b03822fd95422e2fe07627cd golang.org/x/sys 062cd7e4e68206d8bab9b18396626e855c992658 golang.org/x/text a71fd10341b064c10f4a81ceac72bcf70f26ea34 diff --git a/LICENSE_OF_DEPENDENCIES.md b/LICENSE_OF_DEPENDENCIES.md index 8311b751a03..a9a0eb717ca 100644 --- a/LICENSE_OF_DEPENDENCIES.md +++ b/LICENSE_OF_DEPENDENCIES.md @@ -21,8 +21,9 @@ - github.com/tinylib/msgp [MIT LICENSE](https://github.com/tinylib/msgp/blob/master/LICENSE) - github.com/rakyll/statik [APACHE LICENSE](https://github.com/rakyll/statik/blob/master/LICENSE) - github.com/retailnext/hllpp [BSD LICENSE](https://github.com/retailnext/hllpp/blob/master/LICENSE) -- github.com/uber-go/atomic [MIT LICENSE](https://github.com/uber-go/atomic/blob/master/LICENSE.txt) -- github.com/uber-go/zap [MIT LICENSE](https://github.com/uber-go/zap/blob/master/LICENSE.txt) +- go.uber.org/atomic [MIT LICENSE](https://github.com/uber-go/atomic/blob/master/LICENSE.txt) +- go.uber.org/multierr [MIT LICENSE](https://github.com/uber-go/multierr/blob/master/LICENSE.txt) +- go.uber.org/zap [MIT LICENSE](https://github.com/uber-go/zap/blob/master/LICENSE.txt) - golang.org/x/crypto [BSD LICENSE](https://github.com/golang/crypto/blob/master/LICENSE) - golang.org/x/text [BSD LICENSE](https://github.com/golang/text/blob/master/LICENSE) - jquery 2.1.4 [MIT LICENSE](https://github.com/jquery/jquery/blob/master/LICENSE.txt) diff --git a/cmd/influx_inspect/inmem2tsi/inmem2tsi.go b/cmd/influx_inspect/inmem2tsi/inmem2tsi.go index 32cc702ff97..aaae70081c6 100644 --- a/cmd/influx_inspect/inmem2tsi/inmem2tsi.go +++ b/cmd/influx_inspect/inmem2tsi/inmem2tsi.go @@ -10,20 +10,20 @@ import ( "os" "path/filepath" + "github.com/influxdata/influxdb/logger" "github.com/influxdata/influxdb/models" "github.com/influxdata/influxdb/tsdb" "github.com/influxdata/influxdb/tsdb/engine/tsm1" "github.com/influxdata/influxdb/tsdb/index/tsi1" - "github.com/uber-go/zap" + "go.uber.org/zap" ) // Command represents the program execution for "influx_inspect inmem2tsi". type Command struct { - Stderr io.Writer - Stdout io.Writer - + Stderr io.Writer + Stdout io.Writer Verbose bool - Logger zap.Logger + Logger *zap.Logger } // NewCommand returns a new instance of Command. @@ -31,7 +31,7 @@ func NewCommand() *Command { return &Command{ Stderr: os.Stderr, Stdout: os.Stdout, - Logger: zap.New(zap.NullEncoder()), + Logger: zap.NewNop(), } } @@ -47,11 +47,7 @@ func (cmd *Command) Run(args ...string) error { } else if fs.NArg() > 0 || *dataDir == "" || *walDir == "" { return flag.ErrHelp } - - cmd.Logger = zap.New( - zap.NewTextEncoder(), - zap.Output(os.Stderr), - ) + cmd.Logger = logger.New(os.Stderr) return cmd.run(*dataDir, *walDir) } diff --git a/cmd/influxd/main.go b/cmd/influxd/main.go index 84c97c22665..18f903e3e24 100644 --- a/cmd/influxd/main.go +++ b/cmd/influxd/main.go @@ -16,7 +16,8 @@ import ( "github.com/influxdata/influxdb/cmd/influxd/help" "github.com/influxdata/influxdb/cmd/influxd/restore" "github.com/influxdata/influxdb/cmd/influxd/run" - "github.com/uber-go/zap" + "github.com/influxdata/influxdb/logger" + "go.uber.org/zap" ) // These variables are populated via the Go linker. @@ -51,7 +52,7 @@ func main() { // Main represents the program execution. type Main struct { - Logger zap.Logger + Logger *zap.Logger Stdin io.Reader Stdout io.Writer @@ -61,10 +62,7 @@ type Main struct { // NewMain return a new instance of Main. func NewMain() *Main { return &Main{ - Logger: zap.New( - zap.NewTextEncoder(), - zap.Output(os.Stderr), - ), + Logger: logger.New(os.Stderr), Stdin: os.Stdin, Stdout: os.Stdout, Stderr: os.Stderr, diff --git a/cmd/influxd/run/command.go b/cmd/influxd/run/command.go index 0caeb61b6f5..d5db18d7392 100644 --- a/cmd/influxd/run/command.go +++ b/cmd/influxd/run/command.go @@ -13,7 +13,7 @@ import ( "strconv" "time" - "github.com/uber-go/zap" + "go.uber.org/zap" ) const logo = ` @@ -42,7 +42,7 @@ type Command struct { Stdin io.Reader Stdout io.Writer Stderr io.Writer - Logger zap.Logger + Logger *zap.Logger Server *Server @@ -58,7 +58,7 @@ func NewCommand() *Command { Stdin: os.Stdin, Stdout: os.Stdout, Stderr: os.Stderr, - Logger: zap.New(zap.NullEncoder()), + Logger: zap.NewNop(), } } diff --git a/cmd/influxd/run/server.go b/cmd/influxd/run/server.go index abfcab8309c..d43a19872c1 100644 --- a/cmd/influxd/run/server.go +++ b/cmd/influxd/run/server.go @@ -13,6 +13,7 @@ import ( "github.com/influxdata/influxdb" "github.com/influxdata/influxdb/coordinator" + "github.com/influxdata/influxdb/logger" "github.com/influxdata/influxdb/models" "github.com/influxdata/influxdb/monitor" "github.com/influxdata/influxdb/query" @@ -30,7 +31,7 @@ import ( "github.com/influxdata/influxdb/tcp" "github.com/influxdata/influxdb/tsdb" client "github.com/influxdata/usage-client/v1" - "github.com/uber-go/zap" + "go.uber.org/zap" // Initialize the engine & index packages "github.com/influxdata/influxdb/services/storage" @@ -64,7 +65,7 @@ type Server struct { BindAddress string Listener net.Listener - Logger zap.Logger + Logger *zap.Logger MetaClient *meta.Client @@ -142,10 +143,7 @@ func NewServer(c *Config, buildInfo *BuildInfo) (*Server, error) { BindAddress: bind, - Logger: zap.New( - zap.NewTextEncoder(), - zap.Output(os.Stderr), - ), + Logger: logger.New(os.Stderr), MetaClient: meta.NewClient(c.Meta), @@ -234,7 +232,7 @@ func (s *Server) appendSnapshotterService() { // SetLogOutput sets the logger used for all messages. It must not be called // after the Open method has been called. func (s *Server) SetLogOutput(w io.Writer) { - s.Logger = zap.New(zap.NewTextEncoder(), zap.Output(zap.AddSync(w))) + s.Logger = logger.New(w) } func (s *Server) appendMonitorService() { @@ -563,7 +561,7 @@ func (s *Server) reportServer() { // Service represents a service attached to the server. type Service interface { - WithLogger(log zap.Logger) + WithLogger(log *zap.Logger) Open() error Close() error } diff --git a/cmd/store/main.go b/cmd/store/main.go index 2be397b0e76..6b3968cf1fd 100644 --- a/cmd/store/main.go +++ b/cmd/store/main.go @@ -9,8 +9,9 @@ import ( "github.com/influxdata/influxdb/cmd" "github.com/influxdata/influxdb/cmd/store/help" "github.com/influxdata/influxdb/cmd/store/query" + "github.com/influxdata/influxdb/logger" _ "github.com/influxdata/influxdb/tsdb/engine" - "github.com/uber-go/zap" + "go.uber.org/zap" ) func main() { @@ -23,7 +24,7 @@ func main() { // Main represents the program execution. type Main struct { - Logger zap.Logger + Logger *zap.Logger Stdin io.Reader Stdout io.Writer @@ -33,10 +34,7 @@ type Main struct { // NewMain returns a new instance of Main. func NewMain() *Main { return &Main{ - Logger: zap.New( - zap.NewTextEncoder(), - zap.Output(os.Stderr), - ), + Logger: logger.New(os.Stderr), Stdin: os.Stdin, Stdout: os.Stdout, Stderr: os.Stderr, diff --git a/cmd/store/query/query.go b/cmd/store/query/query.go index 54acc906441..15aa7d643e7 100644 --- a/cmd/store/query/query.go +++ b/cmd/store/query/query.go @@ -3,24 +3,22 @@ package query import ( "bufio" "context" + "errors" "flag" "fmt" "io" "os" "path/filepath" "strconv" - "time" - - "errors" - "strings" + "time" "github.com/gogo/protobuf/proto" "github.com/influxdata/influxdb/models" "github.com/influxdata/influxdb/services/storage" "github.com/influxdata/influxql" "github.com/influxdata/yarpc" - "github.com/uber-go/zap" + "go.uber.org/zap" ) // Command represents the program execution for "influx_inspect export". @@ -28,7 +26,7 @@ type Command struct { // Standard input/output, overridden for testing. Stderr io.Writer Stdout io.Writer - Logger zap.Logger + Logger *zap.Logger addr string cpuProfile string diff --git a/coordinator/points_writer.go b/coordinator/points_writer.go index bee4a385a9b..af63abfe38d 100644 --- a/coordinator/points_writer.go +++ b/coordinator/points_writer.go @@ -12,7 +12,7 @@ import ( "github.com/influxdata/influxdb/models" "github.com/influxdata/influxdb/services/meta" "github.com/influxdata/influxdb/tsdb" - "github.com/uber-go/zap" + "go.uber.org/zap" ) // The keys for statistics generated by the "write" module. @@ -45,7 +45,7 @@ type PointsWriter struct { mu sync.RWMutex closing chan struct{} WriteTimeout time.Duration - Logger zap.Logger + Logger *zap.Logger Node *influxdb.Node @@ -88,7 +88,7 @@ func NewPointsWriter() *PointsWriter { return &PointsWriter{ closing: make(chan struct{}), WriteTimeout: DefaultWriteTimeout, - Logger: zap.New(zap.NullEncoder()), + Logger: zap.NewNop(), stats: &WriteStatistics{}, } } @@ -148,7 +148,7 @@ func (w *PointsWriter) AddWriteSubscriber(c chan<- *WritePointsRequest) { } // WithLogger sets the Logger on w. -func (w *PointsWriter) WithLogger(log zap.Logger) { +func (w *PointsWriter) WithLogger(log *zap.Logger) { w.Logger = log.With(zap.String("service", "write")) } diff --git a/coordinator/statement_executor_test.go b/coordinator/statement_executor_test.go index db21bf2abf1..27b8c1bc3a0 100644 --- a/coordinator/statement_executor_test.go +++ b/coordinator/statement_executor_test.go @@ -14,12 +14,12 @@ import ( "github.com/davecgh/go-spew/spew" "github.com/influxdata/influxdb/coordinator" "github.com/influxdata/influxdb/internal" + "github.com/influxdata/influxdb/logger" "github.com/influxdata/influxdb/models" "github.com/influxdata/influxdb/query" "github.com/influxdata/influxdb/services/meta" "github.com/influxdata/influxdb/tsdb" "github.com/influxdata/influxql" - "github.com/uber-go/zap" ) const ( @@ -288,10 +288,7 @@ func NewQueryExecutor() *QueryExecutor { if testing.Verbose() { out = io.MultiWriter(out, os.Stderr) } - e.QueryExecutor.WithLogger(zap.New( - zap.NewTextEncoder(), - zap.Output(zap.AddSync(out)), - )) + e.QueryExecutor.WithLogger(logger.New(out)) return e } diff --git a/internal/tsdb_store.go b/internal/tsdb_store.go index 2d5c70be0cd..c1655c4ce08 100644 --- a/internal/tsdb_store.go +++ b/internal/tsdb_store.go @@ -8,7 +8,7 @@ import ( "github.com/influxdata/influxdb/query" "github.com/influxdata/influxdb/tsdb" "github.com/influxdata/influxql" - "github.com/uber-go/zap" + "go.uber.org/zap" ) // TSDBStoreMock is a mockable implementation of tsdb.Store. @@ -42,7 +42,7 @@ type TSDBStoreMock struct { ShardsFn func(ids []uint64) []*tsdb.Shard StatisticsFn func(tags map[string]string) []models.Statistic TagValuesFn func(auth query.Authorizer, database string, cond influxql.Expr) ([]tsdb.TagValues, error) - WithLoggerFn func(log zap.Logger) + WithLoggerFn func(log *zap.Logger) WriteToShardFn func(shardID uint64, points []models.Point) error } @@ -131,7 +131,7 @@ func (s *TSDBStoreMock) Statistics(tags map[string]string) []models.Statistic { func (s *TSDBStoreMock) TagValues(auth query.Authorizer, database string, cond influxql.Expr) ([]tsdb.TagValues, error) { return s.TagValuesFn(auth, database, cond) } -func (s *TSDBStoreMock) WithLogger(log zap.Logger) { +func (s *TSDBStoreMock) WithLogger(log *zap.Logger) { s.WithLoggerFn(log) } func (s *TSDBStoreMock) WriteToShard(shardID uint64, points []models.Point) error { diff --git a/logger/logger.go b/logger/logger.go new file mode 100644 index 00000000000..b6b43cc537d --- /dev/null +++ b/logger/logger.go @@ -0,0 +1,21 @@ +package logger + +import ( + "io" + "time" + + "go.uber.org/zap" + "go.uber.org/zap/zapcore" +) + +func New(w io.Writer) *zap.Logger { + config := zap.NewProductionEncoderConfig() + config.EncodeTime = func(ts time.Time, encoder zapcore.PrimitiveArrayEncoder) { + encoder.AppendString(ts.UTC().Format(time.RFC3339)) + } + return zap.New(zapcore.NewCore( + zapcore.NewConsoleEncoder(config), + zapcore.AddSync(w), + zapcore.DebugLevel, + )) +} diff --git a/monitor/service.go b/monitor/service.go index 5aaa097c23a..82ee8d21da3 100644 --- a/monitor/service.go +++ b/monitor/service.go @@ -16,7 +16,7 @@ import ( "github.com/influxdata/influxdb/models" "github.com/influxdata/influxdb/monitor/diagnostics" "github.com/influxdata/influxdb/services/meta" - "github.com/uber-go/zap" + "go.uber.org/zap" ) // Policy constants. @@ -61,7 +61,7 @@ type Monitor struct { // Writer for pushing stats back into the database. PointsWriter PointsWriter - Logger zap.Logger + Logger *zap.Logger } // PointsWriter is a simplified interface for writing the points the monitor gathers. @@ -79,7 +79,7 @@ func New(r Reporter, c Config) *Monitor { storeDatabase: c.StoreDatabase, storeInterval: time.Duration(c.StoreInterval), storeRetentionPolicy: MonitorRetentionPolicy, - Logger: zap.New(zap.NullEncoder()), + Logger: zap.NewNop(), } } @@ -211,7 +211,7 @@ func (m *Monitor) SetPointsWriter(pw PointsWriter) error { } // WithLogger sets the logger for the Monitor. -func (m *Monitor) WithLogger(log zap.Logger) { +func (m *Monitor) WithLogger(log *zap.Logger) { m.Logger = log.With(zap.String("service", "monitor")) } diff --git a/query/query_executor.go b/query/query_executor.go index 765e8a4662e..36a36fd8713 100644 --- a/query/query_executor.go +++ b/query/query_executor.go @@ -13,7 +13,7 @@ import ( "github.com/influxdata/influxdb/models" "github.com/influxdata/influxql" - "github.com/uber-go/zap" + "go.uber.org/zap" ) var ( @@ -141,9 +141,6 @@ type ExecutionContext struct { // Output channel where results and errors should be sent. Results chan *Result - // Hold the query executor's logger. - Log zap.Logger - // A channel that is closed when the query is interrupted. InterruptCh <-chan struct{} @@ -219,7 +216,7 @@ type QueryExecutor struct { // Logger to use for all logging. // Defaults to discarding all log output. - Logger zap.Logger + Logger *zap.Logger // expvar-based stats. stats *QueryStatistics @@ -229,7 +226,7 @@ type QueryExecutor struct { func NewQueryExecutor() *QueryExecutor { return &QueryExecutor{ TaskManager: NewTaskManager(), - Logger: zap.New(zap.NullEncoder()), + Logger: zap.NewNop(), stats: &QueryStatistics{}, } } @@ -265,7 +262,7 @@ func (e *QueryExecutor) Close() error { // SetLogOutput sets the writer to which all logs are written. It must not be // called after Open is called. -func (e *QueryExecutor) WithLogger(log zap.Logger) { +func (e *QueryExecutor) WithLogger(log *zap.Logger) { e.Logger = log.With(zap.String("service", "query")) e.TaskManager.Logger = e.Logger } @@ -304,7 +301,6 @@ func (e *QueryExecutor) executeQuery(query *influxql.Query, opt ExecutionOptions QueryID: qid, Query: task, Results: results, - Log: e.Logger, InterruptCh: task.closing, ExecutionOptions: opt, } diff --git a/query/task_manager.go b/query/task_manager.go index 7f3fdbd5340..1d1c6fd04ef 100644 --- a/query/task_manager.go +++ b/query/task_manager.go @@ -7,7 +7,7 @@ import ( "github.com/influxdata/influxdb/models" "github.com/influxdata/influxql" - "github.com/uber-go/zap" + "go.uber.org/zap" ) const ( @@ -51,7 +51,7 @@ type TaskManager struct { // Logger to use for all logging. // Defaults to discarding all log output. - Logger zap.Logger + Logger *zap.Logger // Used for managing and tracking running queries. queries map[uint64]*QueryTask @@ -64,7 +64,7 @@ type TaskManager struct { func NewTaskManager() *TaskManager { return &TaskManager{ QueryTimeout: DefaultQueryTimeout, - Logger: zap.New(zap.NullEncoder()), + Logger: zap.NewNop(), queries: make(map[uint64]*QueryTask), nextID: 1, } diff --git a/services/collectd/service.go b/services/collectd/service.go index 3e61ff1240c..85feefc0f7b 100644 --- a/services/collectd/service.go +++ b/services/collectd/service.go @@ -18,7 +18,7 @@ import ( "github.com/influxdata/influxdb/models" "github.com/influxdata/influxdb/services/meta" "github.com/influxdata/influxdb/tsdb" - "github.com/uber-go/zap" + "go.uber.org/zap" ) // statistics gathered by the collectd service. @@ -59,7 +59,7 @@ type Service struct { Config *Config MetaClient metaClient PointsWriter pointsWriter - Logger zap.Logger + Logger *zap.Logger wg sync.WaitGroup conn *net.UDPConn @@ -82,7 +82,7 @@ func NewService(c Config) *Service { // Use defaults where necessary. Config: c.WithDefaults(), - Logger: zap.New(zap.NullEncoder()), + Logger: zap.NewNop(), stats: &Statistics{}, defaultTags: models.StatisticTags{"bind": c.BindAddress}, } @@ -277,7 +277,7 @@ func (s *Service) createInternalStorage() error { } // WithLogger sets the service's logger. -func (s *Service) WithLogger(log zap.Logger) { +func (s *Service) WithLogger(log *zap.Logger) { s.Logger = log.With(zap.String("service", "collectd")) } diff --git a/services/collectd/service_test.go b/services/collectd/service_test.go index d10b55f4dde..ac59cb2373c 100644 --- a/services/collectd/service_test.go +++ b/services/collectd/service_test.go @@ -12,10 +12,10 @@ import ( "time" "github.com/influxdata/influxdb/internal" + "github.com/influxdata/influxdb/logger" "github.com/influxdata/influxdb/models" "github.com/influxdata/influxdb/services/meta" "github.com/influxdata/influxdb/toml" - "github.com/uber-go/zap" ) func TestService_OpenClose(t *testing.T) { @@ -87,10 +87,7 @@ func TestService_Open_TypesDBDir(t *testing.T) { } if testing.Verbose() { - s.Service.WithLogger(zap.New( - zap.NewTextEncoder(), - zap.Output(os.Stderr), - )) + s.Service.WithLogger(logger.New(os.Stderr)) } s.MetaClient.CreateDatabaseFn = func(name string) (*meta.DatabaseInfo, error) { @@ -424,10 +421,7 @@ func NewTestService(batchSize int, batchDuration time.Duration, parseOpt string) } if testing.Verbose() { - s.Service.WithLogger(zap.New( - zap.NewTextEncoder(), - zap.Output(os.Stderr), - )) + s.Service.WithLogger(logger.New(os.Stderr)) } return s diff --git a/services/continuous_querier/service.go b/services/continuous_querier/service.go index e07082e1753..e7d7cead75b 100644 --- a/services/continuous_querier/service.go +++ b/services/continuous_querier/service.go @@ -13,7 +13,7 @@ import ( "github.com/influxdata/influxdb/query" "github.com/influxdata/influxdb/services/meta" "github.com/influxdata/influxql" - "github.com/uber-go/zap" + "go.uber.org/zap" ) const ( @@ -87,7 +87,7 @@ type Service struct { RunInterval time.Duration // RunCh can be used by clients to signal service to run CQs. RunCh chan *RunRequest - Logger zap.Logger + Logger *zap.Logger loggingEnabled bool queryStatsEnabled bool stats *Statistics @@ -107,7 +107,7 @@ func NewService(c Config) *Service { RunCh: make(chan *RunRequest), loggingEnabled: c.LogEnabled, queryStatsEnabled: c.QueryStatsEnabled, - Logger: zap.New(zap.NullEncoder()), + Logger: zap.NewNop(), stats: &Statistics{}, lastRuns: map[string]time.Time{}, } @@ -146,7 +146,7 @@ func (s *Service) Close() error { } // WithLogger sets the logger on the service. -func (s *Service) WithLogger(log zap.Logger) { +func (s *Service) WithLogger(log *zap.Logger) { s.Logger = log.With(zap.String("service", "continuous_querier")) } diff --git a/services/continuous_querier/service_test.go b/services/continuous_querier/service_test.go index f040a3427b8..a84bdaf0232 100644 --- a/services/continuous_querier/service_test.go +++ b/services/continuous_querier/service_test.go @@ -8,11 +8,11 @@ import ( "testing" "time" + "github.com/influxdata/influxdb/logger" "github.com/influxdata/influxdb/models" "github.com/influxdata/influxdb/query" "github.com/influxdata/influxdb/services/meta" "github.com/influxdata/influxql" - "github.com/uber-go/zap" ) var ( @@ -691,10 +691,7 @@ func NewTestService(t *testing.T) *Service { // Set Logger to write to dev/null so stdout isn't polluted. if testing.Verbose() { - s.WithLogger(zap.New( - zap.NewTextEncoder(), - zap.Output(os.Stderr), - )) + s.WithLogger(logger.New(os.Stderr)) } // Add a couple test databases and CQs. diff --git a/services/graphite/service.go b/services/graphite/service.go index b8444d15682..3a6437b6571 100644 --- a/services/graphite/service.go +++ b/services/graphite/service.go @@ -15,7 +15,7 @@ import ( "github.com/influxdata/influxdb/monitor/diagnostics" "github.com/influxdata/influxdb/services/meta" "github.com/influxdata/influxdb/tsdb" - "github.com/uber-go/zap" + "go.uber.org/zap" ) const udpBufferSize = 65536 @@ -56,7 +56,7 @@ type Service struct { batcher *tsdb.PointBatcher parser *Parser - logger zap.Logger + logger *zap.Logger stats *Statistics defaultTags models.StatisticTags @@ -103,7 +103,7 @@ func NewService(c Config) (*Service, error) { batchPending: d.BatchPending, udpReadBuffer: d.UDPReadBuffer, batchTimeout: time.Duration(d.BatchTimeout), - logger: zap.New(zap.NullEncoder()), + logger: zap.NewNop(), stats: &Statistics{}, defaultTags: models.StatisticTags{"proto": d.Protocol, "bind": d.BindAddress}, tcpConnections: make(map[string]*tcpConnection), @@ -259,7 +259,7 @@ func (s *Service) createInternalStorage() error { } // WithLogger sets the logger on the service. -func (s *Service) WithLogger(log zap.Logger) { +func (s *Service) WithLogger(log *zap.Logger) { s.logger = log.With( zap.String("service", "graphite"), zap.String("addr", s.bindAddress), diff --git a/services/graphite/service_test.go b/services/graphite/service_test.go index fa5d330c8ff..54aba9e63dc 100644 --- a/services/graphite/service_test.go +++ b/services/graphite/service_test.go @@ -10,10 +10,10 @@ import ( "time" "github.com/influxdata/influxdb/internal" + "github.com/influxdata/influxdb/logger" "github.com/influxdata/influxdb/models" "github.com/influxdata/influxdb/services/meta" "github.com/influxdata/influxdb/toml" - "github.com/uber-go/zap" ) func Test_Service_OpenClose(t *testing.T) { @@ -291,10 +291,7 @@ func NewTestService(c *Config) *TestService { } if testing.Verbose() { - service.Service.WithLogger(zap.New( - zap.NewTextEncoder(), - zap.Output(os.Stderr), - )) + service.Service.WithLogger(logger.New(os.Stderr)) } // Set the Meta Client and PointsWriter. diff --git a/services/httpd/handler.go b/services/httpd/handler.go index d0df75566c3..95398ed394a 100644 --- a/services/httpd/handler.go +++ b/services/httpd/handler.go @@ -34,7 +34,7 @@ import ( "github.com/influxdata/influxdb/tsdb" "github.com/influxdata/influxdb/uuid" "github.com/influxdata/influxql" - "github.com/uber-go/zap" + "go.uber.org/zap" ) const ( @@ -107,7 +107,7 @@ type Handler struct { } Config *Config - Logger zap.Logger + Logger *zap.Logger CLFLogger *log.Logger stats *Statistics @@ -119,7 +119,7 @@ func NewHandler(c Config) *Handler { h := &Handler{ mux: pat.New(), Config: &c, - Logger: zap.New(zap.NullEncoder()), + Logger: zap.NewNop(), CLFLogger: log.New(os.Stderr, "[httpd] ", 0), stats: &Statistics{}, requestTracker: NewRequestTracker(), diff --git a/services/httpd/service.go b/services/httpd/service.go index 5a55d473ee8..5d0711b5d25 100644 --- a/services/httpd/service.go +++ b/services/httpd/service.go @@ -14,7 +14,7 @@ import ( "time" "github.com/influxdata/influxdb/models" - "github.com/uber-go/zap" + "go.uber.org/zap" ) // statistics gathered by the httpd package. @@ -60,7 +60,7 @@ type Service struct { Handler *Handler - Logger zap.Logger + Logger *zap.Logger } // NewService returns a new instance of Service. @@ -75,7 +75,7 @@ func NewService(c Config) *Service { unixSocket: c.UnixSocketEnabled, bindSocket: c.BindSocket, Handler: NewHandler(c), - Logger: zap.New(zap.NullEncoder()), + Logger: zap.NewNop(), } if s.key == "" { s.key = s.cert @@ -177,7 +177,7 @@ func (s *Service) Close() error { } // WithLogger sets the logger for the service. -func (s *Service) WithLogger(log zap.Logger) { +func (s *Service) WithLogger(log *zap.Logger) { s.Logger = log.With(zap.String("service", "httpd")) s.Handler.Logger = s.Logger } diff --git a/services/meta/client.go b/services/meta/client.go index ec068329cf3..dd15f69216f 100644 --- a/services/meta/client.go +++ b/services/meta/client.go @@ -20,7 +20,7 @@ import ( "github.com/influxdata/influxdb" "github.com/influxdata/influxql" - "github.com/uber-go/zap" + "go.uber.org/zap" "golang.org/x/crypto/bcrypt" ) @@ -47,7 +47,7 @@ var ( // Client is used to execute commands on and read data from // a meta service cluster. type Client struct { - logger zap.Logger + logger *zap.Logger mu sync.RWMutex closing chan struct{} @@ -77,7 +77,7 @@ func NewClient(config *Config) *Client { }, closing: make(chan struct{}), changed: make(chan struct{}), - logger: zap.New(zap.NullEncoder()), + logger: zap.NewNop(), authCache: make(map[string]authUser, 0), path: config.Dir, retentionAutoCreate: config.RetentionAutoCreate, @@ -979,7 +979,7 @@ func (c *Client) MarshalBinary() ([]byte, error) { } // WithLogger sets the logger for the client. -func (c *Client) WithLogger(log zap.Logger) { +func (c *Client) WithLogger(log *zap.Logger) { c.mu.Lock() defer c.mu.Unlock() c.logger = log.With(zap.String("service", "metaclient")) diff --git a/services/opentsdb/handler.go b/services/opentsdb/handler.go index b2d7e24c804..f41a6fb23ca 100644 --- a/services/opentsdb/handler.go +++ b/services/opentsdb/handler.go @@ -15,7 +15,7 @@ import ( "github.com/influxdata/influxdb" "github.com/influxdata/influxdb/models" - "github.com/uber-go/zap" + "go.uber.org/zap" ) // Handler is an http.Handler for the OpenTSDB service. @@ -27,7 +27,7 @@ type Handler struct { WritePointsPrivileged(database, retentionPolicy string, consistencyLevel models.ConsistencyLevel, points []models.Point) error } - Logger zap.Logger + Logger *zap.Logger stats *Statistics } diff --git a/services/opentsdb/service.go b/services/opentsdb/service.go index 4c60f5e2864..05a4d9faae6 100644 --- a/services/opentsdb/service.go +++ b/services/opentsdb/service.go @@ -19,7 +19,7 @@ import ( "github.com/influxdata/influxdb/models" "github.com/influxdata/influxdb/services/meta" "github.com/influxdata/influxdb/tsdb" - "github.com/uber-go/zap" + "go.uber.org/zap" ) // statistics gathered by the openTSDB package. @@ -73,7 +73,7 @@ type Service struct { batcher *tsdb.PointBatcher LogPointErrors bool - Logger zap.Logger + Logger *zap.Logger stats *Statistics defaultTags models.StatisticTags @@ -93,7 +93,7 @@ func NewService(c Config) (*Service, error) { batchSize: d.BatchSize, batchPending: d.BatchPending, batchTimeout: time.Duration(d.BatchTimeout), - Logger: zap.New(zap.NullEncoder()), + Logger: zap.NewNop(), LogPointErrors: d.LogPointErrors, stats: &Statistics{}, defaultTags: models.StatisticTags{"bind": d.BindAddress}, @@ -230,7 +230,7 @@ func (s *Service) createInternalStorage() error { } // WithLogger sets the logger for the service. -func (s *Service) WithLogger(log zap.Logger) { +func (s *Service) WithLogger(log *zap.Logger) { s.Logger = log.With(zap.String("service", "opentsdb")) } diff --git a/services/opentsdb/service_test.go b/services/opentsdb/service_test.go index ed1abe32b71..ea3172d1f1b 100644 --- a/services/opentsdb/service_test.go +++ b/services/opentsdb/service_test.go @@ -14,9 +14,9 @@ import ( "github.com/davecgh/go-spew/spew" "github.com/influxdata/influxdb/internal" + "github.com/influxdata/influxdb/logger" "github.com/influxdata/influxdb/models" "github.com/influxdata/influxdb/services/meta" - "github.com/uber-go/zap" ) func Test_Service_OpenClose(t *testing.T) { @@ -279,10 +279,7 @@ func NewTestService(database string, bind string) *TestService { } if testing.Verbose() { - service.Service.WithLogger(zap.New( - zap.NewTextEncoder(), - zap.Output(os.Stderr), - )) + service.Service.WithLogger(logger.New(os.Stderr)) } service.Service.MetaClient = service.MetaClient diff --git a/services/precreator/service.go b/services/precreator/service.go index 7feadcdff62..a90192b595e 100644 --- a/services/precreator/service.go +++ b/services/precreator/service.go @@ -6,7 +6,7 @@ import ( "sync" "time" - "github.com/uber-go/zap" + "go.uber.org/zap" ) // Service manages the shard precreation service. @@ -14,7 +14,7 @@ type Service struct { checkInterval time.Duration advancePeriod time.Duration - Logger zap.Logger + Logger *zap.Logger done chan struct{} wg sync.WaitGroup @@ -29,14 +29,14 @@ func NewService(c Config) (*Service, error) { s := Service{ checkInterval: time.Duration(c.CheckInterval), advancePeriod: time.Duration(c.AdvancePeriod), - Logger: zap.New(zap.NullEncoder()), + Logger: zap.NewNop(), } return &s, nil } // WithLogger sets the logger for the service. -func (s *Service) WithLogger(log zap.Logger) { +func (s *Service) WithLogger(log *zap.Logger) { s.Logger = log.With(zap.String("service", "shard-precreation")) } diff --git a/services/retention/service.go b/services/retention/service.go index 53301ddb0e5..5323fa6a297 100644 --- a/services/retention/service.go +++ b/services/retention/service.go @@ -7,7 +7,7 @@ import ( "time" "github.com/influxdata/influxdb/services/meta" - "github.com/uber-go/zap" + "go.uber.org/zap" ) // Service represents the retention policy enforcement service. @@ -26,14 +26,14 @@ type Service struct { wg sync.WaitGroup done chan struct{} - logger zap.Logger + logger *zap.Logger } // NewService returns a configured retention policy enforcement service. func NewService(c Config) *Service { return &Service{ config: c, - logger: zap.New(zap.NullEncoder()), + logger: zap.NewNop(), } } @@ -66,7 +66,7 @@ func (s *Service) Close() error { } // WithLogger sets the logger on the service. -func (s *Service) WithLogger(log zap.Logger) { +func (s *Service) WithLogger(log *zap.Logger) { s.logger = log.With(zap.String("service", "retention")) } diff --git a/services/retention/service_test.go b/services/retention/service_test.go index a1b3705a9d7..c6cc45df02e 100644 --- a/services/retention/service_test.go +++ b/services/retention/service_test.go @@ -9,10 +9,10 @@ import ( "time" "github.com/influxdata/influxdb/internal" + "github.com/influxdata/influxdb/logger" "github.com/influxdata/influxdb/services/meta" "github.com/influxdata/influxdb/services/retention" "github.com/influxdata/influxdb/toml" - "github.com/uber-go/zap" ) func TestService_OpenDisabled(t *testing.T) { @@ -220,12 +220,7 @@ func NewService(c retention.Config) *Service { Service: retention.NewService(c), } - mls := zap.MultiWriteSyncer(zap.AddSync(&s.LogBuf)) - - l := zap.New( - zap.NewTextEncoder(), - zap.Output(mls), - ) + l := logger.New(&s.LogBuf) s.WithLogger(l) s.Service.MetaClient = s.MetaClient diff --git a/services/snapshotter/service.go b/services/snapshotter/service.go index 983a84441df..2876aa61ebf 100644 --- a/services/snapshotter/service.go +++ b/services/snapshotter/service.go @@ -15,7 +15,7 @@ import ( "github.com/influxdata/influxdb" "github.com/influxdata/influxdb/services/meta" "github.com/influxdata/influxdb/tsdb" - "github.com/uber-go/zap" + "go.uber.org/zap" ) const ( @@ -42,14 +42,14 @@ type Service struct { TSDBStore *tsdb.Store Listener net.Listener - Logger zap.Logger + Logger *zap.Logger } // NewService returns a new instance of Service. func NewService() *Service { return &Service{ err: make(chan error), - Logger: zap.New(zap.NullEncoder()), + Logger: zap.NewNop(), } } @@ -72,7 +72,7 @@ func (s *Service) Close() error { } // WithLogger sets the logger on the service. -func (s *Service) WithLogger(log zap.Logger) { +func (s *Service) WithLogger(log *zap.Logger) { s.Logger = log.With(zap.String("service", "snapshot")) } diff --git a/services/storage/rpc_service.go b/services/storage/rpc_service.go index b643731ae5d..53b242787eb 100644 --- a/services/storage/rpc_service.go +++ b/services/storage/rpc_service.go @@ -9,7 +9,7 @@ import ( "github.com/gogo/protobuf/types" "github.com/influxdata/influxdb/tsdb" - "github.com/uber-go/zap" + "go.uber.org/zap" ) //go:generate protoc -I$GOPATH/src -I. --plugin=protoc-gen-yarpc=$GOPATH/bin/protoc-gen-yarpc --yarpc_out=Mgoogle/protobuf/empty.proto=github.com/gogo/protobuf/types:. --gogofaster_out=Mgoogle/protobuf/empty.proto=github.com/gogo/protobuf/types:. storage.proto predicate.proto @@ -19,7 +19,7 @@ type rpcService struct { loggingEnabled bool Store *Store - Logger zap.Logger + Logger *zap.Logger } func (r *rpcService) Capabilities(context.Context, *types.Empty) (*CapabilitiesResponse, error) { diff --git a/services/storage/service.go b/services/storage/service.go index 355b21bc64f..258282eccec 100644 --- a/services/storage/service.go +++ b/services/storage/service.go @@ -5,7 +5,7 @@ import ( "github.com/influxdata/influxdb/services/meta" "github.com/influxdata/influxdb/tsdb" - "github.com/uber-go/zap" + "go.uber.org/zap" ) // Service manages the listener and handler for an HTTP endpoint. @@ -13,7 +13,7 @@ type Service struct { addr string yarpc *yarpcServer loggingEnabled bool - logger zap.Logger + logger *zap.Logger Store *Store TSDBStore *tsdb.Store @@ -28,14 +28,14 @@ func NewService(c Config) *Service { s := &Service{ addr: c.BindAddress, loggingEnabled: c.LogEnabled, - logger: zap.New(zap.NullEncoder()), + logger: zap.NewNop(), } return s } // WithLogger sets the logger for the service. -func (s *Service) WithLogger(log zap.Logger) { +func (s *Service) WithLogger(log *zap.Logger) { s.logger = log.With(zap.String("service", "storage")) } diff --git a/services/storage/store.go b/services/storage/store.go index 09864e5f1b3..8b105160942 100644 --- a/services/storage/store.go +++ b/services/storage/store.go @@ -9,7 +9,7 @@ import ( "github.com/influxdata/influxdb/models" "github.com/influxdata/influxdb/services/meta" "github.com/influxdata/influxdb/tsdb" - "github.com/uber-go/zap" + "go.uber.org/zap" ) type Store struct { @@ -20,15 +20,15 @@ type Store struct { ShardGroupsByTimeRange(database, policy string, min, max time.Time) (a []meta.ShardGroupInfo, err error) } - Logger zap.Logger + Logger *zap.Logger } func NewStore() *Store { - return &Store{Logger: zap.New(zap.NullEncoder())} + return &Store{Logger: zap.NewNop()} } // WithLogger sets the logger for the service. -func (s *Store) WithLogger(log zap.Logger) { +func (s *Store) WithLogger(log *zap.Logger) { s.Logger = log.With(zap.String("service", "store")) } diff --git a/services/storage/yarpc_server.go b/services/storage/yarpc_server.go index f956813f38a..594f2d101a5 100644 --- a/services/storage/yarpc_server.go +++ b/services/storage/yarpc_server.go @@ -4,7 +4,7 @@ import ( "net" "github.com/influxdata/yarpc" - "github.com/uber-go/zap" + "go.uber.org/zap" ) type yarpcServer struct { @@ -12,7 +12,7 @@ type yarpcServer struct { loggingEnabled bool rpc *yarpc.Server store *Store - logger zap.Logger + logger *zap.Logger } func (s *yarpcServer) Open() error { diff --git a/services/subscriber/service.go b/services/subscriber/service.go index d8b0e45bd91..db446d22f29 100644 --- a/services/subscriber/service.go +++ b/services/subscriber/service.go @@ -14,7 +14,7 @@ import ( "github.com/influxdata/influxdb/models" "github.com/influxdata/influxdb/monitor" "github.com/influxdata/influxdb/services/meta" - "github.com/uber-go/zap" + "go.uber.org/zap" ) // Statistics for the Subscriber service. @@ -47,7 +47,7 @@ type Service struct { WaitForDataChanged() chan struct{} } NewPointsWriter func(u url.URL) (PointsWriter, error) - Logger zap.Logger + Logger *zap.Logger update chan struct{} stats *Statistics points chan *coordinator.WritePointsRequest @@ -64,7 +64,7 @@ type Service struct { // NewService returns a subscriber service with given settings func NewService(c Config) *Service { s := &Service{ - Logger: zap.New(zap.NullEncoder()), + Logger: zap.NewNop(), closed: true, stats: &Statistics{}, conf: c, @@ -126,7 +126,7 @@ func (s *Service) Close() error { } // WithLogger sets the logger on the service. -func (s *Service) WithLogger(log zap.Logger) { +func (s *Service) WithLogger(log *zap.Logger) { s.Logger = log.With(zap.String("service", "subscriber")) } @@ -355,7 +355,7 @@ type chanWriter struct { pw PointsWriter pointsWritten *int64 failures *int64 - logger zap.Logger + logger *zap.Logger } // Close closes the chanWriter. diff --git a/services/udp/service.go b/services/udp/service.go index 4e508e27cbc..e950574d8c7 100644 --- a/services/udp/service.go +++ b/services/udp/service.go @@ -12,7 +12,7 @@ import ( "github.com/influxdata/influxdb/models" "github.com/influxdata/influxdb/services/meta" "github.com/influxdata/influxdb/tsdb" - "github.com/uber-go/zap" + "go.uber.org/zap" ) const ( @@ -56,7 +56,7 @@ type Service struct { CreateDatabase(name string) (*meta.DatabaseInfo, error) } - Logger zap.Logger + Logger *zap.Logger stats *Statistics defaultTags models.StatisticTags } @@ -67,7 +67,7 @@ func NewService(c Config) *Service { return &Service{ config: d, parserChan: make(chan []byte, parserChanLen), - Logger: zap.New(zap.NullEncoder()), + Logger: zap.NewNop(), stats: &Statistics{}, defaultTags: models.StatisticTags{"bind": d.BindAddress}, } @@ -300,7 +300,7 @@ func (s *Service) createInternalStorage() error { } // WithLogger sets the logger on the service. -func (s *Service) WithLogger(log zap.Logger) { +func (s *Service) WithLogger(log *zap.Logger) { s.Logger = log.With(zap.String("service", "udp")) } diff --git a/services/udp/service_test.go b/services/udp/service_test.go index bb0e667899b..47b7ff60a23 100644 --- a/services/udp/service_test.go +++ b/services/udp/service_test.go @@ -7,9 +7,9 @@ import ( "time" "github.com/influxdata/influxdb/internal" + "github.com/influxdata/influxdb/logger" "github.com/influxdata/influxdb/models" "github.com/influxdata/influxdb/services/meta" - "github.com/uber-go/zap" ) func TestService_OpenClose(t *testing.T) { @@ -144,10 +144,7 @@ func NewTestService(c *Config) *TestService { } if testing.Verbose() { - service.Service.WithLogger(zap.New( - zap.NewTextEncoder(), - zap.Output(os.Stderr), - )) + service.Service.WithLogger(logger.New(os.Stderr)) } service.Service.MetaClient = service.MetaClient diff --git a/tsdb/engine.go b/tsdb/engine.go index d7c9346d5a0..2e9c5b67f40 100644 --- a/tsdb/engine.go +++ b/tsdb/engine.go @@ -15,7 +15,7 @@ import ( "github.com/influxdata/influxdb/pkg/limiter" "github.com/influxdata/influxdb/query" "github.com/influxdata/influxql" - "github.com/uber-go/zap" + "go.uber.org/zap" ) var ( @@ -35,7 +35,7 @@ type Engine interface { SetEnabled(enabled bool) SetCompactionsEnabled(enabled bool) - WithLogger(zap.Logger) + WithLogger(*zap.Logger) LoadMetadataIndex(shardID uint64, index Index) error diff --git a/tsdb/engine/tsm1/cache.go b/tsdb/engine/tsm1/cache.go index 916627b23d7..f482edd9b9b 100644 --- a/tsdb/engine/tsm1/cache.go +++ b/tsdb/engine/tsm1/cache.go @@ -11,7 +11,7 @@ import ( "github.com/influxdata/influxdb/models" "github.com/influxdata/influxdb/tsdb" "github.com/influxdata/influxql" - "github.com/uber-go/zap" + "go.uber.org/zap" ) // ringShards specifies the number of partitions that the hash ring used to @@ -670,14 +670,14 @@ func (c *Cache) ApplyEntryFn(f func(key []byte, entry *entry) error) error { type CacheLoader struct { files []string - Logger zap.Logger + Logger *zap.Logger } // NewCacheLoader returns a new instance of a CacheLoader. func NewCacheLoader(files []string) *CacheLoader { return &CacheLoader{ files: files, - Logger: zap.New(zap.NullEncoder()), + Logger: zap.NewNop(), } } @@ -747,7 +747,7 @@ func (cl *CacheLoader) Load(cache *Cache) error { } // WithLogger sets the logger on the CacheLoader. -func (cl *CacheLoader) WithLogger(log zap.Logger) { +func (cl *CacheLoader) WithLogger(log *zap.Logger) { cl.Logger = log.With(zap.String("service", "cacheloader")) } diff --git a/tsdb/engine/tsm1/engine.go b/tsdb/engine/tsm1/engine.go index 3653ba9eadb..10c547bbfa9 100644 --- a/tsdb/engine/tsm1/engine.go +++ b/tsdb/engine/tsm1/engine.go @@ -31,7 +31,7 @@ import ( "github.com/influxdata/influxdb/tsdb/index/inmem" "github.com/influxdata/influxdb/tsdb/index/tsi1" "github.com/influxdata/influxql" - "github.com/uber-go/zap" + "go.uber.org/zap" ) //go:generate tmpl -data=@iterator.gen.go.tmpldata iterator.gen.go.tmpl @@ -126,8 +126,8 @@ type Engine struct { id uint64 database string path string - logger zap.Logger // Logger to be used for important messages - traceLogger zap.Logger // Logger to be used when trace-logging is on. + logger *zap.Logger // Logger to be used for important messages + traceLogger *zap.Logger // Logger to be used when trace-logging is on. traceLogging bool index tsdb.Index @@ -174,7 +174,7 @@ func NewEngine(id uint64, idx tsdb.Index, database, path string, walPath string, FileStore: fs, } - logger := zap.New(zap.NullEncoder()) + logger := zap.NewNop() stats := &EngineStatistics{} e := &Engine{ id: id, @@ -541,7 +541,7 @@ func (e *Engine) Close() error { } // WithLogger sets the logger for the engine. -func (e *Engine) WithLogger(log zap.Logger) { +func (e *Engine) WithLogger(log *zap.Logger) { e.logger = log.With(zap.String("engine", "tsm1")) if e.traceLogging { @@ -1510,7 +1510,7 @@ type compactionStrategy struct { successStat *int64 errorStat *int64 - logger zap.Logger + logger *zap.Logger compactor *Compactor fileStore *FileStore diff --git a/tsdb/engine/tsm1/file_store.go b/tsdb/engine/tsm1/file_store.go index d2dedcd0da6..2203189494a 100644 --- a/tsdb/engine/tsm1/file_store.go +++ b/tsdb/engine/tsm1/file_store.go @@ -18,7 +18,7 @@ import ( "github.com/influxdata/influxdb/models" "github.com/influxdata/influxdb/pkg/metrics" "github.com/influxdata/influxdb/query" - "github.com/uber-go/zap" + "go.uber.org/zap" ) // TSMFile represents an on-disk TSM file. @@ -148,8 +148,8 @@ type FileStore struct { files []TSMFile - logger zap.Logger // Logger to be used for important messages - traceLogger zap.Logger // Logger to be used when trace-logging is on. + logger *zap.Logger // Logger to be used for important messages + traceLogger *zap.Logger // Logger to be used when trace-logging is on. traceLogging bool stats *FileStoreStatistics @@ -185,7 +185,7 @@ func (f FileStat) ContainsKey(key []byte) bool { // NewFileStore returns a new instance of FileStore based on the given directory. func NewFileStore(dir string) *FileStore { - logger := zap.New(zap.NullEncoder()) + logger := zap.NewNop() fs := &FileStore{ dir: dir, lastModified: time.Time{}, @@ -210,7 +210,7 @@ func (f *FileStore) enableTraceLogging(enabled bool) { } // WithLogger sets the logger on the file store. -func (f *FileStore) WithLogger(log zap.Logger) { +func (f *FileStore) WithLogger(log *zap.Logger) { f.logger = log.With(zap.String("service", "filestore")) f.purger.logger = f.logger @@ -1260,7 +1260,7 @@ type purger struct { files map[string]TSMFile running bool - logger zap.Logger + logger *zap.Logger } func (p *purger) add(files []TSMFile) { diff --git a/tsdb/engine/tsm1/file_store_test.go b/tsdb/engine/tsm1/file_store_test.go index db856b0827c..5c23193dc82 100644 --- a/tsdb/engine/tsm1/file_store_test.go +++ b/tsdb/engine/tsm1/file_store_test.go @@ -11,8 +11,8 @@ import ( "testing" "time" + "github.com/influxdata/influxdb/logger" "github.com/influxdata/influxdb/tsdb/engine/tsm1" - "github.com/uber-go/zap" ) func TestFileStore_Read(t *testing.T) { @@ -2784,10 +2784,7 @@ func BenchmarkFileStore_Stats(b *testing.B) { fs := tsm1.NewFileStore(dir) if testing.Verbose() { - fs.WithLogger(zap.New( - zap.NewTextEncoder(), - zap.Output(os.Stderr), - )) + fs.WithLogger(logger.New(os.Stderr)) } if err := fs.Open(); err != nil { diff --git a/tsdb/engine/tsm1/iterator.gen.go b/tsdb/engine/tsm1/iterator.gen.go index 7e0b3de0c62..94aaa10cc74 100644 --- a/tsdb/engine/tsm1/iterator.gen.go +++ b/tsdb/engine/tsm1/iterator.gen.go @@ -18,7 +18,7 @@ import ( "github.com/influxdata/influxdb/query" "github.com/influxdata/influxdb/tsdb" "github.com/influxdata/influxql" - "github.com/uber-go/zap" + "go.uber.org/zap" ) type cursor interface { @@ -125,10 +125,10 @@ const statsBufferCopyIntervalN = 100 type floatFinalizerIterator struct { query.FloatIterator - logger zap.Logger + logger *zap.Logger } -func newFloatFinalizerIterator(inner query.FloatIterator, logger zap.Logger) *floatFinalizerIterator { +func newFloatFinalizerIterator(inner query.FloatIterator, logger *zap.Logger) *floatFinalizerIterator { itr := &floatFinalizerIterator{FloatIterator: inner, logger: logger} runtime.SetFinalizer(itr, (*floatFinalizerIterator).closeGC) return itr @@ -588,10 +588,10 @@ func (c *floatDescendingCursor) nextTSM() { type integerFinalizerIterator struct { query.IntegerIterator - logger zap.Logger + logger *zap.Logger } -func newIntegerFinalizerIterator(inner query.IntegerIterator, logger zap.Logger) *integerFinalizerIterator { +func newIntegerFinalizerIterator(inner query.IntegerIterator, logger *zap.Logger) *integerFinalizerIterator { itr := &integerFinalizerIterator{IntegerIterator: inner, logger: logger} runtime.SetFinalizer(itr, (*integerFinalizerIterator).closeGC) return itr @@ -1051,10 +1051,10 @@ func (c *integerDescendingCursor) nextTSM() { type unsignedFinalizerIterator struct { query.UnsignedIterator - logger zap.Logger + logger *zap.Logger } -func newUnsignedFinalizerIterator(inner query.UnsignedIterator, logger zap.Logger) *unsignedFinalizerIterator { +func newUnsignedFinalizerIterator(inner query.UnsignedIterator, logger *zap.Logger) *unsignedFinalizerIterator { itr := &unsignedFinalizerIterator{UnsignedIterator: inner, logger: logger} runtime.SetFinalizer(itr, (*unsignedFinalizerIterator).closeGC) return itr @@ -1514,10 +1514,10 @@ func (c *unsignedDescendingCursor) nextTSM() { type stringFinalizerIterator struct { query.StringIterator - logger zap.Logger + logger *zap.Logger } -func newStringFinalizerIterator(inner query.StringIterator, logger zap.Logger) *stringFinalizerIterator { +func newStringFinalizerIterator(inner query.StringIterator, logger *zap.Logger) *stringFinalizerIterator { itr := &stringFinalizerIterator{StringIterator: inner, logger: logger} runtime.SetFinalizer(itr, (*stringFinalizerIterator).closeGC) return itr @@ -1977,10 +1977,10 @@ func (c *stringDescendingCursor) nextTSM() { type booleanFinalizerIterator struct { query.BooleanIterator - logger zap.Logger + logger *zap.Logger } -func newBooleanFinalizerIterator(inner query.BooleanIterator, logger zap.Logger) *booleanFinalizerIterator { +func newBooleanFinalizerIterator(inner query.BooleanIterator, logger *zap.Logger) *booleanFinalizerIterator { itr := &booleanFinalizerIterator{BooleanIterator: inner, logger: logger} runtime.SetFinalizer(itr, (*booleanFinalizerIterator).closeGC) return itr diff --git a/tsdb/engine/tsm1/iterator.gen.go.tmpl b/tsdb/engine/tsm1/iterator.gen.go.tmpl index 6cea8906a07..df8f66aba72 100644 --- a/tsdb/engine/tsm1/iterator.gen.go.tmpl +++ b/tsdb/engine/tsm1/iterator.gen.go.tmpl @@ -12,7 +12,7 @@ import ( "github.com/influxdata/influxdb/query" "github.com/influxdata/influxdb/tsdb" "github.com/influxdata/influxql" - "github.com/uber-go/zap" + "go.uber.org/zap" ) type cursor interface { @@ -121,10 +121,10 @@ const statsBufferCopyIntervalN = 100 type {{.name}}FinalizerIterator struct { query.{{.Name}}Iterator - logger zap.Logger + logger *zap.Logger } -func new{{.Name}}FinalizerIterator(inner query.{{.Name}}Iterator, logger zap.Logger) *{{.name}}FinalizerIterator { +func new{{.Name}}FinalizerIterator(inner query.{{.Name}}Iterator, logger *zap.Logger) *{{.name}}FinalizerIterator { itr := &{{.name}}FinalizerIterator{ {{.Name}}Iterator: inner, logger: logger} runtime.SetFinalizer(itr, (*{{.name}}FinalizerIterator).closeGC) return itr diff --git a/tsdb/engine/tsm1/iterator.go b/tsdb/engine/tsm1/iterator.go index e0fce2d384f..9db68a22ce5 100644 --- a/tsdb/engine/tsm1/iterator.go +++ b/tsdb/engine/tsm1/iterator.go @@ -8,7 +8,7 @@ import ( "github.com/influxdata/influxdb/pkg/tracing" "github.com/influxdata/influxdb/query" "github.com/influxdata/influxdb/tsdb" - "github.com/uber-go/zap" + "go.uber.org/zap" ) func newLimitIterator(input query.Iterator, opt query.IteratorOptions) query.Iterator { @@ -156,7 +156,7 @@ func (c cursorsAt) close() { // newMergeFinalizerIterator creates a new Merge iterator from the inputs. If the call to Merge succeeds, // the resulting Iterator will be wrapped in a finalizer iterator. // If Merge returns an error, the inputs will be closed. -func newMergeFinalizerIterator(ctx context.Context, inputs []query.Iterator, opt query.IteratorOptions, log zap.Logger) (query.Iterator, error) { +func newMergeFinalizerIterator(ctx context.Context, inputs []query.Iterator, opt query.IteratorOptions, log *zap.Logger) (query.Iterator, error) { itr, err := query.Iterators(inputs).Merge(opt) if err != nil { query.Iterators(inputs).Close() @@ -169,7 +169,7 @@ func newMergeFinalizerIterator(ctx context.Context, inputs []query.Iterator, opt // to ensure close is eventually called if the iterator is garbage collected. // This additional guard attempts to protect against clients of CreateIterator not // correctly closing them and leaking cursors. -func newFinalizerIterator(itr query.Iterator, log zap.Logger) query.Iterator { +func newFinalizerIterator(itr query.Iterator, log *zap.Logger) query.Iterator { if itr == nil { return nil } diff --git a/tsdb/engine/tsm1/wal.go b/tsdb/engine/tsm1/wal.go index ac6822a3de3..14ae1f41e12 100644 --- a/tsdb/engine/tsm1/wal.go +++ b/tsdb/engine/tsm1/wal.go @@ -21,7 +21,7 @@ import ( "github.com/influxdata/influxdb/models" "github.com/influxdata/influxdb/pkg/limiter" "github.com/influxdata/influxdb/pkg/pool" - "github.com/uber-go/zap" + "go.uber.org/zap" ) const ( @@ -104,8 +104,8 @@ type WAL struct { syncDelay time.Duration // WALOutput is the writer used by the logger. - logger zap.Logger // Logger to be used for important messages - traceLogger zap.Logger // Logger to be used when trace-logging is on. + logger *zap.Logger // Logger to be used for important messages + traceLogger *zap.Logger // Logger to be used when trace-logging is on. traceLogging bool // SegmentSize is the file size at which a segment file will be rotated @@ -118,7 +118,7 @@ type WAL struct { // NewWAL initializes a new WAL at the given directory. func NewWAL(path string) *WAL { - logger := zap.New(zap.NullEncoder()) + logger := zap.NewNop() return &WAL{ path: path, @@ -142,7 +142,7 @@ func (l *WAL) enableTraceLogging(enabled bool) { } // WithLogger sets the WAL's logger. -func (l *WAL) WithLogger(log zap.Logger) { +func (l *WAL) WithLogger(log *zap.Logger) { l.logger = log.With(zap.String("service", "wal")) if l.traceLogging { diff --git a/tsdb/index.go b/tsdb/index.go index c044c7faad3..cdd3fc41985 100644 --- a/tsdb/index.go +++ b/tsdb/index.go @@ -10,13 +10,13 @@ import ( "github.com/influxdata/influxdb/pkg/estimator" "github.com/influxdata/influxdb/query" "github.com/influxdata/influxql" - "github.com/uber-go/zap" + "go.uber.org/zap" ) type Index interface { Open() error Close() error - WithLogger(zap.Logger) + WithLogger(*zap.Logger) MeasurementExists(name []byte) (bool, error) MeasurementNamesByExpr(expr influxql.Expr) ([][]byte, error) diff --git a/tsdb/index/inmem/inmem.go b/tsdb/index/inmem/inmem.go index c4a93a6a289..06cab06f412 100644 --- a/tsdb/index/inmem/inmem.go +++ b/tsdb/index/inmem/inmem.go @@ -27,7 +27,7 @@ import ( "github.com/influxdata/influxdb/query" "github.com/influxdata/influxdb/tsdb" "github.com/influxdata/influxql" - "github.com/uber-go/zap" + "go.uber.org/zap" ) // IndexName is the name of this index. @@ -81,7 +81,7 @@ func (i *Index) Type() string { return IndexName } func (i *Index) Open() (err error) { return nil } func (i *Index) Close() error { return nil } -func (i *Index) WithLogger(zap.Logger) {} +func (i *Index) WithLogger(*zap.Logger) {} // Series returns a series by key. func (i *Index) Series(key []byte) (*Series, error) { diff --git a/tsdb/index/tsi1/index.go b/tsdb/index/tsi1/index.go index 5b10a2b8e23..1c58c302104 100644 --- a/tsdb/index/tsi1/index.go +++ b/tsdb/index/tsi1/index.go @@ -21,7 +21,7 @@ import ( "github.com/influxdata/influxdb/query" "github.com/influxdata/influxdb/tsdb" "github.com/influxdata/influxql" - "github.com/uber-go/zap" + "go.uber.org/zap" ) const ( @@ -100,7 +100,7 @@ type Index struct { CompactionEnabled bool CompactionMonitorInterval time.Duration - logger zap.Logger + logger *zap.Logger // Index's version. version int @@ -115,7 +115,7 @@ func NewIndex() *Index { MaxLogFileSize: DefaultMaxLogFileSize, CompactionEnabled: true, - logger: zap.New(zap.NullEncoder()), + logger: zap.NewNop(), version: Version, } } @@ -324,7 +324,7 @@ func (i *Index) writeManifestFile() error { } // WithLogger sets the logger for the index. -func (i *Index) WithLogger(logger zap.Logger) { +func (i *Index) WithLogger(logger *zap.Logger) { i.logger = logger.With(zap.String("index", "tsi")) } diff --git a/tsdb/shard.go b/tsdb/shard.go index 9821b1b98e1..564e462196f 100644 --- a/tsdb/shard.go +++ b/tsdb/shard.go @@ -23,7 +23,7 @@ import ( "github.com/influxdata/influxdb/query" internal "github.com/influxdata/influxdb/tsdb/internal" "github.com/influxdata/influxql" - "github.com/uber-go/zap" + "go.uber.org/zap" ) // monitorStatInterval is the interval at which the shard is inspected @@ -130,8 +130,8 @@ type Shard struct { stats *ShardStatistics defaultTags models.StatisticTags - baseLogger zap.Logger - logger zap.Logger + baseLogger *zap.Logger + logger *zap.Logger EnableOnOpen bool } @@ -139,7 +139,7 @@ type Shard struct { // NewShard returns a new initialized Shard. walPath doesn't apply to the b1 type index func NewShard(id uint64, path string, walPath string, opt EngineOptions) *Shard { db, rp := decodeStorePath(path) - logger := zap.New(zap.NullEncoder()) + logger := zap.NewNop() s := &Shard{ id: id, @@ -169,7 +169,7 @@ func NewShard(id uint64, path string, walPath string, opt EngineOptions) *Shard } // WithLogger sets the logger on the shard. -func (s *Shard) WithLogger(log zap.Logger) { +func (s *Shard) WithLogger(log *zap.Logger) { s.baseLogger = log engine, err := s.engine() if err == nil { diff --git a/tsdb/store.go b/tsdb/store.go index 179b3a7c716..f9df1460c6d 100644 --- a/tsdb/store.go +++ b/tsdb/store.go @@ -21,7 +21,7 @@ import ( "github.com/influxdata/influxdb/pkg/limiter" "github.com/influxdata/influxdb/query" "github.com/influxdata/influxql" - "github.com/uber-go/zap" + "go.uber.org/zap" ) var ( @@ -53,8 +53,8 @@ type Store struct { EngineOptions EngineOptions - baseLogger zap.Logger - Logger zap.Logger + baseLogger *zap.Logger + Logger *zap.Logger closing chan struct{} wg sync.WaitGroup @@ -64,7 +64,7 @@ type Store struct { // NewStore returns a new store with the given path and a default configuration. // The returned store must be initialized by calling Open before using it. func NewStore(path string) *Store { - logger := zap.New(zap.NullEncoder()) + logger := zap.NewNop() return &Store{ databases: make(map[string]struct{}), path: path, @@ -76,7 +76,7 @@ func NewStore(path string) *Store { } // WithLogger sets the logger for the store. -func (s *Store) WithLogger(log zap.Logger) { +func (s *Store) WithLogger(log *zap.Logger) { s.baseLogger = log s.Logger = log.With(zap.String("service", "store")) for _, sh := range s.shards { diff --git a/tsdb/store_test.go b/tsdb/store_test.go index ba07c9114f1..ff13a44eea6 100644 --- a/tsdb/store_test.go +++ b/tsdb/store_test.go @@ -17,12 +17,12 @@ import ( "time" "github.com/davecgh/go-spew/spew" + "github.com/influxdata/influxdb/logger" "github.com/influxdata/influxdb/models" "github.com/influxdata/influxdb/pkg/deep" "github.com/influxdata/influxdb/query" "github.com/influxdata/influxdb/tsdb" "github.com/influxdata/influxql" - "github.com/uber-go/zap" ) // Ensure the store can delete a retention policy and all shards under @@ -1198,10 +1198,7 @@ func NewStore() *Store { s.EngineOptions.Config.TraceLoggingEnabled = true if testing.Verbose() { - s.WithLogger(zap.New( - zap.NewTextEncoder(), - zap.Output(os.Stdout), - )) + s.WithLogger(logger.New(os.Stdout)) } return s }