github.com/influxdata/influxdb/v2@v2.7.6/remotes/transport/middleware_logging.go (about)

     1  package transport
     2  
     3  import (
     4  	"context"
     5  	"time"
     6  
     7  	"github.com/influxdata/influxdb/v2"
     8  	"github.com/influxdata/influxdb/v2/kit/platform"
     9  	"go.uber.org/zap"
    10  )
    11  
    12  func newLoggingService(logger *zap.Logger, underlying RemoteConnectionService) *loggingService {
    13  	return &loggingService{
    14  		logger:     logger,
    15  		underlying: underlying,
    16  	}
    17  }
    18  
    19  type loggingService struct {
    20  	logger     *zap.Logger
    21  	underlying RemoteConnectionService
    22  }
    23  
    24  var _ RemoteConnectionService = (*loggingService)(nil)
    25  
    26  func (l loggingService) ListRemoteConnections(ctx context.Context, filter influxdb.RemoteConnectionListFilter) (cs *influxdb.RemoteConnections, err error) {
    27  	defer func(start time.Time) {
    28  		dur := zap.Duration("took", time.Since(start))
    29  		if err != nil {
    30  			l.logger.Debug("failed to find remotes", zap.Error(err), dur)
    31  			return
    32  		}
    33  		l.logger.Debug("remotes find", dur)
    34  	}(time.Now())
    35  	return l.underlying.ListRemoteConnections(ctx, filter)
    36  }
    37  
    38  func (l loggingService) CreateRemoteConnection(ctx context.Context, request influxdb.CreateRemoteConnectionRequest) (r *influxdb.RemoteConnection, err error) {
    39  	defer func(start time.Time) {
    40  		dur := zap.Duration("took", time.Since(start))
    41  		if err != nil {
    42  			l.logger.Debug("failed to create remote", zap.Error(err), dur)
    43  			return
    44  		}
    45  		l.logger.Debug("remote create", dur)
    46  	}(time.Now())
    47  	return l.underlying.CreateRemoteConnection(ctx, request)
    48  }
    49  
    50  func (l loggingService) GetRemoteConnection(ctx context.Context, id platform.ID) (r *influxdb.RemoteConnection, err error) {
    51  	defer func(start time.Time) {
    52  		dur := zap.Duration("took", time.Since(start))
    53  		if err != nil {
    54  			l.logger.Debug("failed to find remote by ID", zap.Error(err), dur)
    55  			return
    56  		}
    57  		l.logger.Debug("remote find by ID", dur)
    58  	}(time.Now())
    59  	return l.underlying.GetRemoteConnection(ctx, id)
    60  }
    61  
    62  func (l loggingService) UpdateRemoteConnection(ctx context.Context, id platform.ID, request influxdb.UpdateRemoteConnectionRequest) (r *influxdb.RemoteConnection, err error) {
    63  	defer func(start time.Time) {
    64  		dur := zap.Duration("took", time.Since(start))
    65  		if err != nil {
    66  			l.logger.Debug("failed to update remote", zap.Error(err), dur)
    67  			return
    68  		}
    69  		l.logger.Debug("remote update", dur)
    70  	}(time.Now())
    71  	return l.underlying.UpdateRemoteConnection(ctx, id, request)
    72  }
    73  
    74  func (l loggingService) DeleteRemoteConnection(ctx context.Context, id platform.ID) (err error) {
    75  	defer func(start time.Time) {
    76  		dur := zap.Duration("took", time.Since(start))
    77  		if err != nil {
    78  			l.logger.Debug("failed to delete remote", zap.Error(err), dur)
    79  			return
    80  		}
    81  		l.logger.Debug("remote delete", dur)
    82  	}(time.Now())
    83  	return l.underlying.DeleteRemoteConnection(ctx, id)
    84  }