From e5c848e845806b9c4c4f25bd12cccb9c5a5e6030 Mon Sep 17 00:00:00 2001 From: Chris Every Date: Wed, 10 Jan 2024 15:57:25 +0000 Subject: [PATCH] Move metric posting to pre-rotation (#921) --- pkg/rotate/rotatekeys.go | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/pkg/rotate/rotatekeys.go b/pkg/rotate/rotatekeys.go index 53fdba12..3f940cb9 100644 --- a/pkg/rotate/rotatekeys.go +++ b/pkg/rotate/rotatekeys.go @@ -112,12 +112,12 @@ func Rotate(account, provider, project string, c config.Config) (err error) { } else if isDatadogKeySet(c.Credentials.Datadog.APIKey) { ddAPIKey = c.Credentials.Datadog.APIKey } - if !c.RotationMode { - if ddAPIKey != "" { - if metricErr := postMetric(providerKeys, ddAPIKey, c.Datadog); metricErr != nil { - logger.Infow("Posting metrics errored", metricErr) - } + if ddAPIKey != "" && c.Datadog != (config.Datadog{}) { + if metricErr := postMetric(providerKeys, ddAPIKey, c.Datadog); metricErr != nil { + logger.Infow("Posting metrics errored", metricErr) } + } + if !c.RotationMode { if c.EnableKeyAgeLogging { obfuscatedKeys := []keys.Key{} for _, key := range providerKeys { @@ -148,17 +148,7 @@ func Rotate(account, provider, project string, c config.Config) (err error) { logger.Infof("Finalised %d keys that are candidates for rotation: %v", len(rc), rcStrings) - if err = rotateKeys(rc, c.Credentials); err != nil { - return - } - if ddAPIKey != "" { - // Refresh key ages post rotation - if providerKeys, err = keysOfProviders(account, provider, project, c); err != nil { - return - } - return postMetric(providerKeys, ddAPIKey, c.Datadog) - } - return + return rotateKeys(rc, c.Credentials) } // rotateKey creates a new key for the rotation candidate, updates its key locations,