Skip to content

Commit e5c848e

Browse files
authored
Move metric posting to pre-rotation (#921)
1 parent c787db4 commit e5c848e

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

pkg/rotate/rotatekeys.go

+6-16
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ func Rotate(account, provider, project string, c config.Config) (err error) {
112112
} else if isDatadogKeySet(c.Credentials.Datadog.APIKey) {
113113
ddAPIKey = c.Credentials.Datadog.APIKey
114114
}
115-
if !c.RotationMode {
116-
if ddAPIKey != "" {
117-
if metricErr := postMetric(providerKeys, ddAPIKey, c.Datadog); metricErr != nil {
118-
logger.Infow("Posting metrics errored", metricErr)
119-
}
115+
if ddAPIKey != "" && c.Datadog != (config.Datadog{}) {
116+
if metricErr := postMetric(providerKeys, ddAPIKey, c.Datadog); metricErr != nil {
117+
logger.Infow("Posting metrics errored", metricErr)
120118
}
119+
}
120+
if !c.RotationMode {
121121
if c.EnableKeyAgeLogging {
122122
obfuscatedKeys := []keys.Key{}
123123
for _, key := range providerKeys {
@@ -148,17 +148,7 @@ func Rotate(account, provider, project string, c config.Config) (err error) {
148148
logger.Infof("Finalised %d keys that are candidates for rotation: %v",
149149
len(rc), rcStrings)
150150

151-
if err = rotateKeys(rc, c.Credentials); err != nil {
152-
return
153-
}
154-
if ddAPIKey != "" {
155-
// Refresh key ages post rotation
156-
if providerKeys, err = keysOfProviders(account, provider, project, c); err != nil {
157-
return
158-
}
159-
return postMetric(providerKeys, ddAPIKey, c.Datadog)
160-
}
161-
return
151+
return rotateKeys(rc, c.Credentials)
162152
}
163153

164154
// rotateKey creates a new key for the rotation candidate, updates its key locations,

0 commit comments

Comments
 (0)