reports stats on shutdown

This commit is contained in:
Alex Grintsvayg 2018-09-04 11:08:34 -04:00
parent cb386de4c7
commit 59e92ccf88
2 changed files with 9 additions and 3 deletions

View file

@ -54,6 +54,9 @@ func NewServer(store store.BlobStore) *Server {
// Shutdown shuts down the reflector server gracefully. // Shutdown shuts down the reflector server gracefully.
func (s *Server) Shutdown() { func (s *Server) Shutdown() {
log.Println("shutting down reflector server...") log.Println("shutting down reflector server...")
if s.isReportStats() {
s.stats.Shutdown()
}
s.grp.StopAndWait() s.grp.StopAndWait()
log.Println("reflector server stopped") 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()) s.stats = newStatLogger(s.StatLogger, s.StatReportFrequency, s.grp.Child())
if s.StatLogger != nil && s.StatReportFrequency > 0 { if s.isReportStats() {
s.stats.Start() 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 { func BlobHash(blob []byte) string {
hashBytes := sha512.Sum384(blob) hashBytes := sha512.Sum384(blob)
return hex.EncodeToString(hashBytes[:]) return hex.EncodeToString(hashBytes[:])

View file

@ -12,8 +12,6 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
// TODO: send stats on shutdown
// TODO: store daily stats too. and maybe other intervals // TODO: store daily stats too. and maybe other intervals
type stats struct { type stats struct {
@ -46,6 +44,7 @@ func (s *stats) Start() {
} }
func (s *stats) Shutdown() { func (s *stats) Shutdown() {
s.log()
s.grp.StopAndWait() s.grp.StopAndWait()
} }