Skip to content

Commit cce26c8

Browse files
authored
Adding ipv6 to useragent (#1930)
1 parent b31cbc0 commit cce26c8

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

extension/agenthealth/handler/useragent/useragent.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,15 @@ func (ua *userAgent) SetComponents(otelCfg *otelcol.Config, telegrafCfg *telegra
141141
ua.inputs.Add(flagRunAsUser)
142142
}
143143

144+
// Add ipv6 feature flag if dualstack endpoint is enabled
145+
if os.Getenv(envconfig.AWS_USE_DUALSTACK_ENDPOINT) == "true" {
146+
ua.feature.Add("ipv6")
147+
}
148+
144149
ua.inputsStr.Store(componentsStr(typeInputs, ua.inputs))
145150
ua.processorsStr.Store(componentsStr(typeProcessors, ua.processors))
146151
ua.outputsStr.Store(componentsStr(typeOutputs, ua.outputs))
152+
ua.featureStr.Store(componentsStr(typeFeature, ua.feature))
147153
ua.notify()
148154
}
149155

extension/agenthealth/handler/useragent/useragent_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package useragent
55

66
import (
77
"fmt"
8+
"os"
89
"sync"
910
"testing"
1011

@@ -284,3 +285,46 @@ func TestListen(t *testing.T) {
284285
ua.SetContainerInsightsFlag()
285286
wg.Wait()
286287
}
288+
289+
func TestSetComponents_WithDualStackEndpoint(t *testing.T) {
290+
// Save original env var
291+
originalEnv := os.Getenv(envconfig.AWS_USE_DUALSTACK_ENDPOINT)
292+
defer func() {
293+
if originalEnv == "" {
294+
os.Unsetenv(envconfig.AWS_USE_DUALSTACK_ENDPOINT)
295+
} else {
296+
os.Setenv(envconfig.AWS_USE_DUALSTACK_ENDPOINT, originalEnv)
297+
}
298+
}()
299+
300+
t.Run("ipv6_feature_added_when_dualstack_enabled", func(t *testing.T) {
301+
os.Setenv(envconfig.AWS_USE_DUALSTACK_ENDPOINT, "true")
302+
ua := newUserAgent()
303+
ua.SetComponents(&otelcol.Config{}, &telegraf.Config{})
304+
305+
assert.Contains(t, ua.feature, "ipv6")
306+
assert.Contains(t, ua.featureStr.Load(), "ipv6")
307+
header := ua.Header(true)
308+
assert.Contains(t, header, "feature:(ipv6)")
309+
})
310+
311+
t.Run("ipv6_feature_not_added_when_dualstack_disabled", func(t *testing.T) {
312+
os.Setenv(envconfig.AWS_USE_DUALSTACK_ENDPOINT, "false")
313+
ua := newUserAgent()
314+
ua.SetComponents(&otelcol.Config{}, &telegraf.Config{})
315+
316+
assert.NotContains(t, ua.feature, "ipv6")
317+
header := ua.Header(true)
318+
assert.NotContains(t, header, "ipv6")
319+
})
320+
321+
t.Run("ipv6_feature_not_added_when_dualstack_not_set", func(t *testing.T) {
322+
os.Unsetenv(envconfig.AWS_USE_DUALSTACK_ENDPOINT)
323+
ua := newUserAgent()
324+
ua.SetComponents(&otelcol.Config{}, &telegraf.Config{})
325+
326+
assert.NotContains(t, ua.feature, "ipv6")
327+
header := ua.Header(true)
328+
assert.NotContains(t, header, "ipv6")
329+
})
330+
}

0 commit comments

Comments
 (0)