Skip to content

Commit

Permalink
UPSTREAM: <carry>: add audit annotations to track etcd state
Browse files Browse the repository at this point in the history
  • Loading branch information
deads2k committed Jan 14, 2025
1 parent 25a7459 commit bc8ac76
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package etcd3retry

import (
"context"
"k8s.io/apiserver/pkg/audit"
"strings"
"time"

etcdrpc "go.etcd.io/etcd/api/v3/v3rpc/rpctypes"
Expand Down Expand Up @@ -153,6 +155,8 @@ func OnError(ctx context.Context, backoff wait.Backoff, retriable func(error) (s
var retry bool
var retryCounter int
err := backoffWithRequestContext(ctx, backoff, func() (bool, error) {
startTime := time.Now()

err := fn()
if retry {
klog.V(1).Infof("etcd retry - counter: %v, lastErrLabel: %s lastError: %v, error: %v", retryCounter, lastErrLabel, lastErr, err)
Expand All @@ -162,6 +166,12 @@ func OnError(ctx context.Context, backoff wait.Backoff, retriable func(error) (s
return true, nil
}

// add an audit annotation if we hit a no leader condition so we can track this failure in post-processing CI steps.
// We only mark the first time through. Hopefully there's enough traffic that it doesn't matter
if strings.Contains(err.Error(), "no leader") {
audit.AddAuditAnnotation(ctx, "apiserver.internal.openshift.io/no-leader", startTime.Format(time.RFC3339))
}

lastErrLabel, retry = retriable(err)
if retry {
lastErr = err
Expand Down

0 comments on commit bc8ac76

Please sign in to comment.