Skip to content

Commit 1e41cec

Browse files
authored
[pkg/stanza] Fix - Operators with DropOnErrorQuiet should drop log en… (open-telemetry#35834)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Fixed issue in which Operators with DropOnErrorQuiet are not dropping log entries on error. Note: This issue was introduced by a bug fix meant to ensure Silent Operators are not logging errors (open-telemetry#35010). With this fix, this side effect bug has been resolved. <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes 35010 <!--Describe what testing was performed and which tests were added.--> #### Testing Added UT
1 parent f3348e7 commit 1e41cec

File tree

5 files changed

+74
-6
lines changed

5 files changed

+74
-6
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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: Fixed bug causing Operators with DropOnErrorQuiet to send log entries to the next operator.
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: [35010]
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+
This issue was introduced by a bug fix meant to ensure Silent Operators are not logging errors (#35010). With this fix,
20+
this side effect bug has been resolved.
21+
22+
# If your change doesn't affect end users or the exported elements of any package,
23+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
24+
# Optional: The change log or logs in which this entry should be included.
25+
# e.g. '[user]' or '[user, api]'
26+
# Include 'user' if the change is relevant to end users.
27+
# Include 'api' if there is a change to a library API.
28+
# Default: '[user]'
29+
change_logs: []

pkg/stanza/operator/helper/parser.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ func (p *ParserOperator) ProcessWithCallback(ctx context.Context, entry *entry.E
109109
}
110110

111111
if err = p.ParseWith(ctx, entry, parse); err != nil {
112+
if p.OnError == DropOnErrorQuiet || p.OnError == SendOnErrorQuiet {
113+
return nil
114+
}
115+
112116
return err
113117
}
114118
if cb != nil {

pkg/stanza/operator/helper/parser_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,25 @@ func TestParserInvalidParseDrop(t *testing.T) {
142142
fakeOut.ExpectNoEntry(t, 100*time.Millisecond)
143143
}
144144

145+
func TestParserInvalidParseDropQuiet(t *testing.T) {
146+
writer, fakeOut := writerWithFakeOut(t)
147+
parser := ParserOperator{
148+
TransformerOperator: TransformerOperator{
149+
WriterOperator: *writer,
150+
OnError: DropOnErrorQuiet,
151+
},
152+
ParseFrom: entry.NewBodyField(),
153+
}
154+
parse := func(i any) (any, error) {
155+
return i, fmt.Errorf("parse failure")
156+
}
157+
ctx := context.Background()
158+
testEntry := entry.New()
159+
err := parser.ProcessWith(ctx, testEntry, parse)
160+
require.NoError(t, err, "error should be silent")
161+
fakeOut.ExpectNoEntry(t, 100*time.Millisecond) // Entry should be dropped
162+
}
163+
145164
func TestParserInvalidParseSend(t *testing.T) {
146165
writer, fakeOut := writerWithFakeOut(t)
147166
parser := ParserOperator{
@@ -162,6 +181,26 @@ func TestParserInvalidParseSend(t *testing.T) {
162181
fakeOut.ExpectNoEntry(t, 100*time.Millisecond)
163182
}
164183

184+
func TestParserInvalidParseSendQuiet(t *testing.T) {
185+
writer, fakeOut := writerWithFakeOut(t)
186+
parser := ParserOperator{
187+
TransformerOperator: TransformerOperator{
188+
WriterOperator: *writer,
189+
OnError: SendOnErrorQuiet,
190+
},
191+
ParseFrom: entry.NewBodyField(),
192+
}
193+
parse := func(i any) (any, error) {
194+
return i, fmt.Errorf("parse failure")
195+
}
196+
ctx := context.Background()
197+
testEntry := entry.New()
198+
err := parser.ProcessWith(ctx, testEntry, parse)
199+
require.NoError(t, err, "error should be silent")
200+
fakeOut.ExpectEntry(t, testEntry)
201+
fakeOut.ExpectNoEntry(t, 100*time.Millisecond)
202+
}
203+
165204
func TestParserInvalidTimeParseDrop(t *testing.T) {
166205
writer, fakeOut := writerWithFakeOut(t)
167206
parser := ParserOperator{

pkg/stanza/operator/helper/transformer.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,6 @@ func (t *TransformerOperator) HandleEntryError(ctx context.Context, entry *entry
106106
}
107107
}
108108

109-
if t.OnError == SendOnErrorQuiet || t.OnError == DropOnErrorQuiet {
110-
return nil
111-
}
112-
113109
return err
114110
}
115111

pkg/stanza/operator/helper/transformer_test.go

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

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

147147
// Test output logs
@@ -231,7 +231,7 @@ func TestTransformerSendOnErrorQuiet(t *testing.T) {
231231
}
232232

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

237237
// Test output logs

0 commit comments

Comments
 (0)