Skip to content

Commit

Permalink
[connector/routing] Fix config validation with context other than res…
Browse files Browse the repository at this point in the history
…ource (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. #1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Fixes open-telemetry#37410

---------

Co-authored-by: Andrzej Stencel <[email protected]>
  • Loading branch information
vlaborie and andrzej-stencel authored Jan 29, 2025
1 parent d74ba54 commit 992002f
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 2 deletions.
27 changes: 27 additions & 0 deletions .chloggen/fix-routing-connector-context-regression.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: connector/routing

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fix config validation with context other than `resource`

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [37410]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
3 changes: 1 addition & 2 deletions connector/routingconnector/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,14 @@ func (c *Config) Validate() error {
}

switch item.Context {
case "", "resource": // ok
case "", "resource", "span", "metric", "datapoint", "log": // ok
case "request":
if item.Statement != "" || item.Condition == "" {
return fmt.Errorf("%q context requires a 'condition'", item.Context)
}
if _, err := parseRequestCondition(item.Condition); err != nil {
return err
}
fallthrough
default:
return errors.New("invalid context: " + item.Context)
}
Expand Down
126 changes: 126 additions & 0 deletions connector/routingconnector/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,20 @@ func TestValidateConfig(t *testing.T) {
},
error: `"request" context requires a 'condition'`,
},
{
name: "request context with condition",
config: &Config{
Table: []RoutingTableItem{
{
Context: "request",
Condition: `request["attr"] == "acme"`,
Pipelines: []pipeline.ID{
pipeline.NewIDWithName(pipeline.SignalTraces, "otlp"),
},
},
},
},
},
{
name: "request context with invalid condition",
config: &Config{
Expand All @@ -248,6 +262,118 @@ func TestValidateConfig(t *testing.T) {
},
error: `condition must have format 'request["<name>"] <comparator> <value>'`,
},
{
name: "span context with statement",
config: &Config{
Table: []RoutingTableItem{
{
Context: "span",
Statement: `route() where attributes["attr"] == "acme"`,
Pipelines: []pipeline.ID{
pipeline.NewIDWithName(pipeline.SignalTraces, "otlp"),
},
},
},
},
},
{
name: "span context with condition",
config: &Config{
Table: []RoutingTableItem{
{
Context: "span",
Condition: `attributes["attr"] == "acme"`,
Pipelines: []pipeline.ID{
pipeline.NewIDWithName(pipeline.SignalTraces, "otlp"),
},
},
},
},
},
{
name: "metric context with statement",
config: &Config{
Table: []RoutingTableItem{
{
Context: "metric",
Statement: `route() where instrumentation_scope.attributes["attr"] == "acme"`,
Pipelines: []pipeline.ID{
pipeline.NewIDWithName(pipeline.SignalTraces, "otlp"),
},
},
},
},
},
{
name: "metric context with condition",
config: &Config{
Table: []RoutingTableItem{
{
Context: "metric",
Condition: `instrumentation_scope.attributes["attr"] == "acme"`,
Pipelines: []pipeline.ID{
pipeline.NewIDWithName(pipeline.SignalTraces, "otlp"),
},
},
},
},
},
{
name: "datapoint context with statement",
config: &Config{
Table: []RoutingTableItem{
{
Context: "datapoint",
Statement: `route() where attributes["attr"] == "acme"`,
Pipelines: []pipeline.ID{
pipeline.NewIDWithName(pipeline.SignalTraces, "otlp"),
},
},
},
},
},
{
name: "datapoint context with condition",
config: &Config{
Table: []RoutingTableItem{
{
Context: "datapoint",
Condition: `attributes["attr"] == "acme"`,
Pipelines: []pipeline.ID{
pipeline.NewIDWithName(pipeline.SignalTraces, "otlp"),
},
},
},
},
},
{
name: "log context with statement",
config: &Config{
Table: []RoutingTableItem{
{
Context: "log",
Statement: `route() where attributes["attr"] == "acme"`,
Pipelines: []pipeline.ID{
pipeline.NewIDWithName(pipeline.SignalTraces, "otlp"),
},
},
},
},
},
{
name: "log context with condition",
config: &Config{
Table: []RoutingTableItem{
{
Context: "log",
Condition: `attributes["attr"] == "acme"`,
Pipelines: []pipeline.ID{
pipeline.NewIDWithName(pipeline.SignalTraces, "otlp"),
},
},
},
},
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 992002f

Please sign in to comment.