Skip to content

Commit e6ba064

Browse files
vlaborieandrzej-stencel
authored andcommitted
[connector/routing] Fix config validation with context other than resource (open-telemetry#37411)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Remove a residual fallthrough keyword which induce a configuration error <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes open-telemetry#37410 --------- Co-authored-by: Andrzej Stencel <[email protected]>
1 parent a26ae77 commit e6ba064

File tree

3 files changed

+154
-2
lines changed

3 files changed

+154
-2
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: connector/routing
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 with context other than `resource`
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: [37410]
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/config.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,14 @@ func (c *Config) Validate() error {
6565
}
6666

6767
switch item.Context {
68-
case "", "resource": // ok
68+
case "", "resource", "span", "metric", "datapoint", "log": // ok
6969
case "request":
7070
if item.Statement != "" || item.Condition == "" {
7171
return fmt.Errorf("%q context requires a 'condition'", item.Context)
7272
}
7373
if _, err := parseRequestCondition(item.Condition); err != nil {
7474
return err
7575
}
76-
fallthrough
7776
default:
7877
return errors.New("invalid context: " + item.Context)
7978
}

connector/routingconnector/config_test.go

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,20 @@ func TestValidateConfig(t *testing.T) {
233233
},
234234
error: `"request" context requires a 'condition'`,
235235
},
236+
{
237+
name: "request context with condition",
238+
config: &Config{
239+
Table: []RoutingTableItem{
240+
{
241+
Context: "request",
242+
Condition: `request["attr"] == "acme"`,
243+
Pipelines: []pipeline.ID{
244+
pipeline.NewIDWithName(pipeline.SignalTraces, "otlp"),
245+
},
246+
},
247+
},
248+
},
249+
},
236250
{
237251
name: "request context with invalid condition",
238252
config: &Config{
@@ -248,6 +262,118 @@ func TestValidateConfig(t *testing.T) {
248262
},
249263
error: `condition must have format 'request["<name>"] <comparator> <value>'`,
250264
},
265+
{
266+
name: "span context with statement",
267+
config: &Config{
268+
Table: []RoutingTableItem{
269+
{
270+
Context: "span",
271+
Statement: `route() where attributes["attr"] == "acme"`,
272+
Pipelines: []pipeline.ID{
273+
pipeline.NewIDWithName(pipeline.SignalTraces, "otlp"),
274+
},
275+
},
276+
},
277+
},
278+
},
279+
{
280+
name: "span context with condition",
281+
config: &Config{
282+
Table: []RoutingTableItem{
283+
{
284+
Context: "span",
285+
Condition: `attributes["attr"] == "acme"`,
286+
Pipelines: []pipeline.ID{
287+
pipeline.NewIDWithName(pipeline.SignalTraces, "otlp"),
288+
},
289+
},
290+
},
291+
},
292+
},
293+
{
294+
name: "metric context with statement",
295+
config: &Config{
296+
Table: []RoutingTableItem{
297+
{
298+
Context: "metric",
299+
Statement: `route() where instrumentation_scope.attributes["attr"] == "acme"`,
300+
Pipelines: []pipeline.ID{
301+
pipeline.NewIDWithName(pipeline.SignalTraces, "otlp"),
302+
},
303+
},
304+
},
305+
},
306+
},
307+
{
308+
name: "metric context with condition",
309+
config: &Config{
310+
Table: []RoutingTableItem{
311+
{
312+
Context: "metric",
313+
Condition: `instrumentation_scope.attributes["attr"] == "acme"`,
314+
Pipelines: []pipeline.ID{
315+
pipeline.NewIDWithName(pipeline.SignalTraces, "otlp"),
316+
},
317+
},
318+
},
319+
},
320+
},
321+
{
322+
name: "datapoint context with statement",
323+
config: &Config{
324+
Table: []RoutingTableItem{
325+
{
326+
Context: "datapoint",
327+
Statement: `route() where attributes["attr"] == "acme"`,
328+
Pipelines: []pipeline.ID{
329+
pipeline.NewIDWithName(pipeline.SignalTraces, "otlp"),
330+
},
331+
},
332+
},
333+
},
334+
},
335+
{
336+
name: "datapoint context with condition",
337+
config: &Config{
338+
Table: []RoutingTableItem{
339+
{
340+
Context: "datapoint",
341+
Condition: `attributes["attr"] == "acme"`,
342+
Pipelines: []pipeline.ID{
343+
pipeline.NewIDWithName(pipeline.SignalTraces, "otlp"),
344+
},
345+
},
346+
},
347+
},
348+
},
349+
{
350+
name: "log context with statement",
351+
config: &Config{
352+
Table: []RoutingTableItem{
353+
{
354+
Context: "log",
355+
Statement: `route() where attributes["attr"] == "acme"`,
356+
Pipelines: []pipeline.ID{
357+
pipeline.NewIDWithName(pipeline.SignalTraces, "otlp"),
358+
},
359+
},
360+
},
361+
},
362+
},
363+
{
364+
name: "log context with condition",
365+
config: &Config{
366+
Table: []RoutingTableItem{
367+
{
368+
Context: "log",
369+
Condition: `attributes["attr"] == "acme"`,
370+
Pipelines: []pipeline.ID{
371+
pipeline.NewIDWithName(pipeline.SignalTraces, "otlp"),
372+
},
373+
},
374+
},
375+
},
376+
},
251377
}
252378

253379
for _, tt := range tests {

0 commit comments

Comments
 (0)