Skip to content

Commit

Permalink
chore: Remove several instances of WithLogger (influxdata#15996)
Browse files Browse the repository at this point in the history
* chore: Remove several instances of WithLogger

* chore: unexport Logger fields

* chore: unexport some more Logger fields

* chore: go fmt

chore: fix test

chore: s/logger/log

chore: fix test

chore: revert http.Handler.Handler constructor initialization

* refactor: integrate review feedback, fix all test nop loggers

* refactor: capitalize all log messages

* refactor: rename two logger to log
  • Loading branch information
Jacob Marble authored Dec 4, 2019
1 parent 27e2531 commit 5f19c6c
Show file tree
Hide file tree
Showing 174 changed files with 1,331 additions and 1,336 deletions.
12 changes: 6 additions & 6 deletions authorizer/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ var (

type taskServiceValidator struct {
influxdb.TaskService
logger *zap.Logger
log *zap.Logger
}

// TaskService wraps ts and checks appropriate permissions before calling requested methods on ts.
// Authorization failures are logged to the logger.
func NewTaskService(logger *zap.Logger, ts influxdb.TaskService) influxdb.TaskService {
func NewTaskService(log *zap.Logger, ts influxdb.TaskService) influxdb.TaskService {
return &taskServiceValidator{
TaskService: ts,
logger: logger,
log: log,
}
}

Expand Down Expand Up @@ -79,7 +79,7 @@ func (ts *taskServiceValidator) FindTasks(ctx context.Context, filter influxdb.T
// We are getting a list of tasks that may be a superset of what the user is allowed to view.
auth, err := platcontext.GetAuthorizer(ctx)
if err != nil {
ts.logger.Info("Failed to retrieve authorizer from context", zap.String("method", "FindTasks"))
ts.log.Info("Failed to retrieve authorizer from context", zap.String("method", "FindTasks"))
return nil, 0, err
}

Expand Down Expand Up @@ -322,12 +322,12 @@ func (ts *taskServiceValidator) ForceRun(ctx context.Context, taskID influxdb.ID
func (ts *taskServiceValidator) validatePermission(ctx context.Context, perm influxdb.Permission, loggerFields ...zap.Field) error {
auth, err := platcontext.GetAuthorizer(ctx)
if err != nil {
ts.logger.With(loggerFields...).Info("Failed to retrieve authorizer from context")
ts.log.With(loggerFields...).Info("Failed to retrieve authorizer from context")
return err
}

if !auth.Allowed(perm) {
ts.logger.With(loggerFields...).Info("Authorization failed",
ts.log.With(loggerFields...).Info("Authorization failed",
zap.String("user_id", auth.GetUserID().String()),
zap.String("auth_kind", auth.Kind()),
zap.String("auth_id", auth.Identifier().String()),
Expand Down
2 changes: 1 addition & 1 deletion bolt/authorization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func initAuthorizationService(f platformtesting.AuthorizationFields, t *testing.T) (platform.AuthorizationService, string, func()) {
c, closeFn, err := NewTestClient()
c, closeFn, err := NewTestClient(t)
if err != nil {
t.Fatalf("failed to create new bolt client: %v", err)
}
Expand Down
18 changes: 6 additions & 12 deletions bolt/bbolt.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ func getOp(op string) string {

// Client is a client for the boltDB data store.
type Client struct {
Path string
db *bolt.DB
Logger *zap.Logger
Path string
db *bolt.DB
log *zap.Logger

IDGenerator platform.IDGenerator
TokenGenerator platform.TokenGenerator
platform.TimeGenerator
}

// NewClient returns an instance of a Client.
func NewClient() *Client {
func NewClient(log *zap.Logger) *Client {
return &Client{
Logger: zap.NewNop(),
log: log,
IDGenerator: snowflake.NewIDGenerator(),
TokenGenerator: rand.NewTokenGenerator(64),
TimeGenerator: platform.RealTimeGenerator{},
Expand All @@ -47,12 +47,6 @@ func (c *Client) DB() *bolt.DB {
return c.db
}

// WithLogger sets the logger an a client. It should not be called after
// the client has been open.
func (c *Client) WithLogger(l *zap.Logger) {
c.Logger = l
}

// Open / create boltDB file.
func (c *Client) Open(ctx context.Context) error {
// Ensure the required directory structure exists.
Expand All @@ -75,7 +69,7 @@ func (c *Client) Open(ctx context.Context) error {
return err
}

c.Logger.Info("Resources opened", zap.String("path", c.Path))
c.log.Info("Resources opened", zap.String("path", c.Path))
return nil
}

Expand Down
15 changes: 8 additions & 7 deletions bolt/bbolt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ import (
"testing"

"github.com/influxdata/influxdb/bolt"
"go.uber.org/zap/zaptest"
"golang.org/x/crypto/bcrypt"
)

func init() {
bolt.HashCost = bcrypt.MinCost
}

func NewTestClient() (*bolt.Client, func(), error) {
c, closeFn, err := newTestClient()
func NewTestClient(t *testing.T) (*bolt.Client, func(), error) {
c, closeFn, err := newTestClient(t)
if err != nil {
return nil, nil, err
}
Expand All @@ -28,8 +29,8 @@ func NewTestClient() (*bolt.Client, func(), error) {
return c, closeFn, nil
}

func newTestClient() (*bolt.Client, func(), error) {
c := bolt.NewClient()
func newTestClient(t *testing.T) (*bolt.Client, func(), error) {
c := bolt.NewClient(zaptest.NewLogger(t))

f, err := ioutil.TempFile("", "influxdata-platform-bolt-")
if err != nil {
Expand Down Expand Up @@ -61,7 +62,7 @@ func TestClientOpen(t *testing.T) {

boltFile := filepath.Join(tempDir, "test", "bolt.db")

c := bolt.NewClient()
c := bolt.NewClient(zaptest.NewLogger(t))
c.Path = boltFile

if err := c.Open(context.Background()); err != nil {
Expand All @@ -73,15 +74,15 @@ func TestClientOpen(t *testing.T) {
}
}

func NewTestKVStore() (*bolt.KVStore, func(), error) {
func NewTestKVStore(t *testing.T) (*bolt.KVStore, func(), error) {
f, err := ioutil.TempFile("", "influxdata-platform-bolt-")
if err != nil {
return nil, nil, errors.New("unable to open temporary boltdb file")
}
f.Close()

path := f.Name()
s := bolt.NewKVStore(path)
s := bolt.NewKVStore(zaptest.NewLogger(t), path)
if err := s.Open(context.TODO()); err != nil {
return nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion bolt/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func initBucketService(f platformtesting.BucketFields, t *testing.T) (platform.BucketService, string, func()) {
c, closeFn, err := NewTestClient()
c, closeFn, err := NewTestClient(t)
if err != nil {
t.Fatalf("failed to create new bolt client: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion bolt/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func initDashboardService(f platformtesting.DashboardFields, t *testing.T) (platform.DashboardService, string, func()) {
c, closeFn, err := NewTestClient()
c, closeFn, err := NewTestClient(t)
if err != nil {
t.Fatalf("failed to create new bolt client: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion bolt/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (c *Client) ID() platform.ID {
})

if err != nil {
c.Logger.Error("unable to load id", zap.Error(err))
c.log.Error("Unable to load id", zap.Error(err))
}

return id
Expand Down
2 changes: 1 addition & 1 deletion bolt/id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func TestID(t *testing.T) {
c, closeFn, err := newTestClient()
c, closeFn, err := newTestClient(t)
if err != nil {
t.Fatalf("failed to create new bolt client: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion bolt/keyvalue_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func initKeyValueLog(f platformtesting.KeyValueLogFields, t *testing.T) (platform.KeyValueLog, func()) {
c, closeFn, err := NewTestClient()
c, closeFn, err := NewTestClient(t)
if err != nil {
t.Fatalf("failed to create new bolt client: %v", err)
}
Expand Down
19 changes: 7 additions & 12 deletions bolt/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ import (

// KVStore is a kv.Store backed by boltdb.
type KVStore struct {
path string
db *bolt.DB
logger *zap.Logger
path string
db *bolt.DB
log *zap.Logger
}

// NewKVStore returns an instance of KVStore with the file at
// the provided path.
func NewKVStore(path string) *KVStore {
func NewKVStore(log *zap.Logger, path string) *KVStore {
return &KVStore{
path: path,
logger: zap.NewNop(),
path: path,
log: log,
}
}

Expand All @@ -50,7 +50,7 @@ func (s *KVStore) Open(ctx context.Context) error {
}
s.db = db

s.logger.Info("Resources opened", zap.String("path", s.path))
s.log.Info("Resources opened", zap.String("path", s.path))
return nil
}

Expand Down Expand Up @@ -89,11 +89,6 @@ func (s *KVStore) cleanBucket(tx *bolt.Tx, b *bolt.Bucket) {
}
}

// WithLogger sets the logger on the store.
func (s *KVStore) WithLogger(l *zap.Logger) {
s.logger = l
}

// WithDB sets the boltdb on the store.
func (s *KVStore) WithDB(db *bolt.DB) {
s.db = db
Expand Down
2 changes: 1 addition & 1 deletion bolt/kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func initKVStore(f platformtesting.KVStoreFields, t *testing.T) (kv.Store, func()) {
s, closeFn, err := NewTestKVStore()
s, closeFn, err := NewTestKVStore(t)
if err != nil {
t.Fatalf("failed to create new kv store: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion bolt/lookup_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func TestClient_Name(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c, done, err := NewTestClient()
c, done, err := NewTestClient(t)
if err != nil {
t.Fatalf("unable to create bolt test client: %v", err)
}
Expand Down
9 changes: 5 additions & 4 deletions bolt/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ import (
platform "github.com/influxdata/influxdb"
"github.com/influxdata/influxdb/kit/prom"
"github.com/influxdata/influxdb/kit/prom/promtest"
"go.uber.org/zap/zaptest"
)

func TestInitialMetrics(t *testing.T) {
client, teardown, err := NewTestClient()
client, teardown, err := NewTestClient(t)
if err != nil {
t.Fatalf("unable to setup bolt client: %v", err)
}
defer teardown()

reg := prom.NewRegistry()
reg := prom.NewRegistry(zaptest.NewLogger(t))
reg.MustRegister(client)

mfs, err := reg.Gather()
Expand All @@ -41,13 +42,13 @@ func TestInitialMetrics(t *testing.T) {
}

func TestMetrics_Onboarding(t *testing.T) {
client, teardown, err := NewTestClient()
client, teardown, err := NewTestClient(t)
if err != nil {
t.Fatalf("unable to setup bolt client: %v", err)
}
defer teardown()

reg := prom.NewRegistry()
reg := prom.NewRegistry(zaptest.NewLogger(t))
reg.MustRegister(client)

ctx := context.Background()
Expand Down
2 changes: 1 addition & 1 deletion bolt/onboarding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func initOnboardingService(f platformtesting.OnboardingFields, t *testing.T) (platform.OnboardingService, func()) {
c, closeFn, err := NewTestClient()
c, closeFn, err := NewTestClient(t)
if err != nil {
t.Fatalf("failed to create new bolt client: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion bolt/organization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func initOrganizationService(f platformtesting.OrganizationFields, t *testing.T) (platform.OrganizationService, string, func()) {
c, closeFn, err := NewTestClient()
c, closeFn, err := NewTestClient(t)
if err != nil {
t.Fatalf("failed to create new bolt client: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion bolt/passwords_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func initPasswordsService(f platformtesting.PasswordFields, t *testing.T) (platform.PasswordsService, func()) {
c, closeFn, err := NewTestClient()
c, closeFn, err := NewTestClient(t)
if err != nil {
t.Fatalf("failed to create new bolt client: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion bolt/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func initScraperTargetStoreService(f platformtesting.TargetFields, t *testing.T) (platform.ScraperTargetStoreService, string, func()) {
c, closeFn, err := NewTestClient()
c, closeFn, err := NewTestClient(t)
if err != nil {
t.Fatalf("failed to create new bolt client: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion bolt/secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func initSecretService(f platformtesting.SecretServiceFields, t *testing.T) (platform.SecretService, func()) {
c, closeFn, err := NewTestClient()
c, closeFn, err := NewTestClient(t)
if err != nil {
t.Fatalf("failed to create new bolt client: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion bolt/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func initSessionService(f platformtesting.SessionFields, t *testing.T) (platform.SessionService, string, func()) {
c, closeFn, err := NewTestClient()
c, closeFn, err := NewTestClient(t)
if err != nil {
t.Fatalf("failed to create new bolt client: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion bolt/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func initSourceService(f platformtesting.SourceFields, t *testing.T) (platform.SourceService, string, func()) {
c, closeFn, err := NewTestClient()
c, closeFn, err := NewTestClient(t)
if err != nil {
t.Fatalf("failed to create new bolt client: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion bolt/telegraf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func initTelegrafConfigStore(f platformtesting.TelegrafConfigFields, t *testing.T) (platform.TelegrafConfigStore, func()) {
c, closeFn, err := NewTestClient()
c, closeFn, err := NewTestClient(t)
if err != nil {
t.Fatalf("failed to create new bolt client: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion bolt/user_resource_mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func initUserResourceMappingService(f platformtesting.UserResourceFields, t *testing.T) (platform.UserResourceMappingService, func()) {
c, closeFn, err := NewTestClient()
c, closeFn, err := NewTestClient(t)
if err != nil {
t.Fatalf("failed to create new bolt client: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion bolt/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func initUserService(f influxdbtesting.UserFields, t *testing.T) (influxdb.UserService, string, func()) {
svc, closeFn, err := NewTestClient()
svc, closeFn, err := NewTestClient(t)
if err != nil {
t.Fatalf("failed to create new kv store: %v", err)
}
Expand Down
Loading

0 comments on commit 5f19c6c

Please sign in to comment.