From 59e92ccf8803b250bb857b4e340707f3d5376ecc Mon Sep 17 00:00:00 2001 From: Alex Grintsvayg Date: Tue, 4 Sep 2018 11:08:34 -0400 Subject: [PATCH] reports stats on shutdown --- reflector/server.go | 9 ++++++++- reflector/stats.go | 3 +-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/reflector/server.go b/reflector/server.go index 565b535..d9ada28 100644 --- a/reflector/server.go +++ b/reflector/server.go @@ -54,6 +54,9 @@ func NewServer(store store.BlobStore) *Server { // Shutdown shuts down the reflector server gracefully. func (s *Server) Shutdown() { log.Println("shutting down reflector server...") + if s.isReportStats() { + s.stats.Shutdown() + } s.grp.StopAndWait() log.Println("reflector server stopped") } @@ -83,7 +86,7 @@ func (s *Server) Start(address string) error { }() s.stats = newStatLogger(s.StatLogger, s.StatReportFrequency, s.grp.Child()) - if s.StatLogger != nil && s.StatReportFrequency > 0 { + if s.isReportStats() { s.stats.Start() } @@ -367,6 +370,10 @@ func (s *Server) quitting() bool { } } +func (s *Server) isReportStats() bool { + return s.StatLogger != nil && s.StatReportFrequency > 0 +} + func BlobHash(blob []byte) string { hashBytes := sha512.Sum384(blob) return hex.EncodeToString(hashBytes[:]) diff --git a/reflector/stats.go b/reflector/stats.go index c0f9b57..10cfce4 100644 --- a/reflector/stats.go +++ b/reflector/stats.go @@ -12,8 +12,6 @@ import ( log "github.com/sirupsen/logrus" ) -// TODO: send stats on shutdown - // TODO: store daily stats too. and maybe other intervals type stats struct { @@ -46,6 +44,7 @@ func (s *stats) Start() { } func (s *stats) Shutdown() { + s.log() s.grp.StopAndWait() }