diff --git a/.chloggen/mx-psi_configoptional-exporter-pulsar.yaml b/.chloggen/mx-psi_configoptional-exporter-pulsar.yaml new file mode 100644 index 0000000000000..4fab3e4f83385 --- /dev/null +++ b/.chloggen/mx-psi_configoptional-exporter-pulsar.yaml @@ -0,0 +1,27 @@ +# 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. filelogreceiver) +component: pulsarexporter + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Use `configoptional.Optional` for authentication fields + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [41723] + +# (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: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# 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] diff --git a/exporter/pulsarexporter/config.go b/exporter/pulsarexporter/config.go index 8b7be7e09d19b..7dcaa06ac539f 100644 --- a/exporter/pulsarexporter/config.go +++ b/exporter/pulsarexporter/config.go @@ -10,6 +10,7 @@ import ( "github.com/apache/pulsar-client-go/pulsar" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/configopaque" + "go.opentelemetry.io/collector/config/configoptional" "go.opentelemetry.io/collector/config/configretry" "go.opentelemetry.io/collector/exporter/exporterhelper" ) @@ -39,10 +40,10 @@ type Config struct { } type Authentication struct { - TLS *TLS `mapstructure:"tls"` - Token *Token `mapstructure:"token"` - Athenz *Athenz `mapstructure:"athenz"` - OAuth2 *OAuth2 `mapstructure:"oauth2"` + TLS configoptional.Optional[TLS] `mapstructure:"tls"` + Token configoptional.Optional[Token] `mapstructure:"token"` + Athenz configoptional.Optional[Athenz] `mapstructure:"athenz"` + OAuth2 configoptional.Optional[OAuth2] `mapstructure:"oauth2"` } type TLS struct { @@ -95,28 +96,32 @@ func (*Config) Validate() error { func (cfg *Config) auth() pulsar.Authentication { authentication := cfg.Authentication - if authentication.TLS != nil { - return pulsar.NewAuthenticationTLS(authentication.TLS.CertFile, authentication.TLS.KeyFile) + if authentication.TLS.HasValue() { + tlsCfg := authentication.TLS.Get() + return pulsar.NewAuthenticationTLS(tlsCfg.CertFile, tlsCfg.KeyFile) } - if authentication.Token != nil { - return pulsar.NewAuthenticationToken(string(authentication.Token.Token)) + if authentication.Token.HasValue() { + tokenCfg := authentication.Token.Get() + return pulsar.NewAuthenticationToken(string(tokenCfg.Token)) } - if authentication.OAuth2 != nil { + if authentication.OAuth2.HasValue() { + oauth2Cfg := authentication.OAuth2.Get() return pulsar.NewAuthenticationOAuth2(map[string]string{ - "issuerUrl": authentication.OAuth2.IssuerURL, - "clientId": authentication.OAuth2.ClientID, - "audience": authentication.OAuth2.Audience, + "issuerUrl": oauth2Cfg.IssuerURL, + "clientId": oauth2Cfg.ClientID, + "audience": oauth2Cfg.Audience, }) } - if authentication.Athenz != nil { + if authentication.Athenz.HasValue() { + athenzCfg := authentication.Athenz.Get() return pulsar.NewAuthenticationAthenz(map[string]string{ - "providerDomain": authentication.Athenz.ProviderDomain, - "tenantDomain": authentication.Athenz.TenantDomain, - "tenantService": authentication.Athenz.TenantService, - "privateKey": string(authentication.Athenz.PrivateKey), - "keyId": authentication.Athenz.KeyID, - "principalHeader": authentication.Athenz.PrincipalHeader, - "ztsUrl": authentication.Athenz.ZtsURL, + "providerDomain": athenzCfg.ProviderDomain, + "tenantDomain": athenzCfg.TenantDomain, + "tenantService": athenzCfg.TenantService, + "privateKey": string(athenzCfg.PrivateKey), + "keyId": athenzCfg.KeyID, + "principalHeader": athenzCfg.PrincipalHeader, + "ztsUrl": athenzCfg.ZtsURL, }) } diff --git a/exporter/pulsarexporter/config_test.go b/exporter/pulsarexporter/config_test.go index b2b6047e3a902..a09fba7118551 100644 --- a/exporter/pulsarexporter/config_test.go +++ b/exporter/pulsarexporter/config_test.go @@ -13,6 +13,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config/configoptional" "go.opentelemetry.io/collector/config/configretry" "go.opentelemetry.io/collector/confmap/confmaptest" "go.opentelemetry.io/collector/confmap/xconfmap" @@ -55,7 +56,7 @@ func TestLoadConfig(t *testing.T) { Topic: "spans", Encoding: "otlp-spans", TLSTrustCertsFilePath: "ca.pem", - Authentication: Authentication{TLS: &TLS{CertFile: "cert.pem", KeyFile: "key.pem"}}, + Authentication: Authentication{TLS: configoptional.Some(TLS{CertFile: "cert.pem", KeyFile: "key.pem"})}, MaxConnectionsPerBroker: 1, ConnectionTimeout: 5 * time.Second, OperationTimeout: 30 * time.Second, diff --git a/exporter/pulsarexporter/go.mod b/exporter/pulsarexporter/go.mod index 6e8921bd617ee..03fd30a7d08ad 100644 --- a/exporter/pulsarexporter/go.mod +++ b/exporter/pulsarexporter/go.mod @@ -13,6 +13,7 @@ require ( go.opentelemetry.io/collector/component v1.37.0 go.opentelemetry.io/collector/component/componenttest v0.131.0 go.opentelemetry.io/collector/config/configopaque v1.37.0 + go.opentelemetry.io/collector/config/configoptional v0.131.0 go.opentelemetry.io/collector/config/configretry v1.37.0 go.opentelemetry.io/collector/confmap v1.37.0 go.opentelemetry.io/collector/confmap/xconfmap v0.131.0 @@ -82,7 +83,6 @@ require ( github.com/x448/float16 v0.8.4 // indirect go.opentelemetry.io/auto/sdk v1.1.0 // indirect go.opentelemetry.io/collector/client v1.37.0 // indirect - go.opentelemetry.io/collector/config/configoptional v0.131.0 // indirect go.opentelemetry.io/collector/consumer/consumertest v0.131.0 // indirect go.opentelemetry.io/collector/consumer/xconsumer v0.131.0 // indirect go.opentelemetry.io/collector/exporter/xexporter v0.131.0 // indirect