Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add retry when getting the datadog agent in the rc updater #1412

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion pkg/remoteconfig/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"strings"
"time"

"github.com/cenkalti/backoff"
"github.com/go-logr/logr"
"github.com/google/uuid"
apiequality "k8s.io/apimachinery/pkg/api/equality"
Expand Down Expand Up @@ -241,7 +242,7 @@ func (r *RemoteConfigUpdater) agentConfigUpdateCallback(updates map[string]state
r.logger.Info("Merged", "update", mergedUpdate)
}

dda, err := r.getDatadogAgentInstance(ctx)
dda, err := r.getDatadogAgentWithRetry(ctx)
if err != nil {
r.logger.Error(err, "Failed to get updatable agents")
return
Expand Down Expand Up @@ -394,6 +395,34 @@ func (r *RemoteConfigUpdater) getDatadogAgentInstance(ctx context.Context) (v2al
return ddaList.Items[0], nil
}

func (r *RemoteConfigUpdater) getDatadogAgentWithRetry(ctx context.Context) (v2alpha1.DatadogAgent, error) {
var dda v2alpha1.DatadogAgent
var err error

operation := func() error {
dda, err = r.getDatadogAgentInstance(ctx)
if err != nil {
r.logger.Error(err, "Failed to get updatable agents, retrying...")
return err
}
return nil
}

// Create a backoff strategy
expBackoff := backoff.NewExponentialBackOff()
expBackoff.InitialInterval = 1 * time.Second
expBackoff.MaxInterval = 10 * time.Second
expBackoff.MaxElapsedTime = 3 * time.Minute

err = backoff.Retry(operation, expBackoff)
if err != nil {
r.logger.Error(err, "Failed to get updatable agents after retries")
return dda, err
}

return dda, nil
}

func (r *RemoteConfigUpdater) updateInstanceStatus(dda v2alpha1.DatadogAgent, cfg DatadogAgentRemoteConfig) error {

newddaStatus := dda.Status.DeepCopy()
Expand Down
Loading