Skip to content

Commit 3dd727b

Browse files
committed
fix issue where reducing the value of DD_TELEMETRY_HEARTBEAT_INTERVAL would not reduce the value of the flushing interval
Signed-off-by: Eliott Bouhana <[email protected]>
1 parent 90c9985 commit 3dd727b

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

internal/newtelemetry/client_config.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ var (
8383
agentlessURL = "https://instrumentation-telemetry-intake.datadoghq.com/api/v2/apmtelemetry"
8484

8585
// defaultHeartbeatInterval is the default interval at which the agent sends a heartbeat.
86-
defaultHeartbeatInterval = time.Minute // seconds
86+
defaultHeartbeatInterval = time.Minute
8787

8888
// defaultExtendedHeartbeatInterval is the default interval at which the agent sends an extended heartbeat.
8989
defaultExtendedHeartbeatInterval = 24 * time.Hour
@@ -162,12 +162,6 @@ func defaultConfig(config ClientConfig) ClientConfig {
162162
}
163163
}
164164

165-
if config.HeartbeatInterval == 0 {
166-
config.HeartbeatInterval = globalinternal.DurationEnv("DD_TELEMETRY_HEARTBEAT_INTERVAL", defaultHeartbeatInterval)
167-
} else {
168-
config.HeartbeatInterval = defaultAuthorizedHearbeatRange.Clamp(config.HeartbeatInterval)
169-
}
170-
171165
if config.FlushInterval.Min == 0 {
172166
config.FlushInterval.Min = defaultFlushIntervalRange.Min
173167
} else {
@@ -180,6 +174,16 @@ func defaultConfig(config ClientConfig) ClientConfig {
180174
config.FlushInterval.Max = defaultAuthorizedHearbeatRange.Clamp(config.FlushInterval.Max)
181175
}
182176

177+
heartBeatInterval := defaultHeartbeatInterval
178+
if config.HeartbeatInterval != 0 {
179+
heartBeatInterval = config.HeartbeatInterval
180+
}
181+
182+
envVal := globalinternal.FloatEnv("DD_TELEMETRY_HEARTBEAT_INTERVAL", heartBeatInterval.Seconds())
183+
config.HeartbeatInterval = defaultAuthorizedHearbeatRange.Clamp(time.Duration(envVal * float64(time.Second)))
184+
// Make sure we flush at least at each heartbeat interval
185+
config.FlushInterval = config.FlushInterval.ReduceMax(config.HeartbeatInterval)
186+
183187
if config.DependencyLoader == nil && globalinternal.BoolEnv("DD_TELEMETRY_DEPENDENCY_COLLECTION_ENABLED", true) {
184188
config.DependencyLoader = debug.ReadBuildInfo
185189
}

internal/newtelemetry/internal/range.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,11 @@ func (r Range[T]) Contains(value T) bool {
2929
func (r Range[T]) Clamp(value T) T {
3030
return max(min(r.Max, value), r.Min)
3131
}
32+
33+
// ReduceMax returns a new range where value is the new max and min is either the current min or the new value to make sure the range is ordered.
34+
func (r Range[T]) ReduceMax(value T) Range[T] {
35+
return Range[T]{
36+
Min: min(r.Min, value),
37+
Max: value,
38+
}
39+
}

0 commit comments

Comments
 (0)