Skip to content

Commit caf3600

Browse files
rcroweAneurysm9
andauthored
[exporter/kafkaexporter] Fix SASL config validation panic when not present (#24798)
**Description:** Ignore validating SASL auth config when it's not present. Fixes: #24797 --------- Signed-off-by: Rob Crowe <[email protected]> Co-authored-by: Anthony Mirabella <[email protected]>
1 parent 1c47e4f commit caf3600

File tree

3 files changed

+81
-12
lines changed

3 files changed

+81
-12
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Use this changelog template to create an entry for release notes.
2+
# If your change doesn't affect end users, such as a test fix or a tooling change,
3+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
4+
5+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
6+
change_type: bug_fix
7+
8+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
9+
component: exporter/kafkaexporter
10+
11+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
12+
note: Fixes a panic when SASL configuration is not present
13+
14+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
15+
issues: [24797]
16+
17+
# (Optional) One or more lines of additional information to render under the primary note.
18+
# These lines will be padded with 2 spaces and then inserted directly into the document.
19+
# Use pipe (|) for multiline entries.
20+
subtext:

exporter/kafkaexporter/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ func (cfg *Config) Validate() error {
104104
}
105105

106106
func validateSASLConfig(c *SASLConfig) error {
107+
if c == nil {
108+
return nil
109+
}
110+
107111
if c.Username == "" {
108112
return fmt.Errorf("auth.sasl.username is required")
109113
}

exporter/kafkaexporter/config_test.go

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,66 @@ func TestLoadConfig(t *testing.T) {
2828

2929
tests := []struct {
3030
id component.ID
31+
option func(conf *Config)
3132
expected component.Config
3233
}{
3334
{
3435
id: component.NewIDWithName(metadata.Type, ""),
36+
option: func(conf *Config) {
37+
// intentionally left blank so we use default config
38+
},
39+
expected: &Config{
40+
TimeoutSettings: exporterhelper.TimeoutSettings{
41+
Timeout: 10 * time.Second,
42+
},
43+
RetrySettings: exporterhelper.RetrySettings{
44+
Enabled: true,
45+
InitialInterval: 10 * time.Second,
46+
MaxInterval: 1 * time.Minute,
47+
MaxElapsedTime: 10 * time.Minute,
48+
RandomizationFactor: backoff.DefaultRandomizationFactor,
49+
Multiplier: backoff.DefaultMultiplier,
50+
},
51+
QueueSettings: exporterhelper.QueueSettings{
52+
Enabled: true,
53+
NumConsumers: 2,
54+
QueueSize: 10,
55+
},
56+
Topic: "spans",
57+
Encoding: "otlp_proto",
58+
Brokers: []string{"foo:123", "bar:456"},
59+
Authentication: Authentication{
60+
PlainText: &PlainTextConfig{
61+
Username: "jdoe",
62+
Password: "pass",
63+
},
64+
},
65+
Metadata: Metadata{
66+
Full: false,
67+
Retry: MetadataRetry{
68+
Max: 15,
69+
Backoff: defaultMetadataRetryBackoff,
70+
},
71+
},
72+
Producer: Producer{
73+
MaxMessageBytes: 10000000,
74+
RequiredAcks: sarama.WaitForAll,
75+
Compression: "none",
76+
},
77+
},
78+
},
79+
{
80+
id: component.NewIDWithName(metadata.Type, ""),
81+
option: func(conf *Config) {
82+
conf.Authentication = Authentication{
83+
SASL: &SASLConfig{
84+
Username: "jdoe",
85+
Password: "pass",
86+
Mechanism: "PLAIN",
87+
Version: 0,
88+
},
89+
}
90+
},
3591
expected: &Config{
3692
TimeoutSettings: exporterhelper.TimeoutSettings{
3793
Timeout: 10 * time.Second,
@@ -82,18 +138,7 @@ func TestLoadConfig(t *testing.T) {
82138

83139
for _, tt := range tests {
84140
t.Run(tt.id.String(), func(t *testing.T) {
85-
cfg := applyConfigOption(func(conf *Config) {
86-
// config.Validate() reads the Authentication.SASL struct, but it's not present
87-
// in the default config. This sets it to avoid a segfault during testing.
88-
conf.Authentication = Authentication{
89-
SASL: &SASLConfig{
90-
Username: "jdoe",
91-
Password: "pass",
92-
Mechanism: "PLAIN",
93-
Version: 0,
94-
},
95-
}
96-
})
141+
cfg := applyConfigOption(tt.option)
97142

98143
sub, err := cm.Sub(tt.id.String())
99144
require.NoError(t, err)

0 commit comments

Comments
 (0)