diff --git a/pkg/fleet/internal/cdn/cdn.go b/pkg/fleet/internal/cdn/cdn.go index fd4fe16bfb0f4c..03cde9ef4024ed 100644 --- a/pkg/fleet/internal/cdn/cdn.go +++ b/pkg/fleet/internal/cdn/cdn.go @@ -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) } diff --git a/pkg/fleet/internal/cdn/cdn_direct.go b/pkg/fleet/internal/cdn/cdn_direct.go index 7e25016d67d03d..322ed763267f37 100644 --- a/pkg/fleet/internal/cdn/cdn_direct.go +++ b/pkg/fleet/internal/cdn/cdn_direct.go @@ -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..., ) @@ -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 } @@ -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, }, }, }) @@ -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 } diff --git a/pkg/fleet/internal/cdn/cdn_remote.go b/pkg/fleet/internal/cdn/cdn_regular.go similarity index 89% rename from pkg/fleet/internal/cdn/cdn_remote.go rename to pkg/fleet/internal/cdn/cdn_regular.go index d8ee929d0df2dd..bd7deec882cbf8 100644 --- a/pkg/fleet/internal/cdn/cdn_remote.go +++ b/pkg/fleet/internal/cdn/cdn_regular.go @@ -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, @@ -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 { @@ -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"},