Skip to content

Commit a9588fc

Browse files
authored
upgrade(fleet): Make installer refresh rate configurable (#44120)
### What does this PR do? Allows configuration of the Datadog installer refresh rates ### Motivation Customer feedback about too many `datadog-installer` binary calls, which only happen during refreshes ### Describe how you validated your changes Manual QA ### Additional Notes Co-authored-by: baptiste.foy <baptiste.foy@datadoghq.com>
1 parent 5f8f6df commit a9588fc

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

pkg/config/setup/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,9 @@ func InitConfig(config pkgconfigmodel.Setup) {
11851185
config.BindEnvAndSetDefault("installer.registry.auth", "")
11861186
config.BindEnvAndSetDefault("installer.registry.username", "")
11871187
config.BindEnvAndSetDefault("installer.registry.password", "")
1188+
config.BindEnvAndSetDefault("installer.refresh_interval", time.Duration(30*time.Second))
1189+
config.BindEnvAndSetDefault("installer.gc_interval", time.Duration(time.Hour))
1190+
11881191
// Legacy installer configuration
11891192
config.SetKnown("remote_policies") //nolint:forbidigo // TODO: replace by 'SetDefaultAndBindEnv'
11901193

pkg/fleet/daemon/daemon.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ import (
3939
)
4040

4141
const (
42-
// gcInterval is the interval at which the GC will run
43-
gcInterval = 1 * time.Hour
44-
// refreshStateInterval is the interval at which the state will be refreshed
45-
refreshStateInterval = 30 * time.Second
4642
// disableClientIDCheck is the magic string to disable the client ID check.
4743
disableClientIDCheck = "disable-client-id-check"
4844
)
@@ -98,6 +94,8 @@ type daemonImpl struct {
9894
requestsWG sync.WaitGroup
9995
taskDB *taskDB
10096
clientID string
97+
refreshInterval time.Duration
98+
gcInterval time.Duration
10199
}
102100

103101
func newInstaller(installerBin string) func(env *env.Env) installer.Installer {
@@ -151,10 +149,12 @@ func NewDaemon(hostname string, rcFetcher client.ConfigFetcher, config agentconf
151149
ConfigID: configID,
152150
}
153151
installer := newInstaller(installerBin)
154-
return newDaemon(rc, installer, env, taskDB), nil
152+
refreshInterval := config.GetDuration("installer.refresh_interval")
153+
gcInterval := config.GetDuration("installer.gc_interval")
154+
return newDaemon(rc, installer, env, taskDB, refreshInterval, gcInterval), nil
155155
}
156156

157-
func newDaemon(rc *remoteConfig, installer func(env *env.Env) installer.Installer, env *env.Env, taskDB *taskDB) *daemonImpl {
157+
func newDaemon(rc *remoteConfig, installer func(env *env.Env) installer.Installer, env *env.Env, taskDB *taskDB, refreshInterval time.Duration, gcInterval time.Duration) *daemonImpl {
158158
i := &daemonImpl{
159159
env: env,
160160
clientID: rc.client.GetClientID(),
@@ -167,6 +167,8 @@ func newDaemon(rc *remoteConfig, installer func(env *env.Env) installer.Installe
167167
configsOverride: make(map[string]installerConfig),
168168
stopChan: make(chan struct{}),
169169
taskDB: taskDB,
170+
refreshInterval: refreshInterval,
171+
gcInterval: gcInterval,
170172
}
171173
i.refreshState(context.Background())
172174
return i
@@ -309,9 +311,9 @@ func (d *daemonImpl) Start(_ context.Context) error {
309311
}
310312

311313
go func() {
312-
gcTicker := time.NewTicker(gcInterval)
314+
gcTicker := time.NewTicker(d.gcInterval)
313315
defer gcTicker.Stop()
314-
refreshStateTicker := time.NewTicker(refreshStateInterval)
316+
refreshStateTicker := time.NewTicker(d.refreshInterval)
315317
defer refreshStateTicker.Stop()
316318
for {
317319
select {

pkg/fleet/daemon/daemon_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ func newTestInstaller(t *testing.T) *testInstaller {
250250
func(_ *env.Env) installer.Installer { return pm },
251251
&env.Env{RemoteUpdates: true},
252252
taskDB,
253+
30*time.Second,
254+
1*time.Hour,
253255
)
254256
i := &testInstaller{
255257
daemonImpl: daemon,
@@ -493,6 +495,8 @@ func TestRefreshStateRunningVersions(t *testing.T) {
493495
func(_ *env.Env) installer.Installer { return pm },
494496
testEnv,
495497
taskDB,
498+
30*time.Second,
499+
1*time.Hour,
496500
)
497501
i := &testInstaller{
498502
daemonImpl: daemon,

0 commit comments

Comments
 (0)