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
27 changes: 27 additions & 0 deletions .chloggen/mx-psi_configoptional-exporter-pulsar.yaml
Original file line number Diff line number Diff line change
@@ -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]
45 changes: 25 additions & 20 deletions exporter/pulsarexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
})
}

Expand Down
3 changes: 2 additions & 1 deletion exporter/pulsarexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion exporter/pulsarexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down