Add check for certificate expiration on start
Add recovery from panic when checking for certificate expiration
@@ -110,6 +110,7 @@ func (s *localStoreTlsProvider) initialize() {
if period != 0 {
s.stop = make(chan bool)
s.ticker = time.NewTicker(period)
+ s.checkCertExpiration() // perform initial check to emit metrics and logs right away
go s.timerCallback()
}
}
@@ -358,6 +359,17 @@ func (s *localStoreTlsProvider) timerCallback() {
case <-s.ticker.C:
}
+ s.checkCertExpiration()
+ }
+}
+
+func (s *localStoreTlsProvider) checkCertExpiration() {
+
+ defer func() {
+ var retError error
+ log.CapturePanic(s.logger, &retError)
+ }()
+
var errorTime time.Time
if s.settings.ExpirationChecks.ErrorWindow != 0 {
errorTime = time.Now().UTC().Add(s.settings.ExpirationChecks.ErrorWindow)
@@ -374,7 +386,7 @@ func (s *localStoreTlsProvider) timerCallback() {
expiring, expired, err := s.GetExpiringCerts(window)
if err != nil {
s.logger.Error(fmt.Sprintf("error while checking for certificate expiration: %v", err))
- continue
+ return
}
if s.scope != nil {
s.scope.Gauge(metricCertsExpired).Update(float64(len(expired)))
@@ -384,7 +396,6 @@ func (s *localStoreTlsProvider) timerCallback() {
s.logCerts(expiring, false, errorTime)
}
}
-}
func (s *localStoreTlsProvider) logCerts(certs CertExpirationMap, expired bool, errorTime time.Time) {
