diff --git a/.chloggen/ottl-statements-rename.yaml b/.chloggen/ottl-statements-rename.yaml new file mode 100644 index 0000000000000..8c5551d13b838 --- /dev/null +++ b/.chloggen/ottl-statements-rename.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: breaking + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: pkg/ottl + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Rename the `Queries` signal configuration field to `Statements` and remove the `ottlconfig` package. + +# One or more tracking issues related to the change +issues: [14680] + +# (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: diff --git a/.chloggen/transformprocessor-statements-rename.yaml b/.chloggen/transformprocessor-statements-rename.yaml new file mode 100644 index 0000000000000..95419db3fab73 --- /dev/null +++ b/.chloggen/transformprocessor-statements-rename.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: breaking + +# 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: Rename the `queries` config key to `statements`. + +# One or more tracking issues related to the change +issues: [14680] + +# (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: diff --git a/pkg/ottl/README.md b/pkg/ottl/README.md index 8d8745152c459..4355f67dd266d 100644 --- a/pkg/ottl/README.md +++ b/pkg/ottl/README.md @@ -2,7 +2,7 @@ The OpenTelemetry Transformation Language is a language for transforming open telemetry data based on the [OpenTelemetry Collector Processing Exploration](https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/processing.md). -This package reads in OTTL queries and converts them to invokable Booleans and functions based on the OTTL's grammar. +This package reads in OTTL statements and converts them to invokable Booleans and functions based on the OTTL's grammar. The OTTL is signal agnostic; it is not aware of the type of telemetry on which it will operate. Instead, the Booleans and functions returned by the package must be passed a `TransformContext`, which provide access to the signal's telemetry. Telemetry data can be accessed and updated through [Getters and Setters](#getters-and-setters). diff --git a/pkg/ottl/ottlconfig/config.go b/pkg/ottl/ottlconfig/config.go deleted file mode 100644 index 1f3804e5782d1..0000000000000 --- a/pkg/ottl/ottlconfig/config.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ottlconfig // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/ottlconfig" - -// Config configures the OTTL queries to execute against traces, metrics, and logs. -type Config struct { - Traces SignalConfig `mapstructure:"traces"` - Metrics SignalConfig `mapstructure:"metrics"` - Logs SignalConfig `mapstructure:"logs"` -} - -// SignalConfig configures OTTL queries to execute. -type SignalConfig struct { - Queries []string `mapstructure:"queries"` -} diff --git a/pkg/ottl/ottlfuncs/README.md b/pkg/ottl/ottlfuncs/README.md index 0d82a7d2bfa31..4cdd4312987cd 100644 --- a/pkg/ottl/ottlfuncs/README.md +++ b/pkg/ottl/ottlfuncs/README.md @@ -262,7 +262,7 @@ The `set` function allows users to set a telemetry field using a value. `target` is a path expression to a telemetry field. `value` is any value type. If `value` resolves to `nil`, e.g. it references an unset map value, there will be no action. -How the underlying telemetry field is updated is decided by the path expression implementation provided by the user to the `ottl.ParseQueries`. +How the underlying telemetry field is updated is decided by the path expression implementation provided by the user to the `ottl.ParseStatements`. Examples: diff --git a/pkg/ottl/parser.go b/pkg/ottl/parser.go index f444e5473da8d..214b66d7d7fa4 100644 --- a/pkg/ottl/parser.go +++ b/pkg/ottl/parser.go @@ -37,7 +37,7 @@ func NewParser[K any](functions map[string]interface{}, pathParser PathExpressio } func (p *Parser[K]) ParseStatements(statements []string) ([]Statement[K], error) { - var queries []Statement[K] + var parsedStatements []Statement[K] var errors error for _, statement := range statements { @@ -56,7 +56,7 @@ func (p *Parser[K]) ParseStatements(statements []string) ([]Statement[K], error) errors = multierr.Append(errors, err) continue } - queries = append(queries, Statement[K]{ + parsedStatements = append(parsedStatements, Statement[K]{ Function: function, Condition: expression, }) @@ -65,7 +65,7 @@ func (p *Parser[K]) ParseStatements(statements []string) ([]Statement[K], error) if errors != nil { return nil, errors } - return queries, nil + return parsedStatements, nil } var parser = newParser() diff --git a/processor/transformprocessor/README.md b/processor/transformprocessor/README.md index 7cd4f4e024f54..2f711feaec879 100644 --- a/processor/transformprocessor/README.md +++ b/processor/transformprocessor/README.md @@ -8,16 +8,16 @@ | Warnings | [Unsound Transformations, Identity Conflict, Orphaned Telemetry, Other](#warnings) | The transform processor modifies telemetry based on configuration using the [OpenTelemetry Transformation Language](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl). -The processor takes a list of queries for each signal type and executes the queries against the incoming telemetry in the order specified in the config. Each statement can access and transform telemetry using functions and allow the use of a condition to help decide whether the function should be executed. +The processor takes a list of statements for each signal type and executes the statements against the incoming telemetry in the order specified in the config. Each statement can access and transform telemetry using functions and allow the use of a condition to help decide whether the function should be executed. ## Config -The transform processor allows configuring queries for traces, metrics, and logs. Each signal specifies a list of string queries that get passed to the OTTL for interpretation. +The transform processor allows configuring statements for traces, metrics, and logs. Each signal specifies a list of string statements that get passed to the OTTL for interpretation. ```yaml transform: : - queries: + statements: - string - string - string @@ -29,7 +29,7 @@ Example configuration: ```yaml transform: traces: - queries: + statements: - set(status.code, 1) where attributes["http.path"] == "/health" - keep_keys(resource.attributes, "service.name", "service.namespace", "cloud.region", "process.command_line") - set(name, attributes["http.route"]) @@ -40,7 +40,7 @@ transform: - truncate_all(attributes, 4096) - truncate_all(resource.attributes, 4096) metrics: - queries: + statements: - set(metric.description, "Sum") where metric.type == "Sum" - keep_keys(resource.attributes, "host.name") - limit(attributes, 100, "host.name") @@ -49,7 +49,7 @@ transform: - convert_sum_to_gauge() where metric.name == "system.processes.count" - convert_gauge_to_sum("cumulative", false) where metric.name == "prometheus_metric" logs: - queries: + statements: - set(severity_text, "FAIL") where body == "request failed" - replace_all_matches(attributes, "/user/*/list/*", "/user/{userId}/list/{listId}") - replace_all_patterns(attributes, "/account/\\d{4}", "/account/{accountId}") @@ -65,7 +65,7 @@ You can learn more in-depth details on the capabilities and limitations of the O The transform processor utilizes the OTTL's standard contexts for Traces, Metrics and Logs. The contexts allow the OTTL to interact with the underlying telemetry data in its pdata form. - [Traces Context](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/contexts/ottltraces) -- [Metrics Context](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/contexts/ottlmetrics) +- [Metrics Context](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/contexts/ottldatapoints) - [Logs Context](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/contexts/ottllogs) ## Supported functions: @@ -119,7 +119,7 @@ The `convert_summary_count_val_to_sum` function creates a new Sum metric from a `aggregation_temporality` is a string (`"cumulative"` or `"delta"`) representing the desired aggregation temporality of the new metric. `is_monotonic` is a boolean representing the monotonicity of the new metric. -The name for the new metric will be `_count`. The fields that are copied are: `timestamp`, `starttimestamp`, `attibutes`, and `description`. The new metric that is created will be passed to all functions in the metrics queries list. Function conditions will apply. +The name for the new metric will be `_count`. The fields that are copied are: `timestamp`, `starttimestamp`, `attibutes`, and `description`. The new metric that is created will be passed to all functions in the metrics statements list. Function conditions will apply. **NOTE:** This function may cause a metric to break semantics for [Sum metrics](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/data-model.md#sums). Use at your own risk. @@ -138,7 +138,7 @@ The `convert_summary_sum_val_to_sum` function creates a new Sum metric from a Su `aggregation_temporality` is a string (`"cumulative"` or `"delta"`) representing the desired aggregation temporality of the new metric. `is_monotonic` is a boolean representing the monotonicity of the new metric. -The name for the new metric will be `_sum`. The fields that are copied are: `timestamp`, `starttimestamp`, `attibutes`, and `description`. The new metric that is created will be passed to all functions in the metrics queries list. Function conditions will apply. +The name for the new metric will be `_sum`. The fields that are copied are: `timestamp`, `starttimestamp`, `attibutes`, and `description`. The new metric that is created will be passed to all functions in the metrics statements list. Function conditions will apply. **NOTE:** This function may cause a metric to break semantics for [Sum metrics](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/data-model.md#sums). Use at your own risk. @@ -156,7 +156,7 @@ See [CONTRIBUTING.md](https://github.com/open-telemetry/opentelemetry-collector- ## Warnings -The transform processor's implementation of the [OpenTelemetry Transformation Language](https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/processing.md#telemetry-query-language) (OTTL) allows users to modify all aspects of their telemetry. Some specific risks are listed below, but this is not an exhaustive list. In general, understand your data before using the transform processor. +The transform processor's implementation of the [OpenTelemetry Transformation Language]https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/processing.md#opentelemetry-transformation-language) (OTTL) allows users to modify all aspects of their telemetry. Some specific risks are listed below, but this is not an exhaustive list. In general, understand your data before using the transform processor. - [Unsound Transformations](https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/standard-warnings.md#unsound-transformations): Several Metric-only functions allow you to transform one metric data type to another or create new metrics from an existing metrics. Transformations between metric data types are not defined in the [metrics data model](https://github.com/open-telemetry/opentelemetry-specification/blob/main//specification/metrics/data-model.md). These functions have the expectation that you understand the incoming data and know that it can be meaningfully converted to a new metric data type or can meaningfully be used to create new metrics. - Although the OTTL allows the `set` function to be used with `metric.data_type`, its implementation in the transform processor is NOOP. To modify a data type you must use a function specific to that purpose. diff --git a/processor/transformprocessor/config.go b/processor/transformprocessor/config.go index 7f2d76d90a064..a53bd772cb6f2 100644 --- a/processor/transformprocessor/config.go +++ b/processor/transformprocessor/config.go @@ -23,7 +23,6 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottldatapoints" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottllogs" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottltraces" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/ottlconfig" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/logs" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/metrics" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/traces" @@ -32,7 +31,17 @@ import ( type Config struct { config.ProcessorSettings `mapstructure:",squash"` - ottlconfig.Config `mapstructure:",squash"` + OTTLConfig `mapstructure:",squash"` +} + +type OTTLConfig struct { + Traces SignalConfig `mapstructure:"traces"` + Metrics SignalConfig `mapstructure:"metrics"` + Logs SignalConfig `mapstructure:"logs"` +} + +type SignalConfig struct { + Statements []string `mapstructure:"statements"` } var _ config.Processor = (*Config)(nil) @@ -41,19 +50,19 @@ func (c *Config) Validate() error { var errors error ottltracesp := ottltraces.NewParser(traces.Functions(), component.TelemetrySettings{Logger: zap.NewNop()}) - _, err := ottltracesp.ParseStatements(c.Traces.Queries) + _, err := ottltracesp.ParseStatements(c.Traces.Statements) if err != nil { errors = multierr.Append(errors, err) } ottlmetricsp := ottldatapoints.NewParser(metrics.Functions(), component.TelemetrySettings{Logger: zap.NewNop()}) - _, err = ottlmetricsp.ParseStatements(c.Metrics.Queries) + _, err = ottlmetricsp.ParseStatements(c.Metrics.Statements) if err != nil { errors = multierr.Append(errors, err) } ottllogsp := ottllogs.NewParser(logs.Functions(), component.TelemetrySettings{Logger: zap.NewNop()}) - _, err = ottllogsp.ParseStatements(c.Logs.Queries) + _, err = ottllogsp.ParseStatements(c.Logs.Statements) if err != nil { errors = multierr.Append(errors, err) } diff --git a/processor/transformprocessor/config_test.go b/processor/transformprocessor/config_test.go index e509ac0b88fca..d2709daadcd73 100644 --- a/processor/transformprocessor/config_test.go +++ b/processor/transformprocessor/config_test.go @@ -22,8 +22,6 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/confmap/confmaptest" - - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/ottlconfig" ) func TestLoadConfig(t *testing.T) { @@ -38,21 +36,21 @@ func TestLoadConfig(t *testing.T) { id: config.NewComponentIDWithName(typeStr, ""), expected: &Config{ ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), - Config: ottlconfig.Config{ - Traces: ottlconfig.SignalConfig{ - Queries: []string{ + OTTLConfig: OTTLConfig{ + Traces: SignalConfig{ + Statements: []string{ `set(name, "bear") where attributes["http.path"] == "/animal"`, `keep_keys(attributes, "http.method", "http.path")`, }, }, - Metrics: ottlconfig.SignalConfig{ - Queries: []string{ + Metrics: SignalConfig{ + Statements: []string{ `set(metric.name, "bear") where attributes["http.path"] == "/animal"`, `keep_keys(attributes, "http.method", "http.path")`, }, }, - Logs: ottlconfig.SignalConfig{ - Queries: []string{ + Logs: SignalConfig{ + Statements: []string{ `set(body, "bear") where attributes["http.path"] == "/animal"`, `keep_keys(attributes, "http.method", "http.path")`, }, diff --git a/processor/transformprocessor/factory.go b/processor/transformprocessor/factory.go index d0c4285884172..0f43f9cd590fd 100644 --- a/processor/transformprocessor/factory.go +++ b/processor/transformprocessor/factory.go @@ -23,7 +23,6 @@ import ( "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/processor/processorhelper" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/ottlconfig" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/logs" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/metrics" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/traces" @@ -49,15 +48,15 @@ func NewFactory() component.ProcessorFactory { func createDefaultConfig() config.Processor { return &Config{ ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), - Config: ottlconfig.Config{ - Logs: ottlconfig.SignalConfig{ - Queries: []string{}, + OTTLConfig: OTTLConfig{ + Logs: SignalConfig{ + Statements: []string{}, }, - Traces: ottlconfig.SignalConfig{ - Queries: []string{}, + Traces: SignalConfig{ + Statements: []string{}, }, - Metrics: ottlconfig.SignalConfig{ - Queries: []string{}, + Metrics: SignalConfig{ + Statements: []string{}, }, }, } @@ -71,7 +70,7 @@ func createLogsProcessor( ) (component.LogsProcessor, error) { oCfg := cfg.(*Config) - proc, err := logs.NewProcessor(oCfg.Logs.Queries, logs.Functions(), set.TelemetrySettings) + proc, err := logs.NewProcessor(oCfg.Logs.Statements, logs.Functions(), set.TelemetrySettings) if err != nil { return nil, fmt.Errorf("invalid config for \"transform\" processor %w", err) } @@ -92,7 +91,7 @@ func createTracesProcessor( ) (component.TracesProcessor, error) { oCfg := cfg.(*Config) - proc, err := traces.NewProcessor(oCfg.Traces.Queries, traces.Functions(), set.TelemetrySettings) + proc, err := traces.NewProcessor(oCfg.Traces.Statements, traces.Functions(), set.TelemetrySettings) if err != nil { return nil, fmt.Errorf("invalid config for \"transform\" processor %w", err) } @@ -113,7 +112,7 @@ func createMetricsProcessor( ) (component.MetricsProcessor, error) { oCfg := cfg.(*Config) - proc, err := metrics.NewProcessor(oCfg.Metrics.Queries, metrics.Functions(), set.TelemetrySettings) + proc, err := metrics.NewProcessor(oCfg.Metrics.Statements, metrics.Functions(), set.TelemetrySettings) if err != nil { return nil, fmt.Errorf("invalid config for \"transform\" processor %w", err) } diff --git a/processor/transformprocessor/factory_test.go b/processor/transformprocessor/factory_test.go index fd455825dd4dc..1c3319e9d123f 100644 --- a/processor/transformprocessor/factory_test.go +++ b/processor/transformprocessor/factory_test.go @@ -26,8 +26,6 @@ import ( "go.opentelemetry.io/collector/pdata/plog" "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/pdata/ptrace" - - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/ottlconfig" ) func TestFactory_Type(t *testing.T) { @@ -40,15 +38,15 @@ func TestFactory_CreateDefaultConfig(t *testing.T) { cfg := factory.CreateDefaultConfig() assert.Equal(t, cfg, &Config{ ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), - Config: ottlconfig.Config{ - Traces: ottlconfig.SignalConfig{ - Queries: []string{}, + OTTLConfig: OTTLConfig{ + Traces: SignalConfig{ + Statements: []string{}, }, - Metrics: ottlconfig.SignalConfig{ - Queries: []string{}, + Metrics: SignalConfig{ + Statements: []string{}, }, - Logs: ottlconfig.SignalConfig{ - Queries: []string{}, + Logs: SignalConfig{ + Statements: []string{}, }, }, }) @@ -66,7 +64,7 @@ func TestFactoryCreateTracesProcessor_InvalidActions(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() oCfg := cfg.(*Config) - oCfg.Traces.Queries = []string{`set(123`} + oCfg.Traces.Statements = []string{`set(123`} ap, err := factory.CreateTracesProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), cfg, consumertest.NewNop()) assert.Error(t, err) assert.Nil(t, ap) @@ -76,7 +74,7 @@ func TestFactoryCreateTracesProcessor(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() oCfg := cfg.(*Config) - oCfg.Traces.Queries = []string{`set(attributes["test"], "pass") where name == "operationA"`} + oCfg.Traces.Statements = []string{`set(attributes["test"], "pass") where name == "operationA"`} tp, err := factory.CreateTracesProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), cfg, consumertest.NewNop()) assert.NotNil(t, tp) @@ -101,7 +99,7 @@ func TestFactoryCreateMetricsProcessor_InvalidActions(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() oCfg := cfg.(*Config) - oCfg.Metrics.Queries = []string{`set(123`} + oCfg.Metrics.Statements = []string{`set(123`} ap, err := factory.CreateMetricsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), cfg, consumertest.NewNop()) assert.Error(t, err) assert.Nil(t, ap) @@ -111,7 +109,7 @@ func TestFactoryCreateMetricsProcessor(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() oCfg := cfg.(*Config) - oCfg.Metrics.Queries = []string{`set(attributes["test"], "pass") where metric.name == "operationA"`} + oCfg.Metrics.Statements = []string{`set(attributes["test"], "pass") where metric.name == "operationA"`} metricsProcessor, err := factory.CreateMetricsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), cfg, consumertest.NewNop()) assert.NotNil(t, metricsProcessor) @@ -136,7 +134,7 @@ func TestFactoryCreateLogsProcessor(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() oCfg := cfg.(*Config) - oCfg.Logs.Queries = []string{`set(attributes["test"], "pass") where body == "operationA"`} + oCfg.Logs.Statements = []string{`set(attributes["test"], "pass") where body == "operationA"`} lp, err := factory.CreateLogsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), cfg, consumertest.NewNop()) assert.NotNil(t, lp) @@ -161,7 +159,7 @@ func TestFactoryCreateLogsProcessor_InvalidActions(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() oCfg := cfg.(*Config) - oCfg.Logs.Queries = []string{`set(123`} + oCfg.Logs.Statements = []string{`set(123`} ap, err := factory.CreateLogsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), cfg, consumertest.NewNop()) assert.Error(t, err) assert.Nil(t, ap) diff --git a/processor/transformprocessor/internal/logs/processor.go b/processor/transformprocessor/internal/logs/processor.go index 32f075a421b2a..45e40c8a48d19 100644 --- a/processor/transformprocessor/internal/logs/processor.go +++ b/processor/transformprocessor/internal/logs/processor.go @@ -25,17 +25,17 @@ import ( ) type Processor struct { - queries []ottl.Statement[ottllogs.TransformContext] + statements []ottl.Statement[ottllogs.TransformContext] } func NewProcessor(statements []string, functions map[string]interface{}, settings component.TelemetrySettings) (*Processor, error) { ottlp := ottllogs.NewParser(functions, settings) - queries, err := ottlp.ParseStatements(statements) + parsedStatements, err := ottlp.ParseStatements(statements) if err != nil { return nil, err } return &Processor{ - queries: queries, + statements: parsedStatements, }, nil } @@ -47,7 +47,7 @@ func (p *Processor) ProcessLogs(_ context.Context, td plog.Logs) (plog.Logs, err logs := slogs.LogRecords() for k := 0; k < logs.Len(); k++ { ctx := ottllogs.NewTransformContext(logs.At(k), slogs.Scope(), rlogs.Resource()) - for _, statement := range p.queries { + for _, statement := range p.statements { if statement.Condition(ctx) { statement.Function(ctx) } diff --git a/processor/transformprocessor/internal/metrics/processor.go b/processor/transformprocessor/internal/metrics/processor.go index 5d558b0817c0e..35b4419138d2e 100644 --- a/processor/transformprocessor/internal/metrics/processor.go +++ b/processor/transformprocessor/internal/metrics/processor.go @@ -26,17 +26,17 @@ import ( ) type Processor struct { - queries []ottl.Statement[ottldatapoints.TransformContext] + statements []ottl.Statement[ottldatapoints.TransformContext] } func NewProcessor(statements []string, functions map[string]interface{}, settings component.TelemetrySettings) (*Processor, error) { ottlp := ottldatapoints.NewParser(functions, settings) - queries, err := ottlp.ParseStatements(statements) + parsedStatements, err := ottlp.ParseStatements(statements) if err != nil { return nil, err } return &Processor{ - queries: queries, + statements: parsedStatements, }, nil } @@ -95,7 +95,7 @@ func (p *Processor) handleSummaryDataPoints(dps pmetric.SummaryDataPointSlice, m } func (p *Processor) callFunctions(ctx ottldatapoints.TransformContext) { - for _, statement := range p.queries { + for _, statement := range p.statements { if statement.Condition(ctx) { statement.Function(ctx) } diff --git a/processor/transformprocessor/internal/traces/processor.go b/processor/transformprocessor/internal/traces/processor.go index b97523d09f67e..c87928ccbcfe2 100644 --- a/processor/transformprocessor/internal/traces/processor.go +++ b/processor/transformprocessor/internal/traces/processor.go @@ -25,17 +25,17 @@ import ( ) type Processor struct { - queries []ottl.Statement[ottltraces.TransformContext] + statements []ottl.Statement[ottltraces.TransformContext] } func NewProcessor(statements []string, functions map[string]interface{}, settings component.TelemetrySettings) (*Processor, error) { ottlp := ottltraces.NewParser(functions, settings) - queries, err := ottlp.ParseStatements(statements) + parsedStatements, err := ottlp.ParseStatements(statements) if err != nil { return nil, err } return &Processor{ - queries: queries, + statements: parsedStatements, }, nil } @@ -47,7 +47,7 @@ func (p *Processor) ProcessTraces(_ context.Context, td ptrace.Traces) (ptrace.T spans := sspan.Spans() for k := 0; k < spans.Len(); k++ { ctx := ottltraces.NewTransformContext(spans.At(k), sspan.Scope(), rspans.Resource()) - for _, statement := range p.queries { + for _, statement := range p.statements { if statement.Condition(ctx) { statement.Function(ctx) } diff --git a/processor/transformprocessor/internal/traces/processor_test.go b/processor/transformprocessor/internal/traces/processor_test.go index 044da35f1626d..21866a31c75d4 100644 --- a/processor/transformprocessor/internal/traces/processor_test.go +++ b/processor/transformprocessor/internal/traces/processor_test.go @@ -239,32 +239,32 @@ func TestProcess(t *testing.T) { func BenchmarkTwoSpans(b *testing.B) { tests := []struct { - name string - queries []string + name string + statements []string }{ { - name: "no processing", - queries: []string{}, + name: "no processing", + statements: []string{}, }, { - name: "set attribute", - queries: []string{`set(attributes["test"], "pass") where name == "operationA"`}, + name: "set attribute", + statements: []string{`set(attributes["test"], "pass") where name == "operationA"`}, }, { - name: "keep_keys attribute", - queries: []string{`keep_keys(attributes, "http.method") where name == "operationA"`}, + name: "keep_keys attribute", + statements: []string{`keep_keys(attributes, "http.method") where name == "operationA"`}, }, { - name: "no match", - queries: []string{`keep_keys(attributes, "http.method") where name == "unknownOperation"`}, + name: "no match", + statements: []string{`keep_keys(attributes, "http.method") where name == "unknownOperation"`}, }, { - name: "inner field", - queries: []string{`set(status.code, 1) where attributes["http.path"] == "/health"`}, + name: "inner field", + statements: []string{`set(status.code, 1) where attributes["http.path"] == "/health"`}, }, { name: "inner field both spans", - queries: []string{ + statements: []string{ `set(status.code, 1) where name == "operationA"`, `set(status.code, 2) where name == "operationB"`, }, @@ -273,7 +273,7 @@ func BenchmarkTwoSpans(b *testing.B) { for _, tt := range tests { b.Run(tt.name, func(b *testing.B) { - processor, err := NewProcessor(tt.queries, Functions(), componenttest.NewNopTelemetrySettings()) + processor, err := NewProcessor(tt.statements, Functions(), componenttest.NewNopTelemetrySettings()) assert.NoError(b, err) b.ResetTimer() for n := 0; n < b.N; n++ { @@ -287,35 +287,35 @@ func BenchmarkTwoSpans(b *testing.B) { func BenchmarkHundredSpans(b *testing.B) { tests := []struct { - name string - queries []string + name string + statements []string }{ { - name: "no processing", - queries: []string{}, + name: "no processing", + statements: []string{}, }, { name: "set status code", - queries: []string{ + statements: []string{ `set(status.code, 1) where name == "operationA"`, `set(status.code, 2) where name == "operationB"`, }, }, { - name: "hundred queries", - queries: func() []string { - var queries []string - queries = append(queries, `set(status.code, 1) where name == "operationA"`) + name: "hundred statements", + statements: func() []string { + var statements []string + statements = append(statements, `set(status.code, 1) where name == "operationA"`) for i := 0; i < 99; i++ { - queries = append(queries, `keep_keys(attributes, "http.method") where name == "unknownOperation"`) + statements = append(statements, `keep_keys(attributes, "http.method") where name == "unknownOperation"`) } - return queries + return statements }(), }, } for _, tt := range tests { b.Run(tt.name, func(b *testing.B) { - processor, err := NewProcessor(tt.queries, Functions(), componenttest.NewNopTelemetrySettings()) + processor, err := NewProcessor(tt.statements, Functions(), componenttest.NewNopTelemetrySettings()) assert.NoError(b, err) b.ResetTimer() for n := 0; n < b.N; n++ { diff --git a/processor/transformprocessor/testdata/config.yaml b/processor/transformprocessor/testdata/config.yaml index b369328f5168d..4a3d34e95f8dd 100644 --- a/processor/transformprocessor/testdata/config.yaml +++ b/processor/transformprocessor/testdata/config.yaml @@ -1,49 +1,49 @@ transform: traces: - queries: + statements: - set(name, "bear") where attributes["http.path"] == "/animal" - keep_keys(attributes, "http.method", "http.path") metrics: - queries: + statements: - set(metric.name, "bear") where attributes["http.path"] == "/animal" - keep_keys(attributes, "http.method", "http.path") logs: - queries: + statements: - set(body, "bear") where attributes["http.path"] == "/animal" - keep_keys(attributes, "http.method", "http.path") transform/bad_syntax_log: logs: - queries: + statements: - set(body, "bear" where attributes["http.path"] == "/animal" - keep_keys(attributes, "http.method", "http.path") transform/bad_syntax_metric: metrics: - queries: + statements: - set(name, "bear" where attributes["http.path"] == "/animal" - keep_keys(attributes, "http.method", "http.path") transform/bad_syntax_trace: traces: - queries: + statements: - set(name, "bear" where attributes["http.path"] == "/animal" - keep_keys(attributes, "http.method", "http.path") transform/unknown_function_log: logs: - queries: + statements: - set(body, "bear") where attributes["http.path"] == "/animal" - not_a_function(attributes, "http.method", "http.path") transform/unknown_function_metric: metrics: - queries: + statements: - set(metric.name, "bear") where attributes["http.path"] == "/animal" - not_a_function(attributes, "http.method", "http.path") transform/unknown_function_trace: traces: - queries: + statements: - set(name, "bear") where attributes["http.path"] == "/animal" - not_a_function(attributes, "http.method", "http.path")