From 421c655efeeeaf3ae017c1a8396f9791e07e202c Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Thu, 1 Feb 2024 13:45:36 -0800 Subject: [PATCH] [configgrpc] Deprecate GRPCServerSettings, use ServerConfig instead (#9403) **Description:** Deprecate GRPCServerSettings, use ~GRPC~ServerConfig instead **Link to tracking Issue:** #6767 --- .../grpcserversettings_grpcserverconfig.yaml | 25 ++++++++++++++++ config/configgrpc/configgrpc.go | 14 +++++---- config/configgrpc/configgrpc_test.go | 30 +++++++++---------- receiver/otlpreceiver/config.go | 4 +-- receiver/otlpreceiver/config_test.go | 4 +-- receiver/otlpreceiver/factory.go | 2 +- receiver/otlpreceiver/factory_test.go | 12 ++++---- receiver/otlpreceiver/otlp_test.go | 2 +- 8 files changed, 61 insertions(+), 32 deletions(-) create mode 100755 .chloggen/grpcserversettings_grpcserverconfig.yaml diff --git a/.chloggen/grpcserversettings_grpcserverconfig.yaml b/.chloggen/grpcserversettings_grpcserverconfig.yaml new file mode 100755 index 00000000000..4f8907c478c --- /dev/null +++ b/.chloggen/grpcserversettings_grpcserverconfig.yaml @@ -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: deprecation + +# 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: Deprecate GRPCServerSettings, use ServerConfig instead + +# One or more tracking issues or pull requests related to the change +issues: [6767] + +# (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: + +# 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] \ No newline at end of file diff --git a/config/configgrpc/configgrpc.go b/config/configgrpc/configgrpc.go index f26fe7dbcee..a1ec981175b 100644 --- a/config/configgrpc/configgrpc.go +++ b/config/configgrpc/configgrpc.go @@ -117,7 +117,11 @@ type KeepaliveEnforcementPolicy struct { } // GRPCServerSettings defines common settings for a gRPC server configuration. -type GRPCServerSettings struct { +// Deprecated: [v0.94.0] Use ServerConfig instead +type GRPCServerSettings = ServerConfig + +// ServerConfig defines common settings for a gRPC server configuration. +type ServerConfig struct { // Server net.Addr config. For transport only "tcp" and "unix" are valid options. NetAddr confignet.NetAddr `mapstructure:",squash"` @@ -269,17 +273,17 @@ func validateBalancerName(balancerName string) bool { } // ToListenerContext returns the net.Listener constructed from the settings. -func (gss *GRPCServerSettings) ToListenerContext(ctx context.Context) (net.Listener, error) { +func (gss *ServerConfig) ToListenerContext(ctx context.Context) (net.Listener, error) { return gss.NetAddr.Listen(ctx) } // ToListener returns the net.Listener constructed from the settings. // Deprecated: [v0.94.0] use ToListenerContext instead. -func (gss *GRPCServerSettings) ToListener() (net.Listener, error) { +func (gss *ServerConfig) ToListener() (net.Listener, error) { return gss.ToListenerContext(context.Background()) } -func (gss *GRPCServerSettings) ToServer(host component.Host, settings component.TelemetrySettings, extraOpts ...grpc.ServerOption) (*grpc.Server, error) { +func (gss *ServerConfig) ToServer(host component.Host, settings component.TelemetrySettings, extraOpts ...grpc.ServerOption) (*grpc.Server, error) { opts, err := gss.toServerOption(host, settings) if err != nil { return nil, err @@ -288,7 +292,7 @@ func (gss *GRPCServerSettings) ToServer(host component.Host, settings component. return grpc.NewServer(opts...), nil } -func (gss *GRPCServerSettings) toServerOption(host component.Host, settings component.TelemetrySettings) ([]grpc.ServerOption, error) { +func (gss *ServerConfig) toServerOption(host component.Host, settings component.TelemetrySettings) ([]grpc.ServerOption, error) { switch gss.NetAddr.Transport { case "tcp", "tcp4", "tcp6", "udp", "udp4", "udp6": internal.WarnOnUnspecifiedHost(settings.Logger, gss.NetAddr.Endpoint) diff --git a/config/configgrpc/configgrpc_test.go b/config/configgrpc/configgrpc_test.go index a3c6b089b93..95f02ed9b2e 100644 --- a/config/configgrpc/configgrpc_test.go +++ b/config/configgrpc/configgrpc_test.go @@ -173,7 +173,7 @@ func TestAllGrpcClientSettings(t *testing.T) { } func TestDefaultGrpcServerSettings(t *testing.T) { - gss := &GRPCServerSettings{ + gss := &ServerConfig{ NetAddr: confignet.NetAddr{ Endpoint: "0.0.0.0:1234", }, @@ -184,7 +184,7 @@ func TestDefaultGrpcServerSettings(t *testing.T) { } func TestAllGrpcServerSettingsExceptAuth(t *testing.T) { - gss := &GRPCServerSettings{ + gss := &ServerConfig{ NetAddr: confignet.NetAddr{ Endpoint: "localhost:1234", Transport: "tcp", @@ -217,7 +217,7 @@ func TestAllGrpcServerSettingsExceptAuth(t *testing.T) { } func TestGrpcServerAuthSettings(t *testing.T) { - gss := &GRPCServerSettings{ + gss := &ServerConfig{ NetAddr: confignet.NetAddr{ Endpoint: "0.0.0.0:1234", }, @@ -378,11 +378,11 @@ func TestUseSecure(t *testing.T) { func TestGRPCServerWarning(t *testing.T) { tests := []struct { name string - settings GRPCServerSettings + settings ServerConfig len int }{ { - settings: GRPCServerSettings{ + settings: ServerConfig{ NetAddr: confignet.NetAddr{ Endpoint: "0.0.0.0:1234", Transport: "tcp", @@ -391,7 +391,7 @@ func TestGRPCServerWarning(t *testing.T) { len: 1, }, { - settings: GRPCServerSettings{ + settings: ServerConfig{ NetAddr: confignet.NetAddr{ Endpoint: "127.0.0.1:1234", Transport: "tcp", @@ -400,7 +400,7 @@ func TestGRPCServerWarning(t *testing.T) { len: 0, }, { - settings: GRPCServerSettings{ + settings: ServerConfig{ NetAddr: confignet.NetAddr{ Endpoint: "0.0.0.0:1234", Transport: "unix", @@ -428,12 +428,12 @@ func TestGRPCServerWarning(t *testing.T) { func TestGRPCServerSettingsError(t *testing.T) { tests := []struct { - settings GRPCServerSettings + settings ServerConfig err string }{ { err: "^failed to load TLS config: failed to load CA CertPool File: failed to load cert /doesnt/exist:", - settings: GRPCServerSettings{ + settings: ServerConfig{ NetAddr: confignet.NetAddr{ Endpoint: "127.0.0.1:1234", Transport: "tcp", @@ -447,7 +447,7 @@ func TestGRPCServerSettingsError(t *testing.T) { }, { err: "^failed to load TLS config: failed to load TLS cert and key: for auth via TLS, provide both certificate and key, or neither", - settings: GRPCServerSettings{ + settings: ServerConfig{ NetAddr: confignet.NetAddr{ Endpoint: "127.0.0.1:1234", Transport: "tcp", @@ -461,7 +461,7 @@ func TestGRPCServerSettingsError(t *testing.T) { }, { err: "^failed to load client CA CertPool: failed to load CA /doesnt/exist:", - settings: GRPCServerSettings{ + settings: ServerConfig{ NetAddr: confignet.NetAddr{ Endpoint: "127.0.0.1:1234", Transport: "tcp", @@ -481,7 +481,7 @@ func TestGRPCServerSettingsError(t *testing.T) { } func TestGRPCServerSettings_ToListener_Error(t *testing.T) { - settings := GRPCServerSettings{ + settings := ServerConfig{ NetAddr: confignet.NetAddr{ Endpoint: "127.0.0.1:1234567", Transport: "tcp", @@ -608,7 +608,7 @@ func TestHttpReception(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - gss := &GRPCServerSettings{ + gss := &ServerConfig{ NetAddr: confignet.NetAddr{ Endpoint: "localhost:0", Transport: "tcp", @@ -655,7 +655,7 @@ func TestReceiveOnUnixDomainSocket(t *testing.T) { t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) socketName := tempSocketName(t) - gss := &GRPCServerSettings{ + gss := &ServerConfig{ NetAddr: confignet.NetAddr{ Endpoint: socketName, Transport: "unix", @@ -850,7 +850,7 @@ func TestClientInfoInterceptors(t *testing.T) { // prepare the server { - gss := &GRPCServerSettings{ + gss := &ServerConfig{ NetAddr: confignet.NetAddr{ Endpoint: "localhost:0", Transport: "tcp", diff --git a/receiver/otlpreceiver/config.go b/receiver/otlpreceiver/config.go index 5557f13cdd1..00f5d8796c4 100644 --- a/receiver/otlpreceiver/config.go +++ b/receiver/otlpreceiver/config.go @@ -36,8 +36,8 @@ type HTTPConfig struct { // Protocols is the configuration for the supported protocols. type Protocols struct { - GRPC *configgrpc.GRPCServerSettings `mapstructure:"grpc"` - HTTP *HTTPConfig `mapstructure:"http"` + GRPC *configgrpc.ServerConfig `mapstructure:"grpc"` + HTTP *HTTPConfig `mapstructure:"http"` } // Config defines configuration for OTLP receiver. diff --git a/receiver/otlpreceiver/config_test.go b/receiver/otlpreceiver/config_test.go index 46ec9c369f7..f47e1af4087 100644 --- a/receiver/otlpreceiver/config_test.go +++ b/receiver/otlpreceiver/config_test.go @@ -86,7 +86,7 @@ func TestUnmarshalConfig(t *testing.T) { assert.Equal(t, &Config{ Protocols: Protocols{ - GRPC: &configgrpc.GRPCServerSettings{ + GRPC: &configgrpc.ServerConfig{ NetAddr: confignet.NetAddr{ Endpoint: "0.0.0.0:4317", Transport: "tcp", @@ -147,7 +147,7 @@ func TestUnmarshalConfigUnix(t *testing.T) { assert.Equal(t, &Config{ Protocols: Protocols{ - GRPC: &configgrpc.GRPCServerSettings{ + GRPC: &configgrpc.ServerConfig{ NetAddr: confignet.NetAddr{ Endpoint: "/tmp/grpc_otlp.sock", Transport: "unix", diff --git a/receiver/otlpreceiver/factory.go b/receiver/otlpreceiver/factory.go index 103a9ebb064..92559d05d67 100644 --- a/receiver/otlpreceiver/factory.go +++ b/receiver/otlpreceiver/factory.go @@ -43,7 +43,7 @@ func NewFactory() receiver.Factory { func createDefaultConfig() component.Config { return &Config{ Protocols: Protocols{ - GRPC: &configgrpc.GRPCServerSettings{ + GRPC: &configgrpc.ServerConfig{ NetAddr: confignet.NetAddr{ Endpoint: localhostgate.EndpointForPort(grpcPort), Transport: "tcp", diff --git a/receiver/otlpreceiver/factory_test.go b/receiver/otlpreceiver/factory_test.go index 284416ceb37..c0880dd18e0 100644 --- a/receiver/otlpreceiver/factory_test.go +++ b/receiver/otlpreceiver/factory_test.go @@ -52,7 +52,7 @@ func TestCreateSameReceiver(t *testing.T) { func TestCreateTracesReceiver(t *testing.T) { factory := NewFactory() - defaultGRPCSettings := &configgrpc.GRPCServerSettings{ + defaultGRPCSettings := &configgrpc.ServerConfig{ NetAddr: confignet.NetAddr{ Endpoint: testutil.GetAvailableLocalAddress(t), Transport: "tcp", @@ -88,7 +88,7 @@ func TestCreateTracesReceiver(t *testing.T) { name: "invalid_grpc_port", cfg: &Config{ Protocols: Protocols{ - GRPC: &configgrpc.GRPCServerSettings{ + GRPC: &configgrpc.ServerConfig{ NetAddr: confignet.NetAddr{ Endpoint: "localhost:112233", Transport: "tcp", @@ -162,7 +162,7 @@ func TestCreateTracesReceiver(t *testing.T) { func TestCreateMetricReceiver(t *testing.T) { factory := NewFactory() - defaultGRPCSettings := &configgrpc.GRPCServerSettings{ + defaultGRPCSettings := &configgrpc.ServerConfig{ NetAddr: confignet.NetAddr{ Endpoint: testutil.GetAvailableLocalAddress(t), Transport: "tcp", @@ -198,7 +198,7 @@ func TestCreateMetricReceiver(t *testing.T) { name: "invalid_grpc_address", cfg: &Config{ Protocols: Protocols{ - GRPC: &configgrpc.GRPCServerSettings{ + GRPC: &configgrpc.ServerConfig{ NetAddr: confignet.NetAddr{ Endpoint: "327.0.0.1:1122", Transport: "tcp", @@ -271,7 +271,7 @@ func TestCreateMetricReceiver(t *testing.T) { func TestCreateLogReceiver(t *testing.T) { factory := NewFactory() - defaultGRPCSettings := &configgrpc.GRPCServerSettings{ + defaultGRPCSettings := &configgrpc.ServerConfig{ NetAddr: confignet.NetAddr{ Endpoint: testutil.GetAvailableLocalAddress(t), Transport: "tcp", @@ -307,7 +307,7 @@ func TestCreateLogReceiver(t *testing.T) { name: "invalid_grpc_address", cfg: &Config{ Protocols: Protocols{ - GRPC: &configgrpc.GRPCServerSettings{ + GRPC: &configgrpc.ServerConfig{ NetAddr: confignet.NetAddr{ Endpoint: "327.0.0.1:1122", Transport: "tcp", diff --git a/receiver/otlpreceiver/otlp_test.go b/receiver/otlpreceiver/otlp_test.go index 24615227d0a..81728fbd625 100644 --- a/receiver/otlpreceiver/otlp_test.go +++ b/receiver/otlpreceiver/otlp_test.go @@ -633,7 +633,7 @@ func TestOTLPReceiverHTTPTracesIngestTest(t *testing.T) { func TestGRPCInvalidTLSCredentials(t *testing.T) { cfg := &Config{ Protocols: Protocols{ - GRPC: &configgrpc.GRPCServerSettings{ + GRPC: &configgrpc.ServerConfig{ NetAddr: confignet.NetAddr{ Endpoint: testutil.GetAvailableLocalAddress(t), Transport: "tcp",