Skip to content

Commit f970421

Browse files
authored
Operators with silent errors will log errors as debug and won't return an error (#35010)
An operator configured with silent errors shouldn't log errors while processing log entries. **Description:** Operators that are expected to sometimes fail, can result in error logs that are quite verbose. This aims to address this issue by getting rid of error logs that the user wishes to silence (debug logs instead). By making sure no error is returned, there won't be any need to worry about other components logging error logs. **Link to tracking Issue:** [Issue #35008](#35008) **Testing:** Manually tested as this is a matter of logs.
1 parent d5595bb commit f970421

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

.chloggen/operator-silent-error.yaml

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: pkg/stanza
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: An operator configured with silent errors shouldn't log errors while processing log entries.
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: [35008]
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: []

pkg/stanza/operator/helper/transformer.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,14 @@ func (t *TransformerOperator) HandleEntryError(ctx context.Context, entry *entry
102102
if t.OnError == SendOnError || t.OnError == SendOnErrorQuiet {
103103
writeErr := t.Write(ctx, entry)
104104
if writeErr != nil {
105-
return fmt.Errorf("failed to send entry after error: %w", writeErr)
105+
err = fmt.Errorf("failed to send entry after error: %w", writeErr)
106106
}
107107
}
108+
109+
if t.OnError == SendOnErrorQuiet || t.OnError == DropOnErrorQuiet {
110+
return nil
111+
}
112+
108113
return err
109114
}
110115

pkg/stanza/operator/helper/transformer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func TestTransformerDropOnErrorQuiet(t *testing.T) {
143143
}
144144

145145
err := transformer.ProcessWith(ctx, testEntry, transform)
146-
require.Error(t, err)
146+
require.NoError(t, err)
147147
output.AssertNotCalled(t, "Process", mock.Anything, mock.Anything)
148148

149149
// Test output logs
@@ -233,7 +233,7 @@ func TestTransformerSendOnErrorQuiet(t *testing.T) {
233233
}
234234

235235
err := transformer.ProcessWith(ctx, testEntry, transform)
236-
require.Error(t, err)
236+
require.NoError(t, err)
237237
output.AssertCalled(t, "Process", mock.Anything, mock.Anything)
238238

239239
// Test output logs

0 commit comments

Comments
 (0)