Skip to content

Commit

Permalink
Fix secrets-encrypt metrics
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Nola <[email protected]>
  • Loading branch information
dereknola committed Aug 21, 2024
1 parent 2f80c78 commit de6410b
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions pkg/secretsencrypt/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func WaitForEncryptionConfigReload(runtime *config.ControlRuntime, reloadSuccess
return true, err
}

if newReloadSuccess <= reloadSuccesses || newReloadTime <= reloadTime {
if newReloadTime <= reloadTime {
lastFailure = fmt.Sprintf("apiserver has not reloaded encryption configuration (reload success: %d/%d, reload timestamp %d/%d)", newReloadSuccess, reloadSuccesses, newReloadTime, reloadTime)
return false, nil
}
Expand Down Expand Up @@ -253,10 +253,11 @@ func GetEncryptionConfigMetrics(runtime *config.ControlRuntime, initialMetrics b
return true, err
}
tsMetric := mf["apiserver_encryption_config_controller_automatic_reload_last_timestamp_seconds"]
successMetric := mf["apiserver_encryption_config_controller_automatic_reload_success_total"]
// Potentially multiple metrics with different success/failure labels
totalMetrics := mf["apiserver_encryption_config_controller_automatic_reloads_total"]

// First time, no metrics exist, so return zeros
if tsMetric == nil && successMetric == nil && initialMetrics {
if tsMetric == nil && totalMetrics == nil && initialMetrics {
return true, nil
}

Expand All @@ -265,8 +266,8 @@ func GetEncryptionConfigMetrics(runtime *config.ControlRuntime, initialMetrics b
return false, nil
}

if successMetric == nil {
lastFailure = "encryption config success metric not found"
if totalMetrics == nil {
lastFailure = "encryption config total metric not found"
return false, nil
}

Expand All @@ -275,8 +276,14 @@ func GetEncryptionConfigMetrics(runtime *config.ControlRuntime, initialMetrics b
return true, fmt.Errorf("encryption reload time is incorrectly ahead of current time")
}

reloadSuccessCounter = int64(successMetric.GetMetric()[0].GetCounter().GetValue())

for _, totalMetric := range totalMetrics.GetMetric() {
logrus.Debugf("totalMetric: %+v", totalMetric)
for _, label := range totalMetric.GetLabel() {
if label.GetValue() == "success" {
reloadSuccessCounter = int64(totalMetric.GetCounter().GetValue())
}
}
}
return true, nil
})

Expand Down

0 comments on commit de6410b

Please sign in to comment.