Skip to content

Commit 3cb9a64

Browse files
committed
Undo an unnecessary struct field type change
1 parent 6b2c133 commit 3cb9a64

5 files changed

Lines changed: 15 additions & 13 deletions

File tree

config/confighttp/keepalive_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ func TestServerConfigValidate(t *testing.T) {
187187
name: "deprecated keep_alives_enabled false only — no conflict",
188188
cfg: func() ServerConfig {
189189
c := NewDefaultServerConfig()
190-
disabled := false
191-
c.KeepAlivesEnabled = &disabled
190+
c.KeepAlivesEnabled = false
192191
return c
193192
}(),
194193
},
@@ -207,8 +206,7 @@ func TestServerConfigValidate(t *testing.T) {
207206
cfg: func() ServerConfig {
208207
c := NewDefaultServerConfig()
209208
c.Keepalive = configoptional.Some(KeepaliveServerConfig{})
210-
disabled := false
211-
c.KeepAlivesEnabled = &disabled
209+
c.KeepAlivesEnabled = false
212210
return c
213211
}(),
214212
expectError: true,
@@ -305,8 +303,7 @@ func TestServerConfigDeprecatedKeepAlivesDisabled(t *testing.T) {
305303
settings := component.TelemetrySettings{Logger: zap.New(core)}
306304

307305
cfg := NewDefaultServerConfig()
308-
disabled := false
309-
cfg.KeepAlivesEnabled = &disabled
306+
cfg.KeepAlivesEnabled = false
310307

311308
srv, err := cfg.ToServer(t.Context(), nil, settings, http.NewServeMux())
312309
require.NoError(t, err)

config/confighttp/server.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ type ServerConfig struct {
101101
// Deprecated: use Keepalive.IdleTimeout instead.
102102
IdleTimeout time.Duration `mapstructure:"idle_timeout,omitempty"`
103103
// Deprecated: set Keepalive to None to disable keep-alives.
104-
KeepAlivesEnabled *bool `mapstructure:"keep_alives_enabled,omitempty"`
104+
// Note: only the false value is meaningful; true is indistinguishable from the default.
105+
KeepAlivesEnabled bool `mapstructure:"keep_alives_enabled,omitempty"`
105106
}
106107

107108
type KeepaliveServerConfig struct {
@@ -128,11 +129,12 @@ func NewDefaultServerConfig() ServerConfig {
128129
Keepalive: configoptional.Default(KeepaliveServerConfig{
129130
IdleTimeout: 1 * time.Minute,
130131
}),
132+
KeepAlivesEnabled: true,
131133
}
132134
}
133135

134136
func (sc *ServerConfig) Validate() error {
135-
if sc.Keepalive.HasValue() && (sc.IdleTimeout != 0 || sc.KeepAlivesEnabled != nil) {
137+
if sc.Keepalive.HasValue() && (sc.IdleTimeout != 0 || !sc.KeepAlivesEnabled) {
136138
return errors.New("confighttp.ServerConfig: cannot use deprecated keepalive fields (idle_timeout, keep_alives_enabled) alongside the 'keepalive' section; migrate to the 'keepalive' section")
137139
}
138140
return nil
@@ -205,7 +207,7 @@ func (sc *ServerConfig) ToServer(ctx context.Context, extensions map[component.I
205207
if sc.IdleTimeout != 0 {
206208
settings.Logger.Warn("'idle_timeout' is deprecated; use 'keepalive.idle_timeout' instead")
207209
}
208-
if sc.KeepAlivesEnabled != nil {
210+
if !sc.KeepAlivesEnabled {
209211
settings.Logger.Warn("'keep_alives_enabled' is deprecated; set keepalive to null (keepalive: null) to disable keep-alives")
210212
}
211213

@@ -326,7 +328,7 @@ func (sc *ServerConfig) ToServer(ctx context.Context, extensions map[component.I
326328

327329
// Convert deprecated fields into the canonical Keepalive optional so the
328330
// application logic below only has to deal with one struct.
329-
if sc.KeepAlivesEnabled != nil && !*sc.KeepAlivesEnabled {
331+
if !sc.Keepalive.HasValue() && !sc.KeepAlivesEnabled {
330332
sc.Keepalive = configoptional.None[KeepaliveServerConfig]()
331333
} else if sc.IdleTimeout != 0 {
332334
sc.Keepalive = configoptional.Some(KeepaliveServerConfig{

config/confighttp/server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ func TestServerUnmarshalYAMLComprehensiveConfig(t *testing.T) {
11531153
require.NoError(t, err)
11541154

11551155
// Test server configuration
1156-
var serverConfig ServerConfig
1156+
serverConfig := NewDefaultServerConfig()
11571157
serverSub, err := cm.Sub("server")
11581158
require.NoError(t, err)
11591159
require.NoError(t, serverSub.Unmarshal(&serverConfig))

internal/e2e/confighttp_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func TestConfmapMarshalConfigHTTP(t *testing.T) {
3131
require.NoError(t, conf.Marshal(confighttp.NewDefaultServerConfig()))
3232
assert.Equal(t, map[string]any{
3333
"cors": nil,
34+
"keep_alives_enabled": true,
3435
"keepalive": nil,
3536
"read_header_timeout": 60 * time.Second,
3637
"tls": nil,

receiver/otlpreceiver/config_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ func TestUnmarshalConfig(t *testing.T) {
141141
AllowedOrigins: []string{"https://*.test.com", "https://test.com"},
142142
MaxAge: 7200,
143143
}),
144-
Keepalive: configoptional.Some(confighttp.KeepaliveServerConfig{}),
144+
Keepalive: configoptional.Some(confighttp.KeepaliveServerConfig{}),
145+
KeepAlivesEnabled: true,
145146
},
146147
TracesURLPath: "/traces",
147148
MetricsURLPath: "/v2/metrics",
@@ -174,7 +175,8 @@ func TestUnmarshalConfigUnix(t *testing.T) {
174175
Endpoint: "/tmp/http_otlp.sock",
175176
Transport: confignet.TransportTypeUnix,
176177
},
177-
Keepalive: configoptional.Some(confighttp.KeepaliveServerConfig{}),
178+
Keepalive: configoptional.Some(confighttp.KeepaliveServerConfig{}),
179+
KeepAlivesEnabled: true,
178180
},
179181
TracesURLPath: defaultTracesURLPath,
180182
MetricsURLPath: defaultMetricsURLPath,

0 commit comments

Comments
 (0)