github.com/openshift/installer@v1.4.17/pkg/destroy/gcp/errortracker.go (about) 1 package gcp 2 3 import ( 4 "time" 5 6 "github.com/sirupsen/logrus" 7 ) 8 9 const ( 10 suppressDuration = time.Minute * 5 11 ) 12 13 // errorTracker holds a history of errors 14 type errorTracker struct { 15 history map[string]time.Time 16 } 17 18 // suppressWarning logs errors WARN once every duration and the rest to DEBUG 19 func (o *errorTracker) suppressWarning(identifier string, err error, logger logrus.FieldLogger) { 20 if o.history == nil { 21 o.history = map[string]time.Time{} 22 } 23 if firstSeen, ok := o.history[identifier]; ok { 24 if time.Since(firstSeen) > suppressDuration { 25 logger.Warn(err) 26 o.history[identifier] = time.Now() // reset the clock 27 } else { 28 logger.Debug(err) 29 } 30 } else { // first error for this identifier 31 o.history[identifier] = time.Now() 32 logger.Debug(err) 33 } 34 }