Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
arnikola committed Nov 2, 2021
1 parent 4b95340 commit ab6289d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
13 changes: 8 additions & 5 deletions src/aggregator/aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,17 +394,19 @@ func (agg *aggregator) Close() error {
agg.state = aggregatorClosed

var (
lastOpCompleted = time.Now()
currTime time.Time
lastOpCompleted = time.Now()
currTime time.Time
closeLogger = agg.logger.With(zap.String("closing", "aggregator"))

logCloseOperation = func(op string) {
currTime = time.Now()
agg.logger.Info(fmt.Sprintf("!!! closed %s", op),
closeLogger.Info(fmt.Sprintf("closed %s", op),
zap.String("took", currTime.Sub(lastOpCompleted).String()))
lastOpCompleted = currTime
}
)

agg.logger.Info("signalling aggregator done")
closeLogger.Info("signaling aggregator done")
close(agg.doneCh)

// Waiting for the ticking goroutines to return.
Expand Down Expand Up @@ -432,11 +434,12 @@ func (agg *aggregator) Close() error {
logCloseOperation("passthrough writer")

if agg.adminClient != nil {
agg.logger.Info("closing admin client")
closeLogger.Info("closing admin client")
agg.adminClient.Close()
logCloseOperation("admin client")
}

closeLogger.Info("done")
return nil
}

Expand Down
1 change: 0 additions & 1 deletion src/aggregator/aggregator/map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,6 @@ func TestMetricMapTickCancellation(t *testing.T) {
doneCh := make(chan struct{})
go func() {
<-tickedCh
fmt.Println("closing ch")
close(doneCh)
}()

Expand Down
28 changes: 16 additions & 12 deletions src/cmd/services/m3aggregator/serve/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,21 @@ func Serve(
doneCh chan struct{},
opts Options,
) error {
iOpts := opts.InstrumentOpts()
log := iOpts.Logger()
var (
iOpts = opts.InstrumentOpts()
log = iOpts.Logger()
closeLogger = log.With(zap.String("closing", "aggregator_server"))
)

defer func() {
start := time.Now()
log.Info("!! closing aggregator")
closeLogger.Info("closing aggregator")
err := aggregator.Close()
fields := []zap.Field{zap.String("took", time.Since(start).String())}
if err != nil {
log.Warn("closed aggregator with error", append(fields, zap.Error(err))...)
closeLogger.Warn("closed aggregator with error", append(fields, zap.Error(err))...)
} else {
log.Info("!! closed aggregator", fields...)
closeLogger.Info("closed aggregator", fields...)
}
}()

Expand All @@ -65,9 +69,9 @@ func Serve(

defer func() {
start := time.Now()
log.Info("!! closing m3msg server")
closeLogger.Info("closing m3msg server")
m3msgServer.Close()
log.Info("m3msg server closed", zap.String("took", time.Since(start).String()))
closeLogger.Info("m3msg server closed", zap.String("took", time.Since(start).String()))
}()

log.Info("m3msg server listening", zap.String("addr", m3msgAddr))
Expand All @@ -82,9 +86,9 @@ func Serve(

defer func() {
start := time.Now()
log.Info("!! closing raw TCPServer")
closeLogger.Info("closing raw TCPServer")
rawTCPServer.Close()
log.Info("!! closed raw TCPServer", zap.String("took", time.Since(start).String()))
closeLogger.Info("closed raw TCPServer", zap.String("took", time.Since(start).String()))
}()

log.Info("raw TCP server listening", zap.String("addr", rawTCPAddr))
Expand All @@ -100,17 +104,17 @@ func Serve(

defer func() {
start := time.Now()
log.Info("!! closing http server")
closeLogger.Info("closing http server")
httpServer.Close()
log.Info("!! closed http server", zap.String("took", time.Since(start).String()))
closeLogger.Info("closed http server", zap.String("took", time.Since(start).String()))
}()

log.Info("http server listening", zap.String("addr", httpAddr))
}

// Wait for exit signal.
<-doneCh
log.Info("!! server signalled on doneCh")
closeLogger.Info("server signaled on doneCh")

return nil
}

0 comments on commit ab6289d

Please sign in to comment.