Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[processor/transform] Report all parsing errors #24245

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .chloggen/tp-report-all-parsing-errors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use this changelog template to create an entry for release notes.
# If your change doesn't affect end users, such as a test fix or a tooling change,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.

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

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Report all errors from parsing OTTL statements

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

# (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:
13 changes: 8 additions & 5 deletions processor/transformprocessor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package transformprocessor // import "github.com/open-telemetry/opentelemetry-co

import (
"go.opentelemetry.io/collector/component"
"go.uber.org/multierr"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl"
Expand All @@ -31,6 +32,8 @@ type Config struct {
var _ component.Config = (*Config)(nil)

func (c *Config) Validate() error {
var errors error

if len(c.TraceStatements) > 0 {
pc, err := common.NewTraceParserCollection(component.TelemetrySettings{Logger: zap.NewNop()}, common.WithSpanParser(traces.SpanFunctions()), common.WithSpanEventParser(traces.SpanEventFunctions()))
if err != nil {
Expand All @@ -39,7 +42,7 @@ func (c *Config) Validate() error {
for _, cs := range c.TraceStatements {
_, err = pc.ParseContextStatements(cs)
if err != nil {
return err
errors = multierr.Append(errors, err)
}
}
}
Expand All @@ -50,9 +53,9 @@ func (c *Config) Validate() error {
return err
}
for _, cs := range c.MetricStatements {
_, err = pc.ParseContextStatements(cs)
_, err := pc.ParseContextStatements(cs)
if err != nil {
return err
errors = multierr.Append(errors, err)
}
}
}
Expand All @@ -65,10 +68,10 @@ func (c *Config) Validate() error {
for _, cs := range c.LogStatements {
_, err = pc.ParseContextStatements(cs)
if err != nil {
return err
errors = multierr.Append(errors, err)
}
}
}

return nil
return errors
}
13 changes: 12 additions & 1 deletion processor/transformprocessor/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/confmap/confmaptest"
"go.uber.org/multierr"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/common"
Expand All @@ -22,6 +23,7 @@ func TestLoadConfig(t *testing.T) {
tests := []struct {
id component.ID
expected component.Config
errorLen int64
}{
{
id: component.NewIDWithName(metadata.Type, ""),
Expand Down Expand Up @@ -108,6 +110,9 @@ func TestLoadConfig(t *testing.T) {
{
id: component.NewIDWithName(metadata.Type, "unknown_function_log"),
},
{
id: component.NewIDWithName(metadata.Type, "bad_syntax_multi_signal"),
},
}
for _, tt := range tests {
t.Run(tt.id.String(), func(t *testing.T) {
Expand All @@ -122,7 +127,13 @@ func TestLoadConfig(t *testing.T) {
assert.NoError(t, component.UnmarshalConfig(sub, cfg))

if tt.expected == nil {
assert.Error(t, component.ValidateConfig(cfg))
err = component.ValidateConfig(cfg)
assert.Error(t, err)

if tt.errorLen > 0 {
evan-bradley marked this conversation as resolved.
Show resolved Hide resolved
assert.Equal(t, tt.errorLen, len(multierr.Errors(err)))
}

return
}
assert.NoError(t, component.ValidateConfig(cfg))
Expand Down
8 changes: 7 additions & 1 deletion processor/transformprocessor/internal/logs/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/pdata/plog"
"go.uber.org/multierr"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl"
Expand All @@ -27,14 +28,19 @@ func NewProcessor(contextStatements []common.ContextStatements, errorMode ottl.E
}

contexts := make([]consumer.Logs, len(contextStatements))
var errors error
for i, cs := range contextStatements {
context, err := pc.ParseContextStatements(cs)
if err != nil {
return nil, err
errors = multierr.Append(errors, err)
}
contexts[i] = context
}

if errors != nil {
return nil, errors
}

return &Processor{
contexts: contexts,
logger: settings.Logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.uber.org/multierr"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl"
Expand All @@ -27,14 +28,19 @@ func NewProcessor(contextStatements []common.ContextStatements, errorMode ottl.E
}

contexts := make([]consumer.Metrics, len(contextStatements))
var errors error
for i, cs := range contextStatements {
context, err := pc.ParseContextStatements(cs)
if err != nil {
return nil, err
errors = multierr.Append(errors, err)
}
contexts[i] = context
}

if errors != nil {
return nil, errors
}

return &Processor{
contexts: contexts,
logger: settings.Logger,
Expand Down
8 changes: 7 additions & 1 deletion processor/transformprocessor/internal/traces/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/pdata/ptrace"
"go.uber.org/multierr"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl"
Expand All @@ -27,14 +28,19 @@ func NewProcessor(contextStatements []common.ContextStatements, errorMode ottl.E
}

contexts := make([]consumer.Traces, len(contextStatements))
var errors error
for i, cs := range contextStatements {
context, err := pc.ParseContextStatements(cs)
if err != nil {
return nil, err
errors = multierr.Append(errors, err)
}
contexts[i] = context
}

if errors != nil {
return nil, errors
}

return &Processor{
contexts: contexts,
logger: settings.Logger,
Expand Down
17 changes: 17 additions & 0 deletions processor/transformprocessor/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ transform/bad_syntax_trace:
- set(name, "bear" where attributes["http.path"] == "/animal"
- keep_keys(attributes, ["http.method", "http.path"])

transform/bad_syntax_multi_signal:
trace_statements:
- context: span
statements:
- set(name, "bear" where attributes["http.path"] == "/animal"
- keep_keys(attributes, ["http.method", "http.path"])
metric_statements:
- context: datapoint
statements:
- set(name, "bear" where attributes["http.path"] == "/animal"
- keep_keys(attributes, ["http.method", "http.path"])
log_statements:
- context: log
statements:
- set(body, "bear" where attributes["http.path"] == "/animal"
- keep_keys(attributes, ["http.method", "http.path"])

transform/unknown_function_log:
log_statements:
- context: log
Expand Down
Loading