Skip to content

Commit

Permalink
[configgrpc] Deprecate GRPCClientSettings, use GRPCClientConfig instead
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme committed Jan 26, 2024
1 parent 9082cb1 commit 8a7b914
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 58 deletions.
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 GRPCClientConfig 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 GRPCClientConfig instead
type GRPCClientSettings = GRPCClientConfig

// GRPCClientConfig defines common settings for a gRPC client configuration.
type GRPCClientConfig 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 @@ -151,8 +155,8 @@ type GRPCServerSettings 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.GRPCClientConfig.Endpoint.
func (gcs *GRPCClientConfig) SanitizedEndpoint() string {
switch {
case gcs.isSchemeHTTP():
return strings.TrimPrefix(gcs.Endpoint, "http://")
Expand All @@ -163,19 +167,19 @@ func (gcs *GRPCClientSettings) SanitizedEndpoint() string {
}
}

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

func (gcs *GRPCClientSettings) isSchemeHTTPS() bool {
func (gcs *GRPCClientConfig) 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 *GRPCClientConfig) 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 @@ -184,7 +188,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 *GRPCClientConfig) toDialOptions(host component.Host, settings component.TelemetrySettings) ([]grpc.DialOption, error) {
var opts []grpc.DialOption
if configcompression.IsCompressed(gcs.Compression) {
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 := &GRPCClientConfig{
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 GRPCClientConfig
name string
host component.Host
}{
{
name: "test all with gzip compression",
settings: GRPCClientSettings{
settings: GRPCClientConfig{
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: GRPCClientConfig{
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: GRPCClientConfig{
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 GRPCClientConfig
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: GRPCClientConfig{
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: GRPCClientConfig{
Headers: nil,
Endpoint: "",
Compression: "",
Expand All @@ -279,7 +279,7 @@ func TestGRPCClientSettingsError(t *testing.T) {
},
{
err: "invalid balancer_name: test",
settings: GRPCClientSettings{
settings: GRPCClientConfig{
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: GRPCClientConfig{
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: GRPCClientConfig{
Endpoint: "localhost:1234",
Auth: &configauth.Authentication{AuthenticatorID: component.NewID("doesntexist")},
},
host: &mockHost{},
},
{
err: "unsupported compression type \"zlib\"",
settings: GRPCClientSettings{
settings: GRPCClientConfig{
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: GRPCClientConfig{
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: GRPCClientConfig{
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 := &GRPCClientConfig{
Headers: nil,
Endpoint: "",
Compression: "",
Expand Down Expand Up @@ -625,7 +625,7 @@ func TestHttpReception(t *testing.T) {
_ = s.Serve(ln)
}()

gcs := &GRPCClientSettings{
gcs := &GRPCClientConfig{
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 := &GRPCClientConfig{
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 := &GRPCClientConfig{
Endpoint: l.Addr().String(),
TLSSetting: configtls.TLSClientSetting{
Insecure: true,
Expand Down
4 changes: 2 additions & 2 deletions exporter/otlpexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (

// Config defines configuration for OTLP exporter.
type Config struct {
exporterhelper.TimeoutSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
exporterhelper.TimeoutSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded 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.GRPCClientConfig `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{
GRPCClientConfig: configgrpc.GRPCClientConfig{
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{
GRPCClientConfig: configgrpc.GRPCClientConfig{
Headers: map[string]configopaque.String{},
// Default to gzip compression
Compression: configcompression.Gzip,
Expand Down
26 changes: 13 additions & 13 deletions exporter/otlpexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestCreateDefaultConfig(t *testing.T) {
func TestCreateMetricsExporter(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig().(*Config)
cfg.GRPCClientSettings.Endpoint = testutil.GetAvailableLocalAddress(t)
cfg.GRPCClientConfig.Endpoint = testutil.GetAvailableLocalAddress(t)

set := exportertest.NewNopCreateSettings()
oexp, err := factory.CreateMetricsExporter(context.Background(), set, cfg)
Expand All @@ -58,7 +58,7 @@ func TestCreateTracesExporter(t *testing.T) {
{
name: "NoEndpoint",
config: &Config{
GRPCClientSettings: configgrpc.GRPCClientSettings{
GRPCClientConfig: configgrpc.GRPCClientConfig{
Endpoint: "",
},
},
Expand All @@ -67,7 +67,7 @@ func TestCreateTracesExporter(t *testing.T) {
{
name: "UseSecure",
config: &Config{
GRPCClientSettings: configgrpc.GRPCClientSettings{
GRPCClientConfig: configgrpc.GRPCClientConfig{
Endpoint: endpoint,
TLSSetting: configtls.TLSClientSetting{
Insecure: false,
Expand All @@ -78,7 +78,7 @@ func TestCreateTracesExporter(t *testing.T) {
{
name: "Keepalive",
config: &Config{
GRPCClientSettings: configgrpc.GRPCClientSettings{
GRPCClientConfig: configgrpc.GRPCClientConfig{
Endpoint: endpoint,
Keepalive: &configgrpc.KeepaliveClientConfig{
Time: 30 * time.Second,
Expand All @@ -91,7 +91,7 @@ func TestCreateTracesExporter(t *testing.T) {
{
name: "NoneCompression",
config: &Config{
GRPCClientSettings: configgrpc.GRPCClientSettings{
GRPCClientConfig: configgrpc.GRPCClientConfig{
Endpoint: endpoint,
Compression: "none",
},
Expand All @@ -100,7 +100,7 @@ func TestCreateTracesExporter(t *testing.T) {
{
name: "GzipCompression",
config: &Config{
GRPCClientSettings: configgrpc.GRPCClientSettings{
GRPCClientConfig: configgrpc.GRPCClientConfig{
Endpoint: endpoint,
Compression: configcompression.Gzip,
},
Expand All @@ -109,7 +109,7 @@ func TestCreateTracesExporter(t *testing.T) {
{
name: "SnappyCompression",
config: &Config{
GRPCClientSettings: configgrpc.GRPCClientSettings{
GRPCClientConfig: configgrpc.GRPCClientConfig{
Endpoint: endpoint,
Compression: configcompression.Snappy,
},
Expand All @@ -118,7 +118,7 @@ func TestCreateTracesExporter(t *testing.T) {
{
name: "ZstdCompression",
config: &Config{
GRPCClientSettings: configgrpc.GRPCClientSettings{
GRPCClientConfig: configgrpc.GRPCClientConfig{
Endpoint: endpoint,
Compression: configcompression.Zstd,
},
Expand All @@ -127,7 +127,7 @@ func TestCreateTracesExporter(t *testing.T) {
{
name: "Headers",
config: &Config{
GRPCClientSettings: configgrpc.GRPCClientSettings{
GRPCClientConfig: configgrpc.GRPCClientConfig{
Endpoint: endpoint,
Headers: map[string]configopaque.String{
"hdr1": "val1",
Expand All @@ -139,15 +139,15 @@ func TestCreateTracesExporter(t *testing.T) {
{
name: "NumConsumers",
config: &Config{
GRPCClientSettings: configgrpc.GRPCClientSettings{
GRPCClientConfig: configgrpc.GRPCClientConfig{
Endpoint: endpoint,
},
},
},
{
name: "CaCert",
config: &Config{
GRPCClientSettings: configgrpc.GRPCClientSettings{
GRPCClientConfig: configgrpc.GRPCClientConfig{
Endpoint: endpoint,
TLSSetting: configtls.TLSClientSetting{
TLSSetting: configtls.TLSSetting{
Expand All @@ -160,7 +160,7 @@ func TestCreateTracesExporter(t *testing.T) {
{
name: "CertPemFileError",
config: &Config{
GRPCClientSettings: configgrpc.GRPCClientSettings{
GRPCClientConfig: configgrpc.GRPCClientConfig{
Endpoint: endpoint,
TLSSetting: configtls.TLSClientSetting{
TLSSetting: configtls.TLSSetting{
Expand Down Expand Up @@ -204,7 +204,7 @@ func TestCreateTracesExporter(t *testing.T) {
func TestCreateLogsExporter(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig().(*Config)
cfg.GRPCClientSettings.Endpoint = testutil.GetAvailableLocalAddress(t)
cfg.GRPCClientConfig.Endpoint = testutil.GetAvailableLocalAddress(t)

set := exportertest.NewNopCreateSettings()
oexp, err := factory.CreateLogsExporter(context.Background(), set, cfg)
Expand Down
Loading

0 comments on commit 8a7b914

Please sign in to comment.