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
25 changes: 25 additions & 0 deletions .chloggen/jackgopack4_configgrpc-configoptional.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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: [13250, 13252]

# (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: Components using `configgrpc` package may need to update config values.

# 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]
5 changes: 3 additions & 2 deletions config/configgrpc/client_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config/configmiddleware"
"go.opentelemetry.io/collector/config/confignet"
"go.opentelemetry.io/collector/config/configoptional"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/extension"
"go.opentelemetry.io/collector/extension/extensionmiddleware"
Expand Down Expand Up @@ -103,12 +104,12 @@ func TestClientMiddlewareOrdering(t *testing.T) {

// Start a gRPC server that will record the incoming metadata
server := &grpcTraceServer{}
srv, addr := server.startTestServer(t, ServerConfig{
srv, addr := server.startTestServer(t, configoptional.Some(ServerConfig{
NetAddr: confignet.AddrConfig{
Endpoint: "localhost:0",
Transport: confignet.TransportTypeTCP,
},
})
}))
defer srv.Stop()

// Create client config with middleware extensions
Expand Down
47 changes: 25 additions & 22 deletions config/configgrpc/configgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"go.opentelemetry.io/collector/config/configmiddleware"
"go.opentelemetry.io/collector/config/confignet"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/config/configoptional"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/extension/extensionauth"
)
Expand Down Expand Up @@ -79,7 +80,7 @@ type ClientConfig struct {

// The keepalive parameters for gRPC client. See grpc.WithKeepaliveParams.
// (https://godoc.org/google.golang.org/grpc#WithKeepaliveParams).
Keepalive *KeepaliveClientConfig `mapstructure:"keepalive,omitempty"`
Keepalive configoptional.Optional[KeepaliveClientConfig] `mapstructure:"keepalive,omitempty"`

// ReadBufferSize for gRPC client. See grpc.WithReadBufferSize.
// (https://godoc.org/google.golang.org/grpc#WithReadBufferSize).
Expand All @@ -105,7 +106,7 @@ type ClientConfig struct {
Authority string `mapstructure:"authority,omitempty"`

// Auth configuration for outgoing RPCs.
Auth *configauth.Config `mapstructure:"auth,omitempty"`
Auth configoptional.Optional[configauth.Config] `mapstructure:"auth,omitempty"`

// Middlewares for the gRPC client.
Middlewares []configmiddleware.Config `mapstructure:"middlewares,omitempty"`
Expand All @@ -119,7 +120,7 @@ func ptr[T any](v T) *T {
func NewDefaultClientConfig() ClientConfig {
return ClientConfig{
TLS: configtls.NewDefaultClientConfig(),
Keepalive: ptr(NewDefaultKeepaliveClientConfig()),
Keepalive: configoptional.Some(NewDefaultKeepaliveClientConfig()),
BalancerName: BalancerName(),
}
}
Expand Down Expand Up @@ -180,7 +181,7 @@ type ServerConfig struct {

// Configures the protocol to use TLS.
// The default value is nil, which will cause the protocol to not use TLS.
TLS *configtls.ServerConfig `mapstructure:"tls,omitempty"`
TLS configoptional.Optional[configtls.ServerConfig] `mapstructure:"tls,omitempty"`

// MaxRecvMsgSizeMiB sets the maximum size (in MiB) of messages accepted by the server.
MaxRecvMsgSizeMiB int `mapstructure:"max_recv_msg_size_mib,omitempty"`
Expand All @@ -198,10 +199,10 @@ type ServerConfig struct {
WriteBufferSize int `mapstructure:"write_buffer_size,omitempty"`

// Keepalive anchor for all the settings related to keepalive.
Keepalive *KeepaliveServerConfig `mapstructure:"keepalive,omitempty"`
Keepalive configoptional.Optional[KeepaliveServerConfig] `mapstructure:"keepalive,omitempty"`

// Auth for this receiver
Auth *configauth.Config `mapstructure:"auth,omitempty"`
Auth configoptional.Optional[configauth.Config] `mapstructure:"auth,omitempty"`

// Include propagates the incoming connection's metadata to downstream consumers.
IncludeMetadata bool `mapstructure:"include_metadata,omitempty"`
Expand All @@ -216,7 +217,7 @@ type ServerConfig struct {
// NewDefaultServerConfig returns a new instance of ServerConfig with default values.
func NewDefaultServerConfig() ServerConfig {
return ServerConfig{
Keepalive: ptr(NewDefaultKeepaliveServerConfig()),
Keepalive: configoptional.Some(NewDefaultKeepaliveServerConfig()),
}
}

Expand Down Expand Up @@ -330,21 +331,22 @@ func (gcs *ClientConfig) getGrpcDialOptions(
opts = append(opts, grpc.WithWriteBufferSize(gcs.WriteBufferSize))
}

if gcs.Keepalive != nil {
if gcs.Keepalive.HasValue() {
keepaliveConfig := gcs.Keepalive.Get()
keepAliveOption := grpc.WithKeepaliveParams(keepalive.ClientParameters{
Time: gcs.Keepalive.Time,
Timeout: gcs.Keepalive.Timeout,
PermitWithoutStream: gcs.Keepalive.PermitWithoutStream,
Time: keepaliveConfig.Time,
Timeout: keepaliveConfig.Timeout,
PermitWithoutStream: keepaliveConfig.PermitWithoutStream,
})
opts = append(opts, keepAliveOption)
}

if gcs.Auth != nil {
if gcs.Auth.HasValue() {
if host.GetExtensions() == nil {
return nil, errors.New("no extensions configuration available")
}

grpcAuthenticator, cerr := gcs.Auth.GetGRPCClientAuthenticator(ctx, host.GetExtensions())
grpcAuthenticator, cerr := gcs.Auth.Get().GetGRPCClientAuthenticator(ctx, host.GetExtensions())
if cerr != nil {
return nil, cerr
}
Expand Down Expand Up @@ -455,8 +457,8 @@ func (gss *ServerConfig) getGrpcServerOptions(
) ([]grpc.ServerOption, error) {
var opts []grpc.ServerOption

if gss.TLS != nil {
tlsCfg, err := gss.TLS.LoadTLSConfig(context.Background())
if gss.TLS.HasValue() {
tlsCfg, err := gss.TLS.Get().LoadTLSConfig(context.Background())
if err != nil {
return nil, err
}
Expand All @@ -483,9 +485,10 @@ 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#L184-L200
if gss.Keepalive != nil {
if gss.Keepalive.ServerParameters != nil {
svrParams := gss.Keepalive.ServerParameters
if gss.Keepalive.HasValue() {
keepaliveConfig := gss.Keepalive.Get()
if keepaliveConfig.ServerParameters != nil {
svrParams := keepaliveConfig.ServerParameters
opts = append(opts, grpc.KeepaliveParams(keepalive.ServerParameters{
MaxConnectionIdle: svrParams.MaxConnectionIdle,
MaxConnectionAge: svrParams.MaxConnectionAge,
Expand All @@ -498,8 +501,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 gss.Keepalive.EnforcementPolicy != nil {
enfPol := gss.Keepalive.EnforcementPolicy
if keepaliveConfig.EnforcementPolicy != nil {
enfPol := keepaliveConfig.EnforcementPolicy
opts = append(opts, grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{
MinTime: enfPol.MinTime,
PermitWithoutStream: enfPol.PermitWithoutStream,
Expand All @@ -510,8 +513,8 @@ func (gss *ServerConfig) getGrpcServerOptions(
var uInterceptors []grpc.UnaryServerInterceptor
var sInterceptors []grpc.StreamServerInterceptor

if gss.Auth != nil {
authenticator, err := gss.Auth.GetServerAuthenticator(context.Background(), host.GetExtensions())
if gss.Auth.HasValue() {
authenticator, err := gss.Auth.Get().GetServerAuthenticator(context.Background(), host.GetExtensions())
if err != nil {
return nil, err
}
Expand Down
Loading
Loading