github.com/influxdata/influxdb/v2@v2.7.6/replications/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 ReplicationService) *loggingService {
    13  	return &loggingService{
    14  		logger:     logger,
    15  		underlying: underlying,
    16  	}
    17  }
    18  
    19  type loggingService struct {
    20  	logger     *zap.Logger
    21  	underlying ReplicationService
    22  }
    23  
    24  var _ ReplicationService = (*loggingService)(nil)
    25  
    26  func (l loggingService) ListReplications(ctx context.Context, filter influxdb.ReplicationListFilter) (rs *influxdb.Replications, 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 replications", zap.Error(err), dur)
    31  			return
    32  		}
    33  		l.logger.Debug("replications find", dur)
    34  	}(time.Now())
    35  	return l.underlying.ListReplications(ctx, filter)
    36  }
    37  
    38  func (l loggingService) CreateReplication(ctx context.Context, request influxdb.CreateReplicationRequest) (r *influxdb.Replication, 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 replication", zap.Error(err), dur)
    43  			return
    44  		}
    45  		l.logger.Debug("replication create", dur)
    46  	}(time.Now())
    47  	return l.underlying.CreateReplication(ctx, request)
    48  }
    49  
    50  func (l loggingService) ValidateNewReplication(ctx context.Context, request influxdb.CreateReplicationRequest) (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 validate replication create", zap.Error(err), dur)
    55  			return
    56  		}
    57  		l.logger.Debug("replication validate create", dur)
    58  	}(time.Now())
    59  	return l.underlying.ValidateNewReplication(ctx, request)
    60  }
    61  
    62  func (l loggingService) GetReplication(ctx context.Context, id platform.ID) (r *influxdb.Replication, 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 find replication by ID", zap.Error(err), dur)
    67  			return
    68  		}
    69  		l.logger.Debug("replication find by ID", dur)
    70  	}(time.Now())
    71  	return l.underlying.GetReplication(ctx, id)
    72  }
    73  
    74  func (l loggingService) UpdateReplication(ctx context.Context, id platform.ID, request influxdb.UpdateReplicationRequest) (r *influxdb.Replication, 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 update replication", zap.Error(err), dur)
    79  			return
    80  		}
    81  		l.logger.Debug("replication update", dur)
    82  	}(time.Now())
    83  	return l.underlying.UpdateReplication(ctx, id, request)
    84  }
    85  
    86  func (l loggingService) ValidateUpdatedReplication(ctx context.Context, id platform.ID, request influxdb.UpdateReplicationRequest) (err error) {
    87  	defer func(start time.Time) {
    88  		dur := zap.Duration("took", time.Since(start))
    89  		if err != nil {
    90  			l.logger.Debug("failed to validate replication update", zap.Error(err), dur)
    91  			return
    92  		}
    93  		l.logger.Debug("replication validate update", dur)
    94  	}(time.Now())
    95  	return l.underlying.ValidateUpdatedReplication(ctx, id, request)
    96  }
    97  
    98  func (l loggingService) DeleteReplication(ctx context.Context, id platform.ID) (err error) {
    99  	defer func(start time.Time) {
   100  		dur := zap.Duration("took", time.Since(start))
   101  		if err != nil {
   102  			l.logger.Debug("failed to delete replication", zap.Error(err), dur)
   103  			return
   104  		}
   105  		l.logger.Debug("replication delete", dur)
   106  	}(time.Now())
   107  	return l.underlying.DeleteReplication(ctx, id)
   108  }
   109  
   110  func (l loggingService) ValidateReplication(ctx context.Context, id platform.ID) (err error) {
   111  	defer func(start time.Time) {
   112  		dur := zap.Duration("took", time.Since(start))
   113  		if err != nil {
   114  			l.logger.Debug("failed to validate replication", zap.Error(err), dur)
   115  			return
   116  		}
   117  		l.logger.Debug("replication validate", dur)
   118  	}(time.Now())
   119  	return l.underlying.ValidateReplication(ctx, id)
   120  }