Skip to content

Commit

Permalink
remove retries
Browse files Browse the repository at this point in the history
  • Loading branch information
BaptisteFoy committed Oct 22, 2024
1 parent 555cdbe commit 2f7e27f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
6 changes: 3 additions & 3 deletions pkg/fleet/internal/cdn/cdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func New(env *env.Env, configDBPath string) (CDN, error) {
if env.CDNLocalDirPath != "" {
return newLocal(env)
}
if env.CDNEnabled {
return newRemote(env, configDBPath)
if !env.CDNEnabled {
return newDirect(env, configDBPath)
}
return newDirect(env, configDBPath)
return newRegular(env, configDBPath)
}
32 changes: 14 additions & 18 deletions pkg/fleet/internal/cdn/cdn_direct.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ func newDirect(env *env.Env, configDBPath string) (CDN, error) {
}

service, err := remoteconfig.NewService(
pkgconfigsetup.Datadog(), // May not be filled
pkgconfigsetup.Datadog(), // May not be filled as we don't read the config when we're not in the daemon, in which case we'll use the defaults
"Datadog Installer",
fmt.Sprintf("https://config.%s", env.Site),
hostname,
func() []string { return append(ht.get(), "installer:true") }, // Add a tag to identify the installer
&rctelemetryreporterimpl.DdRcTelemetryReporter{}, // No telemetry for this client
ht.get,
&rctelemetryreporterimpl.DdRcTelemetryReporter{}, // No telemetry for this client
version.AgentVersion,
options...,
)
Expand All @@ -83,12 +83,13 @@ func newDirect(env *env.Env, configDBPath string) (CDN, error) {
}

func (c *cdnDirect) Get(ctx context.Context, pkg string) (cfg Config, err error) {
span, _ := tracer.StartSpanFromContext(ctx, "cdn_direct.Get")
span, _ := tracer.StartSpanFromContext(ctx, "cdn.Get")
span.SetTag("cdn_type", "remote_config")
defer func() { span.Finish(tracer.WithError(err)) }()

switch pkg {
case "datadog-agent":
orderConfig, layers, err := c.get(ctx, 0)
orderConfig, layers, err := c.get(ctx)
if err != nil {
return nil, err
}
Expand All @@ -104,16 +105,18 @@ func (c *cdnDirect) Get(ctx context.Context, pkg string) (cfg Config, err error)
}

// get calls the Remote Config service to get the ordered layers.
func (c *cdnDirect) get(ctx context.Context, retry int) (*orderConfig, [][]byte, error) {
func (c *cdnDirect) get(ctx context.Context) (*orderConfig, [][]byte, error) {
agentConfigUpdate, err := c.rcService.ClientGetConfigs(ctx, &pbgo.ClientGetConfigsRequest{
Client: &pbgo.Client{
Id: c.clientUUID,
Products: []string{"AGENT_CONFIG"},
IsUpdater: true,
ClientUpdater: &pbgo.ClientUpdater{},
Id: c.clientUUID,
Products: []string{"AGENT_CONFIG"},
IsUpdater: true,
ClientUpdater: &pbgo.ClientUpdater{
Tags: []string{"installer:true"},
},
State: &pbgo.ClientState{
RootVersion: c.currentRootsVersion,
TargetsVersion: 1,
TargetsVersion: 0,
},
},
})
Expand Down Expand Up @@ -168,13 +171,6 @@ func (c *cdnDirect) get(ctx context.Context, retry int) (*orderConfig, [][]byte,
if layersErr != nil {
return nil, nil, layersErr
}

if configOrder == nil && retry < 10 {
// Retry for up to 10 seconds to get the order config
time.Sleep(1 * time.Second)
return c.get(ctx, retry+1)

}
return configOrder, configLayers, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import (
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)

type cdnRemote struct {
type cdnRegular struct {
client *remoteconfig.HTTPClient
currentRootsVersion uint64
}

func newRemote(env *env.Env, configDBPath string) (CDN, error) {
func newRegular(env *env.Env, configDBPath string) (CDN, error) {
client, err := remoteconfig.NewHTTPClient(
configDBPath,
env.Site,
Expand All @@ -35,15 +35,16 @@ func newRemote(env *env.Env, configDBPath string) (CDN, error) {
if err != nil {
return nil, err
}
return &cdnRemote{
return &cdnRegular{
client: client,
currentRootsVersion: 1,
}, nil
}

// Get gets the configuration from the CDN.
func (c *cdnRemote) Get(ctx context.Context, pkg string) (cfg Config, err error) {
span, _ := tracer.StartSpanFromContext(ctx, "cdn_remote.Get")
func (c *cdnRegular) Get(ctx context.Context, pkg string) (cfg Config, err error) {
span, _ := tracer.StartSpanFromContext(ctx, "cdn.Get")
span.SetTag("cdn_type", "cdn")
defer func() { span.Finish(tracer.WithError(err)) }()

switch pkg {
Expand All @@ -64,12 +65,12 @@ func (c *cdnRemote) Get(ctx context.Context, pkg string) (cfg Config, err error)
}

// Close cleans up the CDN's resources
func (c *cdnRemote) Close() error {
func (c *cdnRegular) Close() error {
return c.client.Close()
}

// get calls the Remote Config service to get the ordered layers.
func (c *cdnRemote) get(ctx context.Context) (*orderConfig, [][]byte, error) {
func (c *cdnRegular) get(ctx context.Context) (*orderConfig, [][]byte, error) {
agentConfigUpdate, err := c.client.GetCDNConfigUpdate(
ctx,
[]string{"AGENT_CONFIG"},
Expand Down

0 comments on commit 2f7e27f

Please sign in to comment.