Skip to content

Commit fb2718d

Browse files
authored
[pkg/ottl] Add new silent ErrorMode (#29710)
**Description:** Adds a new ErrorMode, `silent`, that `StatementSequence` and `ConditionSequence` can use to disable logging when ignoring errors. **Link to tracking Issue:** Closes #22743 **Testing:** Updated unit tests **Documentation:** Updated READMEs and godoc comments.
1 parent 536635f commit fb2718d

File tree

8 files changed

+94
-16
lines changed

8 files changed

+94
-16
lines changed

.chloggen/ottl-silent-error-mode.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: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: pkg/ottl
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Add `silent` ErrorMode to allow disabling logging of errors that are ignored.
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: [29710]
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: []

connector/routingconnector/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ The following settings are available:
3535
- `table.statement (required)`: the routing condition provided as the [OTTL] statement.
3636
- `table.pipelines (required)`: the list of pipelines to use when the routing condition is met.
3737
- `default_pipelines (optional)`: contains the list of pipelines to use when a record does not meet any of specified conditions.
38-
- `error_mode (optional)`: determines how errors returned from OTTL statements are handled. Valid values are `ignore` and `propagate`. If `ignored` is used and a statement's condition has an error then the payload will be routed to the default pipelines. If not supplied, `propagate` is used.
38+
- `error_mode (optional)`: determines how errors returned from OTTL statements are handled. Valid values are `propagate`, `ignore` and `silent`. If `ignored` or `silent` is used and a statement's condition has an error then the payload will be routed to the default pipelines. When `silent` is used the error is not logged. If not supplied, `propagate` is used.
3939

4040
Example:
4141

pkg/ottl/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ type ErrorMode string
1313
const (
1414
IgnoreError ErrorMode = "ignore"
1515
PropagateError ErrorMode = "propagate"
16+
SilentError ErrorMode = "silent"
1617
)
1718

1819
func (e *ErrorMode) UnmarshalText(text []byte) error {
1920
str := ErrorMode(strings.ToLower(string(text)))
2021
switch str {
21-
case IgnoreError, PropagateError:
22+
case IgnoreError, PropagateError, SilentError:
2223
*e = str
2324
return nil
2425
default:

pkg/ottl/parser.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ func NewStatementSequence[K any](statements []*Statement[K], telemetrySettings c
260260
// Execute is a function that will execute all the statements in the StatementSequence list.
261261
// When the ErrorMode of the StatementSequence is `propagate`, errors cause the execution to halt and the error is returned.
262262
// When the ErrorMode of the StatementSequence is `ignore`, errors are logged and execution continues to the next statement.
263+
// When the ErrorMode of the StatementSequence is `silent`, errors are not logged and execution continues to the next statement.
263264
func (s *StatementSequence[K]) Execute(ctx context.Context, tCtx K) error {
264265
for _, statement := range s.statements {
265266
_, _, err := statement.Execute(ctx, tCtx)
@@ -268,7 +269,9 @@ func (s *StatementSequence[K]) Execute(ctx context.Context, tCtx K) error {
268269
err = fmt.Errorf("failed to execute statement: %v, %w", statement.origText, err)
269270
return err
270271
}
271-
s.telemetrySettings.Logger.Warn("failed to execute statement", zap.Error(err), zap.String("statement", statement.origText))
272+
if s.errorMode == IgnoreError {
273+
s.telemetrySettings.Logger.Warn("failed to execute statement", zap.Error(err), zap.String("statement", statement.origText))
274+
}
272275
}
273276
}
274277
return nil
@@ -323,7 +326,8 @@ func NewConditionSequence[K any](conditions []*Condition[K], telemetrySettings c
323326
// If using the default OR LogicOperation, if any Condition evaluates to true, then true is returned and if all Conditions evaluate to false, then false is returned.
324327
// If using the AND LogicOperation, if any Condition evaluates to false, then false is returned and if all Conditions evaluate to true, then true is returned.
325328
// When the ErrorMode of the ConditionSequence is `propagate`, errors cause the evaluation to be false and an error is returned.
326-
// When the ErrorMode of the ConditionSequence is `ignore`, errors cause the evaluation to continue to the next condition.
329+
// When the ErrorMode of the ConditionSequence is `ignore`, errors are logged and cause the evaluation to continue to the next condition.
330+
// When the ErrorMode of the ConditionSequence is `silent`, errors are not logged and cause the evaluation to continue to the next condition.
327331
// When using the AND LogicOperation with the `ignore` ErrorMode the sequence will evaluate to false if all conditions error.
328332
func (c *ConditionSequence[K]) Eval(ctx context.Context, tCtx K) (bool, error) {
329333
var atLeastOneMatch bool
@@ -334,7 +338,9 @@ func (c *ConditionSequence[K]) Eval(ctx context.Context, tCtx K) (bool, error) {
334338
err = fmt.Errorf("failed to eval condition: %v, %w", condition.origText, err)
335339
return false, err
336340
}
337-
c.telemetrySettings.Logger.Warn("failed to eval condition", zap.Error(err), zap.String("condition", condition.origText))
341+
if c.errorMode == IgnoreError {
342+
c.telemetrySettings.Logger.Warn("failed to eval condition", zap.Error(err), zap.String("condition", condition.origText))
343+
}
338344
continue
339345
}
340346
if match {

pkg/ottl/parser_test.go

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,6 +2091,26 @@ func Test_Statements_Execute_Error(t *testing.T) {
20912091
},
20922092
errorMode: PropagateError,
20932093
},
2094+
{
2095+
name: "SilentError error from condition",
2096+
condition: func(context.Context, any) (bool, error) {
2097+
return true, fmt.Errorf("test")
2098+
},
2099+
function: func(ctx context.Context, tCtx any) (any, error) {
2100+
return 1, nil
2101+
},
2102+
errorMode: SilentError,
2103+
},
2104+
{
2105+
name: "SilentError error from function",
2106+
condition: func(context.Context, any) (bool, error) {
2107+
return true, nil
2108+
},
2109+
function: func(ctx context.Context, tCtx any) (any, error) {
2110+
return 1, fmt.Errorf("test")
2111+
},
2112+
errorMode: SilentError,
2113+
},
20942114
}
20952115
for _, tt := range tests {
20962116
t.Run(tt.name, func(t *testing.T) {
@@ -2262,14 +2282,32 @@ func Test_ConditionSequence_Eval_Error(t *testing.T) {
22622282
errorMode ErrorMode
22632283
}{
22642284
{
2265-
name: "Propagate Error from function",
2285+
name: "Propagate Error from condition",
22662286
conditions: []boolExpressionEvaluator[any]{
22672287
func(context.Context, any) (bool, error) {
22682288
return true, fmt.Errorf("test")
22692289
},
22702290
},
22712291
errorMode: PropagateError,
22722292
},
2293+
{
2294+
name: "Ignore Error from function with IgnoreError",
2295+
conditions: []boolExpressionEvaluator[any]{
2296+
func(context.Context, any) (bool, error) {
2297+
return true, fmt.Errorf("test")
2298+
},
2299+
},
2300+
errorMode: IgnoreError,
2301+
},
2302+
{
2303+
name: "Ignore Error from function with SilentError",
2304+
conditions: []boolExpressionEvaluator[any]{
2305+
func(context.Context, any) (bool, error) {
2306+
return true, fmt.Errorf("test")
2307+
},
2308+
},
2309+
errorMode: SilentError,
2310+
},
22732311
}
22742312
for _, tt := range tests {
22752313
t.Run(tt.name, func(t *testing.T) {
@@ -2287,8 +2325,12 @@ func Test_ConditionSequence_Eval_Error(t *testing.T) {
22872325
}
22882326

22892327
result, err := conditions.Eval(context.Background(), nil)
2290-
assert.Error(t, err)
22912328
assert.False(t, result)
2329+
if tt.errorMode == PropagateError {
2330+
assert.Error(t, err)
2331+
} else {
2332+
assert.NoError(t, err)
2333+
}
22922334
})
22932335
}
22942336
}

processor/filterprocessor/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ If all datapoints for a metric are dropped, the metric will also be dropped.
4848

4949
The filter processor also allows configuring an optional field, `error_mode`, which will determine how the processor reacts to errors that occur while processing an OTTL condition.
5050

51-
| error_mode | description |
52-
|-----------------------|----------------------------------------------------------------------------------------------------------------------------|
53-
| ignore | The processor ignores errors returned by conditions and continues on to the next condition. This is the recommended mode. |
54-
| propagate | The processor returns the error up the pipeline. This will result in the payload being dropped from the collector. |
51+
| error_mode | description |
52+
|------------|----------------------------------------------------------------------------------------------------------------------------------------|
53+
| ignore | The processor ignores errors returned by conditions, logs them, and continues on to the next condition. This is the recommended mode. |
54+
| silent | The processor ignores errors returned by conditions, does not log them, and continues on to the next condition. |
55+
| propagate | The processor returns the error up the pipeline. This will result in the payload being dropped from the collector. |
5556

5657
If not specified, `propagate` will be used.
5758

processor/routingprocessor/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ To configure the routing processor with [OTTL] routing conditions use the follow
7171
- `table.statement (required)`: the routing condition provided as the [OTTL] statement.
7272
- `table.exporters (required)`: the list of exporters to use when the routing condition is met.
7373
- `default_exporters (optional)`: contains the list of exporters to use when a record does not meet any of specified conditions.
74-
- `error_mode (optional)`: determines how errors returned from OTTL statements are handled. Valid values are `ignore` and `propagate`. If `ignored` is used and a statement's condition has an error then the payload will be routed to the default exporter. If not supplied, `propagate` is used.
74+
- `error_mode (optional)`: determines how errors returned from OTTL statements are handled. Valid values are `ignore` and `propagate`. If `ignored` or `silent` is used and a statement's condition has an error then the payload will be routed to the default exporter. When `silent` is used the error is not logged. If not supplied, `propagate` is used.
7575

7676

7777
```yaml

processor/transformprocessor/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ Each context will be processed in the order specified and each statement for a c
3737

3838
The transform processor also allows configuring an optional field, `error_mode`, which will determine how the processor reacts to errors that occur while processing a statement.
3939

40-
| error_mode | description |
41-
|-----------------------|----------------------------------------------------------------------------------------------------------------------------|
42-
| ignore | The processor ignores errors returned by statements and continues on to the next statement. This is the recommended mode. |
43-
| propagate | The processor returns the error up the pipeline. This will result in the payload being dropped from the collector. |
40+
| error_mode | description |
41+
|------------|---------------------------------------------------------------------------------------------------------------------------------------------|
42+
| ignore | The processor ignores errors returned by statements, logs the error, and continues on to the next statement. This is the recommended mode. |
43+
| silent | The processor ignores errors returned by statements, does not log the error, and continues on to the next statement. |
44+
| propagate | The processor returns the error up the pipeline. This will result in the payload being dropped from the collector. |
4445

4546
If not specified, `propagate` will be used.
4647

0 commit comments

Comments
 (0)