Skip to content

Commit

Permalink
Move metric posting to pre-rotation (#921)
Browse files Browse the repository at this point in the history
  • Loading branch information
eversC authored Jan 10, 2024
1 parent c787db4 commit e5c848e
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions pkg/rotate/rotatekeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit e5c848e

Please sign in to comment.