Skip to content

Commit

Permalink
fix issue where reducing the value of DD_TELEMETRY_HEARTBEAT_INTERVAL…
Browse files Browse the repository at this point in the history
… would not reduce the value of the flushing interval

Signed-off-by: Eliott Bouhana <[email protected]>
  • Loading branch information
eliottness committed Feb 7, 2025
1 parent 90c9985 commit 3dd727b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
18 changes: 11 additions & 7 deletions internal/newtelemetry/client_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ var (
agentlessURL = "https://instrumentation-telemetry-intake.datadoghq.com/api/v2/apmtelemetry"

// defaultHeartbeatInterval is the default interval at which the agent sends a heartbeat.
defaultHeartbeatInterval = time.Minute // seconds
defaultHeartbeatInterval = time.Minute

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

if config.HeartbeatInterval == 0 {
config.HeartbeatInterval = globalinternal.DurationEnv("DD_TELEMETRY_HEARTBEAT_INTERVAL", defaultHeartbeatInterval)
} else {
config.HeartbeatInterval = defaultAuthorizedHearbeatRange.Clamp(config.HeartbeatInterval)
}

if config.FlushInterval.Min == 0 {
config.FlushInterval.Min = defaultFlushIntervalRange.Min
} else {
Expand All @@ -180,6 +174,16 @@ func defaultConfig(config ClientConfig) ClientConfig {
config.FlushInterval.Max = defaultAuthorizedHearbeatRange.Clamp(config.FlushInterval.Max)
}

heartBeatInterval := defaultHeartbeatInterval
if config.HeartbeatInterval != 0 {
heartBeatInterval = config.HeartbeatInterval
}

envVal := globalinternal.FloatEnv("DD_TELEMETRY_HEARTBEAT_INTERVAL", heartBeatInterval.Seconds())
config.HeartbeatInterval = defaultAuthorizedHearbeatRange.Clamp(time.Duration(envVal * float64(time.Second)))
// Make sure we flush at least at each heartbeat interval
config.FlushInterval = config.FlushInterval.ReduceMax(config.HeartbeatInterval)

if config.DependencyLoader == nil && globalinternal.BoolEnv("DD_TELEMETRY_DEPENDENCY_COLLECTION_ENABLED", true) {
config.DependencyLoader = debug.ReadBuildInfo
}
Expand Down
8 changes: 8 additions & 0 deletions internal/newtelemetry/internal/range.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,11 @@ func (r Range[T]) Contains(value T) bool {
func (r Range[T]) Clamp(value T) T {
return max(min(r.Max, value), r.Min)
}

// 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.
func (r Range[T]) ReduceMax(value T) Range[T] {
return Range[T]{
Min: min(r.Min, value),
Max: value,
}
}

0 comments on commit 3dd727b

Please sign in to comment.