Commit 265799d
[pkg/stanza]: fix operator field config validation (open-telemetry#40728)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
A few operators with `entry.Field` in their config were validating their
configuration in their `Build` function via a comparison to
`entry.NewNilField`. This was an inaccuracy; when a field is not
provided during the unmarshal step, nothing ever gets run to actually
construct the underlying struct field, meaning that the `entry.Field`
was functionally set to `entry.Field{}`. This is not the same as
`entry.NewNilField` which actually implements and supplies an interface
value under the hood. This caused bad configs to pass validation and led
to collector panic instead of nice failure messages.
This PR changed `entry.NewNilField` to actually produce the correct
pattern for a "nil field", while leaving the original implementation
intact in `entry.NewNoopField` in case it is useful elsewhere (though at
the moment I only saw it used for nil comparisons, which as far as I can
tell were either never useful or something got refactored without being
caught). I also added functionality to
`operatortest.ConfigUnmarshalTest` to check for validation failures by
expecting a particular error when calling the operator's `Build` method.
<!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Addresses a panic discovered by open-telemetry#40398.
<!--Describe what testing was performed and which tests were added.-->
#### Testing
Tests were added to each operator's config validation. I tested manually
via a built collector by running the config from the linked issue and
confirming that instead of `panic` I get an error message.
```shell
2025-06-15T01:53:10.582Z info [email protected]/service.go:199 Setting up own telemetry... {"resource": {}}
2025-06-15T01:53:10.582Z info builders/builders.go:26 Development component. May change in the future. {"resource": {}, "otelcol.component.id": "debug", "otelcol.component.kind": "exporter", "otelcol.signal": "logs"}
Error: failed to build pipelines: failed to create "filelog/my-app-name" receiver for data type "logs": remove: field is empty
2025/06/15 01:53:10 collector server run finished with error: failed to build pipelines: failed to create "filelog/my-app-name" receiver for data type "logs": remove: field is empty
```
---------
Co-authored-by: Andrzej Stencel <[email protected]>1 parent 4103fab commit 265799d
File tree
26 files changed
+304
-175
lines changed- .chloggen
- pkg/stanza
- entry
- operator
- helper
- input
- file
- syslog
- tcp
- udp
- operatortest
- parser/syslog
- transformer
- assignkeys
- copy
- testdata
- flatten
- move
- testdata
- recombine
- remove
- testdata
- pipeline
26 files changed
+304
-175
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
99 | 103 | | |
100 | 104 | | |
101 | 105 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
9 | 12 | | |
10 | 13 | | |
11 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
155 | | - | |
156 | | - | |
| 155 | + | |
| 156 | + | |
157 | 157 | | |
158 | 158 | | |
159 | | - | |
160 | | - | |
| 159 | + | |
| 160 | + | |
161 | 161 | | |
162 | 162 | | |
163 | | - | |
164 | | - | |
| 163 | + | |
| 164 | + | |
165 | 165 | | |
166 | 166 | | |
167 | | - | |
168 | | - | |
| 167 | + | |
| 168 | + | |
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
177 | | - | |
178 | | - | |
| 177 | + | |
| 178 | + | |
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
| |||
0 commit comments