Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .chloggen/13252-configgrpc-keepalive-configoptional.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: configgrpc

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Update optional fields to use `configoptional.Optional` field for optional values.

# One or more tracking issues or pull requests related to the change
issues: [13252, 13364]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
Specifically, the following fields have been updated to `configoptional`:
- `KeepaliveServerConfig.ServerParameters` (`KeepaliveServerParameters` type)
- `KeepaliveServerConfig.EnforcementPolicy` (`KeepaliveEnforcementPolicy` type)

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [api]
20 changes: 8 additions & 12 deletions config/configgrpc/configgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ type ClientConfig struct {
Middlewares []configmiddleware.Config `mapstructure:"middlewares,omitempty"`
}

func ptr[T any](v T) *T {
return &v
}

// NewDefaultClientConfig returns a new instance of ClientConfig with default values.
func NewDefaultClientConfig() ClientConfig {
return ClientConfig{
Expand All @@ -127,17 +123,17 @@ func NewDefaultClientConfig() ClientConfig {

// KeepaliveServerConfig is the configuration for keepalive.
type KeepaliveServerConfig struct {
ServerParameters *KeepaliveServerParameters `mapstructure:"server_parameters,omitempty"`
EnforcementPolicy *KeepaliveEnforcementPolicy `mapstructure:"enforcement_policy,omitempty"`
ServerParameters configoptional.Optional[KeepaliveServerParameters] `mapstructure:"server_parameters,omitempty"`
EnforcementPolicy configoptional.Optional[KeepaliveEnforcementPolicy] `mapstructure:"enforcement_policy,omitempty"`
// prevent unkeyed literal initialization
_ struct{}
}

// NewDefaultKeepaliveServerConfig returns a new instance of KeepaliveServerConfig with default values.
func NewDefaultKeepaliveServerConfig() KeepaliveServerConfig {
return KeepaliveServerConfig{
ServerParameters: ptr(NewDefaultKeepaliveServerParameters()),
EnforcementPolicy: ptr(NewDefaultKeepaliveEnforcementPolicy()),
ServerParameters: configoptional.Some(NewDefaultKeepaliveServerParameters()),
EnforcementPolicy: configoptional.Some(NewDefaultKeepaliveEnforcementPolicy()),
}
}

Expand Down Expand Up @@ -487,8 +483,8 @@ func (gss *ServerConfig) getGrpcServerOptions(
// https://github.com/grpc/grpc-go/blob/120728e1f775e40a2a764341939b78d666b08260/internal/transport/http2_server.go#L184-L200
if gss.Keepalive.HasValue() {
keepaliveConfig := gss.Keepalive.Get()
if keepaliveConfig.ServerParameters != nil {
svrParams := keepaliveConfig.ServerParameters
if keepaliveConfig.ServerParameters.HasValue() {
svrParams := keepaliveConfig.ServerParameters.Get()
opts = append(opts, grpc.KeepaliveParams(keepalive.ServerParameters{
MaxConnectionIdle: svrParams.MaxConnectionIdle,
MaxConnectionAge: svrParams.MaxConnectionAge,
Expand All @@ -501,8 +497,8 @@ func (gss *ServerConfig) getGrpcServerOptions(
// to apply them over zero/nil values before passing these as grpc.ServerOptions.
// The following shows the server code for applying default grpc.ServerOptions.
// https://github.com/grpc/grpc-go/blob/120728e1f775e40a2a764341939b78d666b08260/internal/transport/http2_server.go#L202-L205
if keepaliveConfig.EnforcementPolicy != nil {
enfPol := keepaliveConfig.EnforcementPolicy
if keepaliveConfig.EnforcementPolicy.HasValue() {
enfPol := keepaliveConfig.EnforcementPolicy.Get()
opts = append(opts, grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{
MinTime: enfPol.MinTime,
PermitWithoutStream: enfPol.PermitWithoutStream,
Expand Down
12 changes: 6 additions & 6 deletions config/configgrpc/configgrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ func TestNewDefaultKeepaliveEnforcementPolicy(t *testing.T) {

func TestNewDefaultKeepaliveServerConfig(t *testing.T) {
expected := KeepaliveServerConfig{
ServerParameters: ptr(NewDefaultKeepaliveServerParameters()),
EnforcementPolicy: ptr(NewDefaultKeepaliveEnforcementPolicy()),
ServerParameters: configoptional.Some(NewDefaultKeepaliveServerParameters()),
EnforcementPolicy: configoptional.Some(NewDefaultKeepaliveEnforcementPolicy()),
}
result := NewDefaultKeepaliveServerConfig()
assert.Equal(t, expected, result)
Expand Down Expand Up @@ -391,17 +391,17 @@ func TestAllGrpcServerSettingsExceptAuth(t *testing.T) {
ReadBufferSize: 1024,
WriteBufferSize: 1024,
Keepalive: configoptional.Some(KeepaliveServerConfig{
ServerParameters: &KeepaliveServerParameters{
ServerParameters: configoptional.Some(KeepaliveServerParameters{
MaxConnectionIdle: time.Second,
MaxConnectionAge: time.Second,
MaxConnectionAgeGrace: time.Second,
Time: time.Second,
Timeout: time.Second,
},
EnforcementPolicy: &KeepaliveEnforcementPolicy{
}),
EnforcementPolicy: configoptional.Some(KeepaliveEnforcementPolicy{
MinTime: time.Second,
PermitWithoutStream: true,
},
}),
}),
}
opts, err := gss.getGrpcServerOptions(context.Background(), componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings(), []ToServerOption{})
Expand Down
8 changes: 4 additions & 4 deletions receiver/otlpreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,17 @@ func TestUnmarshalConfig(t *testing.T) {
ReadBufferSize: 1024,
WriteBufferSize: 1024,
Keepalive: configoptional.Some(configgrpc.KeepaliveServerConfig{
ServerParameters: &configgrpc.KeepaliveServerParameters{
ServerParameters: configoptional.Some(configgrpc.KeepaliveServerParameters{
MaxConnectionIdle: 11 * time.Second,
MaxConnectionAge: 12 * time.Second,
MaxConnectionAgeGrace: 13 * time.Second,
Time: 30 * time.Second,
Timeout: 5 * time.Second,
},
EnforcementPolicy: &configgrpc.KeepaliveEnforcementPolicy{
}),
EnforcementPolicy: configoptional.Some(configgrpc.KeepaliveEnforcementPolicy{
MinTime: 10 * time.Second,
PermitWithoutStream: true,
},
}),
}),
}),
HTTP: configoptional.Some(HTTPConfig{
Expand Down
Loading