Skip to content

Commit a7f5414

Browse files
mauri870zeck-ops
authored andcommitted
[processor/logdedup] fix config validation not working (open-telemetry#37278)
#### Description The Config struct has a Validate method but it is only used in tests. Ensure we validate the configuration when creating the processor.
1 parent aba4413 commit a7f5414

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: logdedupprocessor
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Fix config validation not working when creating a processor.
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [37278]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

processor/logdedupprocessor/factory.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ func createLogsProcessor(_ context.Context, settings processor.Settings, cfg com
3232
return nil, fmt.Errorf("invalid config type: %+v", cfg)
3333
}
3434

35+
if err := processorCfg.Validate(); err != nil {
36+
return nil, err
37+
}
38+
3539
processor, err := newProcessor(processorCfg, consumer, settings)
3640
if err != nil {
3741
return nil, fmt.Errorf("error creating processor: %w", err)

processor/logdedupprocessor/processor_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,24 @@ func TestProcessorConsumeMultipleConditions(t *testing.T) {
308308
err = p.Shutdown(context.Background())
309309
require.NoError(t, err)
310310
}
311+
312+
func TestProcessorConfigValidate(t *testing.T) {
313+
t.Parallel()
314+
invalidCfg := &Config{
315+
LogCountAttribute: defaultLogCountAttribute,
316+
Interval: -1,
317+
Timezone: "",
318+
}
319+
320+
_, err := createLogsProcessor(context.Background(), processortest.NewNopSettings(), invalidCfg, consumertest.NewNop())
321+
require.Error(t, err)
322+
323+
validCfg := &Config{
324+
LogCountAttribute: defaultLogCountAttribute,
325+
Interval: defaultInterval,
326+
Timezone: defaultTimezone,
327+
}
328+
329+
_, err = createLogsProcessor(context.Background(), processortest.NewNopSettings(), validCfg, consumertest.NewNop())
330+
require.NoError(t, err)
331+
}

0 commit comments

Comments
 (0)