Skip to content

Commit

Permalink
[configgrpc] Deprecate GRPCClientSettings, use ClientConfig instead (#…
Browse files Browse the repository at this point in the history
…9402)

**Description:**
Deprecate GRPCClientSettings, use ClientConfig instead

**Link to tracking Issue:**
#6767
  • Loading branch information
atoulme committed Feb 2, 2024
1 parent c5d86ce commit 3665732
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 57 deletions.
25 changes: 25 additions & 0 deletions .chloggen/grpcclientsettings_grpcclientconfig-otlpreceiver.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: otlpexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Config struct is moving from embedding the deprecated GRPCClientSettings struct to using ClientConfig 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]
25 changes: 25 additions & 0 deletions .chloggen/grpcclientsettings_grpcclientconfig.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: 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 GRPCClientSettings, use ClientConfig 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: []
18 changes: 11 additions & 7 deletions config/configgrpc/configgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ type KeepaliveClientConfig struct {
}

// GRPCClientSettings defines common settings for a gRPC client configuration.
type GRPCClientSettings struct {
// Deprecated: [v0.94.0] Use ClientConfig instead
type GRPCClientSettings = ClientConfig

// ClientConfig defines common settings for a gRPC client configuration.
type ClientConfig struct {
// The target to which the exporter is going to send traces or metrics,
// using the gRPC protocol. The valid syntax is described at
// https://github.com/grpc/grpc/blob/master/doc/naming.md.
Expand Down Expand Up @@ -155,8 +159,8 @@ type ServerConfig struct {
IncludeMetadata bool `mapstructure:"include_metadata"`
}

// SanitizedEndpoint strips the prefix of either http:// or https:// from configgrpc.GRPCClientSettings.Endpoint.
func (gcs *GRPCClientSettings) SanitizedEndpoint() string {
// SanitizedEndpoint strips the prefix of either http:// or https:// from configgrpc.ClientConfig.Endpoint.
func (gcs *ClientConfig) SanitizedEndpoint() string {
switch {
case gcs.isSchemeHTTP():
return strings.TrimPrefix(gcs.Endpoint, "http://")
Expand All @@ -167,19 +171,19 @@ func (gcs *GRPCClientSettings) SanitizedEndpoint() string {
}
}

func (gcs *GRPCClientSettings) isSchemeHTTP() bool {
func (gcs *ClientConfig) isSchemeHTTP() bool {
return strings.HasPrefix(gcs.Endpoint, "http://")
}

func (gcs *GRPCClientSettings) isSchemeHTTPS() bool {
func (gcs *ClientConfig) isSchemeHTTPS() bool {
return strings.HasPrefix(gcs.Endpoint, "https://")
}

// ToClientConn creates a client connection to the given target. By default, it's
// a non-blocking dial (the function won't wait for connections to be
// established, and connecting happens in the background). To make it a blocking
// dial, use grpc.WithBlock() dial option.
func (gcs *GRPCClientSettings) ToClientConn(ctx context.Context, host component.Host, settings component.TelemetrySettings, extraOpts ...grpc.DialOption) (*grpc.ClientConn, error) {
func (gcs *ClientConfig) ToClientConn(ctx context.Context, host component.Host, settings component.TelemetrySettings, extraOpts ...grpc.DialOption) (*grpc.ClientConn, error) {
opts, err := gcs.toDialOptions(host, settings)
if err != nil {
return nil, err
Expand All @@ -188,7 +192,7 @@ func (gcs *GRPCClientSettings) ToClientConn(ctx context.Context, host component.
return grpc.DialContext(ctx, gcs.SanitizedEndpoint(), opts...)
}

func (gcs *GRPCClientSettings) toDialOptions(host component.Host, settings component.TelemetrySettings) ([]grpc.DialOption, error) {
func (gcs *ClientConfig) toDialOptions(host component.Host, settings component.TelemetrySettings) ([]grpc.DialOption, error) {
var opts []grpc.DialOption
if gcs.Compression.IsCompressed() {
cp, err := getGRPCCompressionName(gcs.Compression)
Expand Down
36 changes: 18 additions & 18 deletions config/configgrpc/configgrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestDefaultGrpcClientSettings(t *testing.T) {
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) })

gcs := &GRPCClientSettings{
gcs := &ClientConfig{
TLSSetting: configtls.TLSClientSetting{
Insecure: true,
},
Expand All @@ -71,13 +71,13 @@ func TestAllGrpcClientSettings(t *testing.T) {
t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) })

tests := []struct {
settings GRPCClientSettings
settings ClientConfig
name string
host component.Host
}{
{
name: "test all with gzip compression",
settings: GRPCClientSettings{
settings: ClientConfig{
Headers: map[string]configopaque.String{
"test": "test",
},
Expand Down Expand Up @@ -106,7 +106,7 @@ func TestAllGrpcClientSettings(t *testing.T) {
},
{
name: "test all with snappy compression",
settings: GRPCClientSettings{
settings: ClientConfig{
Headers: map[string]configopaque.String{
"test": "test",
},
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestAllGrpcClientSettings(t *testing.T) {
},
{
name: "test all with zstd compression",
settings: GRPCClientSettings{
settings: ClientConfig{
Headers: map[string]configopaque.String{
"test": "test",
},
Expand Down Expand Up @@ -241,13 +241,13 @@ func TestGRPCClientSettingsError(t *testing.T) {
t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) })

tests := []struct {
settings GRPCClientSettings
settings ClientConfig
err string
host component.Host
}{
{
err: "^failed to load TLS config: failed to load CA CertPool File: failed to load cert /doesnt/exist:",
settings: GRPCClientSettings{
settings: ClientConfig{
Headers: nil,
Endpoint: "",
Compression: "",
Expand All @@ -263,7 +263,7 @@ func TestGRPCClientSettingsError(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: GRPCClientSettings{
settings: ClientConfig{
Headers: nil,
Endpoint: "",
Compression: "",
Expand All @@ -279,7 +279,7 @@ func TestGRPCClientSettingsError(t *testing.T) {
},
{
err: "invalid balancer_name: test",
settings: GRPCClientSettings{
settings: ClientConfig{
Headers: map[string]configopaque.String{
"test": "test",
},
Expand All @@ -301,23 +301,23 @@ func TestGRPCClientSettingsError(t *testing.T) {
},
{
err: "failed to resolve authenticator \"doesntexist\": authenticator not found",
settings: GRPCClientSettings{
settings: ClientConfig{
Endpoint: "localhost:1234",
Auth: &configauth.Authentication{AuthenticatorID: component.NewID("doesntexist")},
},
host: &mockHost{ext: map[component.ID]component.Component{}},
},
{
err: "no extensions configuration available",
settings: GRPCClientSettings{
settings: ClientConfig{
Endpoint: "localhost:1234",
Auth: &configauth.Authentication{AuthenticatorID: component.NewID("doesntexist")},
},
host: &mockHost{},
},
{
err: "unsupported compression type \"zlib\"",
settings: GRPCClientSettings{
settings: ClientConfig{
Endpoint: "localhost:1234",
TLSSetting: configtls.TLSClientSetting{
Insecure: true,
Expand All @@ -328,7 +328,7 @@ func TestGRPCClientSettingsError(t *testing.T) {
},
{
err: "unsupported compression type \"deflate\"",
settings: GRPCClientSettings{
settings: ClientConfig{
Endpoint: "localhost:1234",
TLSSetting: configtls.TLSClientSetting{
Insecure: true,
Expand All @@ -339,7 +339,7 @@ func TestGRPCClientSettingsError(t *testing.T) {
},
{
err: "unsupported compression type \"bad\"",
settings: GRPCClientSettings{
settings: ClientConfig{
Endpoint: "localhost:1234",
TLSSetting: configtls.TLSClientSetting{
Insecure: true,
Expand All @@ -363,7 +363,7 @@ func TestUseSecure(t *testing.T) {
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) })

gcs := &GRPCClientSettings{
gcs := &ClientConfig{
Headers: nil,
Endpoint: "",
Compression: "",
Expand Down Expand Up @@ -625,7 +625,7 @@ func TestHttpReception(t *testing.T) {
_ = s.Serve(ln)
}()

gcs := &GRPCClientSettings{
gcs := &ClientConfig{
Endpoint: ln.Addr().String(),
TLSSetting: *test.tlsClientCreds,
}
Expand Down Expand Up @@ -671,7 +671,7 @@ func TestReceiveOnUnixDomainSocket(t *testing.T) {
_ = srv.Serve(ln)
}()

gcs := &GRPCClientSettings{
gcs := &ClientConfig{
Endpoint: "unix://" + ln.Addr().String(),
TLSSetting: configtls.TLSClientSetting{
Insecure: true,
Expand Down Expand Up @@ -872,7 +872,7 @@ func TestClientInfoInterceptors(t *testing.T) {

// prepare the client and execute a RPC
{
gcs := &GRPCClientSettings{
gcs := &ClientConfig{
Endpoint: l.Addr().String(),
TLSSetting: configtls.TLSClientSetting{
Insecure: true,
Expand Down
2 changes: 1 addition & 1 deletion exporter/otlpexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Config struct {
QueueConfig exporterhelper.QueueSettings `mapstructure:"sending_queue"`
RetryConfig configretry.BackOffConfig `mapstructure:"retry_on_failure"`

configgrpc.GRPCClientSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
configgrpc.ClientConfig `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
}

var _ component.Config = (*Config)(nil)
2 changes: 1 addition & 1 deletion exporter/otlpexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestUnmarshalConfig(t *testing.T) {
NumConsumers: 2,
QueueSize: 10,
},
GRPCClientSettings: configgrpc.GRPCClientSettings{
ClientConfig: configgrpc.ClientConfig{
Headers: map[string]configopaque.String{
"can you have a . here?": "F0000000-0000-0000-0000-000000000000",
"header1": "234",
Expand Down
2 changes: 1 addition & 1 deletion exporter/otlpexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func createDefaultConfig() component.Config {
TimeoutSettings: exporterhelper.NewDefaultTimeoutSettings(),
RetryConfig: configretry.NewDefaultBackOffConfig(),
QueueConfig: exporterhelper.NewDefaultQueueSettings(),
GRPCClientSettings: configgrpc.GRPCClientSettings{
ClientConfig: configgrpc.ClientConfig{
Headers: map[string]configopaque.String{},
// Default to gzip compression
Compression: configcompression.Gzip,
Expand Down

0 comments on commit 3665732

Please sign in to comment.