From 5659ade404f740c37ff13cc1546ecaa6b966e76e Mon Sep 17 00:00:00 2001 From: Dan Jaglowski Date: Fri, 4 Oct 2024 14:55:45 -0400 Subject: [PATCH] [pdatautil] Add function for splitting log records while preserving context --- .chloggen/split-log-records.yaml | 27 ++++ connector/routingconnector/README.md | 100 ++++++++++++- connector/routingconnector/config.go | 14 ++ connector/routingconnector/config_test.go | 31 ++++ connector/routingconnector/logs.go | 40 ++--- connector/routingconnector/logs_test.go | 10 ++ connector/routingconnector/metrics.go | 2 +- connector/routingconnector/router.go | 96 ++++++++---- .../all_match_first_only/config.yaml | 13 ++ .../all_match_first_only/input.yaml | 141 ++++++++++++++++++ .../all_match_first_only/sink_0.yaml | 141 ++++++++++++++++++ .../all_match_last_only/config.yaml | 13 ++ .../all_match_last_only/input.yaml | 141 ++++++++++++++++++ .../all_match_last_only/sink_1.yaml | 141 ++++++++++++++++++ .../match_none_with_default/config.yaml | 13 ++ .../match_none_with_default/input.yaml | 141 ++++++++++++++++++ .../match_none_with_default/sink_default.yaml | 141 ++++++++++++++++++ .../match_none_without_default/config.yaml | 12 ++ .../match_none_without_default/input.yaml | 141 ++++++++++++++++++ .../some_match_each_route/config.yaml | 13 ++ .../some_match_each_route/input.yaml | 141 ++++++++++++++++++ .../some_match_each_route/sink_0.yaml | 53 +++++++ .../some_match_each_route/sink_1.yaml | 53 +++++++ .../some_match_each_route/sink_default.yaml | 105 +++++++++++++ .../config.yaml | 13 ++ .../input.yaml | 141 ++++++++++++++++++ .../sink_0.yaml | 41 +++++ .../sink_default.yaml | 111 ++++++++++++++ .../with_resource_condition/config.yaml | 13 ++ .../with_resource_condition/input.yaml | 141 ++++++++++++++++++ .../with_resource_condition/sink_0.yaml | 71 +++++++++ .../with_resource_condition/sink_default.yaml | 71 +++++++++ .../with_scope_condition/config.yaml | 13 ++ .../with_scope_condition/input.yaml | 141 ++++++++++++++++++ .../with_scope_condition/sink_0.yaml | 81 ++++++++++ .../with_scope_condition/sink_default.yaml | 81 ++++++++++ .../match_logs_then_resource/config.yaml | 13 ++ .../match_logs_then_resource/input.yaml | 141 ++++++++++++++++++ .../match_logs_then_resource/sink_0.yaml | 105 +++++++++++++ .../match_logs_then_resource/sink_1.yaml | 53 +++++++ .../sink_default.yaml | 53 +++++++ .../match_resource_then_logs/config.yaml | 13 ++ .../match_resource_then_logs/input.yaml | 141 ++++++++++++++++++ .../match_resource_then_logs/sink_0.yaml | 71 +++++++++ .../match_resource_then_logs/sink_1.yaml | 53 +++++++ .../sink_default.yaml | 53 +++++++ connector/routingconnector/traces.go | 2 +- 47 files changed, 3289 insertions(+), 50 deletions(-) create mode 100644 .chloggen/split-log-records.yaml create mode 100644 connector/routingconnector/testdata/logs/log_context/all_match_first_only/config.yaml create mode 100644 connector/routingconnector/testdata/logs/log_context/all_match_first_only/input.yaml create mode 100644 connector/routingconnector/testdata/logs/log_context/all_match_first_only/sink_0.yaml create mode 100644 connector/routingconnector/testdata/logs/log_context/all_match_last_only/config.yaml create mode 100644 connector/routingconnector/testdata/logs/log_context/all_match_last_only/input.yaml create mode 100644 connector/routingconnector/testdata/logs/log_context/all_match_last_only/sink_1.yaml create mode 100644 connector/routingconnector/testdata/logs/log_context/match_none_with_default/config.yaml create mode 100644 connector/routingconnector/testdata/logs/log_context/match_none_with_default/input.yaml create mode 100644 connector/routingconnector/testdata/logs/log_context/match_none_with_default/sink_default.yaml create mode 100644 connector/routingconnector/testdata/logs/log_context/match_none_without_default/config.yaml create mode 100644 connector/routingconnector/testdata/logs/log_context/match_none_without_default/input.yaml create mode 100644 connector/routingconnector/testdata/logs/log_context/some_match_each_route/config.yaml create mode 100644 connector/routingconnector/testdata/logs/log_context/some_match_each_route/input.yaml create mode 100644 connector/routingconnector/testdata/logs/log_context/some_match_each_route/sink_0.yaml create mode 100644 connector/routingconnector/testdata/logs/log_context/some_match_each_route/sink_1.yaml create mode 100644 connector/routingconnector/testdata/logs/log_context/some_match_each_route/sink_default.yaml create mode 100644 connector/routingconnector/testdata/logs/log_context/with_resource_and_scope_conditions/config.yaml create mode 100644 connector/routingconnector/testdata/logs/log_context/with_resource_and_scope_conditions/input.yaml create mode 100644 connector/routingconnector/testdata/logs/log_context/with_resource_and_scope_conditions/sink_0.yaml create mode 100644 connector/routingconnector/testdata/logs/log_context/with_resource_and_scope_conditions/sink_default.yaml create mode 100644 connector/routingconnector/testdata/logs/log_context/with_resource_condition/config.yaml create mode 100644 connector/routingconnector/testdata/logs/log_context/with_resource_condition/input.yaml create mode 100644 connector/routingconnector/testdata/logs/log_context/with_resource_condition/sink_0.yaml create mode 100644 connector/routingconnector/testdata/logs/log_context/with_resource_condition/sink_default.yaml create mode 100644 connector/routingconnector/testdata/logs/log_context/with_scope_condition/config.yaml create mode 100644 connector/routingconnector/testdata/logs/log_context/with_scope_condition/input.yaml create mode 100644 connector/routingconnector/testdata/logs/log_context/with_scope_condition/sink_0.yaml create mode 100644 connector/routingconnector/testdata/logs/log_context/with_scope_condition/sink_default.yaml create mode 100644 connector/routingconnector/testdata/logs/mixed_context/match_logs_then_resource/config.yaml create mode 100644 connector/routingconnector/testdata/logs/mixed_context/match_logs_then_resource/input.yaml create mode 100644 connector/routingconnector/testdata/logs/mixed_context/match_logs_then_resource/sink_0.yaml create mode 100644 connector/routingconnector/testdata/logs/mixed_context/match_logs_then_resource/sink_1.yaml create mode 100644 connector/routingconnector/testdata/logs/mixed_context/match_logs_then_resource/sink_default.yaml create mode 100644 connector/routingconnector/testdata/logs/mixed_context/match_resource_then_logs/config.yaml create mode 100644 connector/routingconnector/testdata/logs/mixed_context/match_resource_then_logs/input.yaml create mode 100644 connector/routingconnector/testdata/logs/mixed_context/match_resource_then_logs/sink_0.yaml create mode 100644 connector/routingconnector/testdata/logs/mixed_context/match_resource_then_logs/sink_1.yaml create mode 100644 connector/routingconnector/testdata/logs/mixed_context/match_resource_then_logs/sink_default.yaml diff --git a/.chloggen/split-log-records.yaml b/.chloggen/split-log-records.yaml new file mode 100644 index 000000000000..db61dd67953a --- /dev/null +++ b/.chloggen/split-log-records.yaml @@ -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: enhancement + +# 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: Add ability to route log records individually using OTTL log record context. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [19738] + +# (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: [] diff --git a/connector/routingconnector/README.md b/connector/routingconnector/README.md index 8366bcfbb53f..72ebf8a4afe0 100644 --- a/connector/routingconnector/README.md +++ b/connector/routingconnector/README.md @@ -33,14 +33,17 @@ If you are not already familiar with connectors, you may find it helpful to firs The following settings are available: - `table (required)`: the routing table for this connector. +- `table.context (optional, default: resource)`: the [OTTL Context] in which the statement will be evaluated. Currently, only `resource` and `log` are supported. - `table.statement`: the routing condition provided as the [OTTL] statement. Required if `table.condition` is not provided. - `table.condition`: the routing condition provided as the [OTTL] condition. Required if `table.statement` is not provided. - `table.pipelines (required)`: the list of pipelines to use when the routing condition is met. - `default_pipelines (optional)`: contains the list of pipelines to use when a record does not meet any of specified conditions. - `error_mode (optional)`: determines how errors returned from OTTL statements are handled. Valid values are `propagate`, `ignore` and `silent`. If `ignore` or `silent` is used and a statement's condition has an error then the payload will be routed to the default pipelines. When `silent` is used the error is not logged. If not supplied, `propagate` is used. -- `match_once (optional, default: false)`: determines whether the connector matches multiple statements or not. If enabled, the payload will be routed to the first pipeline in the `table` whose routing condition is met. +- `match_once (optional, default: false)`: determines whether the connector matches multiple statements or not. If enabled, the payload will be routed to the first pipeline in the `table` whose routing condition is met. May only be `false` when used with `resource` context. -Example: +### Examples + +Route traces based on an attribute: ```yaml receivers: @@ -91,6 +94,92 @@ service: exporters: [jaeger/ecorp] ``` +Route logs based on region: + +```yaml +receivers: + otlp: + +exporters: + file/other: + path: ./other.log + file/east: + path: ./east.log + file/west: + path: ./west.log + +connectors: + routing: + match_once: true + default_pipelines: [logs/other] + table: + - context: log + condition: attributes["region"] == "east" + pipelines: [logs/east] + - context: log + condition: attributes["region"] == "west" + pipelines: [logs/west] + +service: + pipelines: + logs/in: + receivers: [otlp] + exporters: [routing] + logs/east: + receivers: [routing] + exporters: [file/east] + logs/west: + receivers: [routing] + exporters: [file/west] + logs/other: + receivers: [routing] + exporters: [file/other] +``` + +Route all low level logs to cheap storage. Route the remainder based on service name: + +```yaml +receivers: + otlp: + +exporters: + file/cheap: + path: ./cheap.log + file/service1: + path: ./service1-important.log + file/ecorp: + path: ./service2-important.log + +connectors: + routing: + match_once: true + table: + - context: log + condition: severity_number < SEVERITY_NUMBER_ERROR + pipelines: [logs/cheap] + - context: resource + condition: attributes["service.name"] == "service1" + pipelines: [logs/service1] + - context: resource + condition: attributes["service.name"] == "service2" + pipelines: [logs/service2] + +service: + pipelines: + logs/in: + receivers: [otlp] + exporters: [routing] + logs/cheap: + receivers: [routing] + exporters: [file/cheap] + logs/service1: + receivers: [routing] + exporters: [file/service1] + logs/service2: + receivers: [routing] + exporters: [file/service2] +``` + A signal may get matched by routing conditions of more than one routing table entry. In this case, the signal will be routed to all pipelines of matching routes. Respectively, if none of the routing conditions met, then a signal is routed to default pipelines. @@ -109,10 +198,11 @@ Respectively, if none of the routing conditions met, then a signal is routed to The full list of settings exposed for this connector are documented [here](./config.go) with detailed sample configuration files: -- [logs](./testdata/config_logs.yaml) -- [metrics](./testdata/config_metrics.yaml) -- [traces](./testdata/config_traces.yaml) +- [logs](./testdata/config/logs.yaml) +- [metrics](./testdata/config/metrics.yaml) +- [traces](./testdata/config/traces.yaml) [Connectors README]:https://github.com/open-telemetry/opentelemetry-collector/blob/main/connector/README.md [OTTL]: https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/ottl/README.md +[OTTL Context]: https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/ottl/LANGUAGE.md#contexts diff --git a/connector/routingconnector/config.go b/connector/routingconnector/config.go index 8c868e152a00..3824c577c5cc 100644 --- a/connector/routingconnector/config.go +++ b/connector/routingconnector/config.go @@ -67,6 +67,16 @@ func (c *Config) Validate() error { if len(item.Pipelines) == 0 { return errNoPipelines } + + switch item.Context { + case "", "resource": // ok + case "log": + if !c.MatchOnce { + return errors.New("log context is not supported with match_once: false") + } + default: + return errors.New("invalid context: " + item.Context) + } } return nil @@ -74,6 +84,10 @@ func (c *Config) Validate() error { // RoutingTableItem specifies how data should be routed to the different pipelines type RoutingTableItem struct { + // One of "resource" or "log" (other OTTL contexts will be added in the future) + // Optional. Default "resource". + Context string `mapstructure:"context"` + // Statement is a OTTL statement used for making a routing decision. // One of 'Statement' or 'Condition' must be provided. Statement string `mapstructure:"statement"` diff --git a/connector/routingconnector/config_test.go b/connector/routingconnector/config_test.go index 5f3514f76e4d..aa36ad885e16 100644 --- a/connector/routingconnector/config_test.go +++ b/connector/routingconnector/config_test.go @@ -203,6 +203,37 @@ func TestValidateConfig(t *testing.T) { }, error: "invalid route: both condition and statement provided", }, + { + name: "invalid context", + config: &Config{ + Table: []RoutingTableItem{ + { + Context: "invalid", + Statement: `route() where attributes["attr"] == "acme"`, + Pipelines: []pipeline.ID{ + pipeline.NewIDWithName(pipeline.SignalTraces, "otlp"), + }, + }, + }, + }, + error: "invalid context: invalid", + }, + { + name: "log context with match_once false", + config: &Config{ + MatchOnce: false, + Table: []RoutingTableItem{ + { + Context: "log", + Statement: `route() where attributes["attr"] == "acme"`, + Pipelines: []pipeline.ID{ + pipeline.NewIDWithName(pipeline.SignalTraces, "otlp"), + }, + }, + }, + }, + error: "log context is not supported with match_once: false", + }, } for _, tt := range tests { diff --git a/connector/routingconnector/logs.go b/connector/routingconnector/logs.go index dca421b74f9d..7fb0f92f65da 100644 --- a/connector/routingconnector/logs.go +++ b/connector/routingconnector/logs.go @@ -15,6 +15,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/connector/routingconnector/internal/plogutil" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottllog" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlresource" ) @@ -74,29 +75,36 @@ func (c *logsConnector) switchLogs(ctx context.Context, ld plog.Logs) error { var errs error for _, route := range c.router.routeSlice { matchedLogs := plog.NewLogs() - - plogutil.MoveResourcesIf(ld, matchedLogs, - func(rl plog.ResourceLogs) bool { - rtx := ottlresource.NewTransformContext(rl.Resource(), rl) - _, isMatch, err := route.statement.Execute(ctx, rtx) - errs = errors.Join(errs, err) - return isMatch - }, - ) - + switch route.statementContext { + case "", "resource": + plogutil.MoveResourcesIf(ld, matchedLogs, + func(rl plog.ResourceLogs) bool { + rtx := ottlresource.NewTransformContext(rl.Resource(), rl) + _, isMatch, err := route.resourceStatement.Execute(ctx, rtx) + errs = errors.Join(errs, err) + return isMatch + }, + ) + case "log": + plogutil.MoveRecordsWithContextIf(ld, matchedLogs, + func(rl plog.ResourceLogs, sl plog.ScopeLogs, lr plog.LogRecord) bool { + ltx := ottllog.NewTransformContext(lr, sl.Scope(), rl.Resource(), sl, rl) + _, isMatch, err := route.logStatement.Execute(ctx, ltx) + errs = errors.Join(errs, err) + return isMatch + }, + ) + } if errs != nil { if c.config.ErrorMode == ottl.PropagateError { return errs } groupAll(groups, c.router.defaultConsumer, matchedLogs) - } groupAll(groups, route.consumer, matchedLogs) } - // anything left wasn't matched by any route. Send to default consumer groupAll(groups, c.router.defaultConsumer, ld) - for consumer, group := range groups { errs = errors.Join(errs, consumer.ConsumeLogs(ctx, group)) } @@ -110,14 +118,12 @@ func (c *logsConnector) matchAll(ctx context.Context, ld plog.Logs) error { // higher CPU usage. groups := make(map[consumer.Logs]plog.Logs) var errs error - for i := 0; i < ld.ResourceLogs().Len(); i++ { rlogs := ld.ResourceLogs().At(i) rtx := ottlresource.NewTransformContext(rlogs.Resource(), rlogs) - noRoutesMatch := true for _, route := range c.router.routeSlice { - _, isMatch, err := route.statement.Execute(ctx, rtx) + _, isMatch, err := route.resourceStatement.Execute(ctx, rtx) if err != nil { if c.config.ErrorMode == ottl.PropagateError { return err @@ -129,9 +135,7 @@ func (c *logsConnector) matchAll(ctx context.Context, ld plog.Logs) error { noRoutesMatch = false group(groups, route.consumer, rlogs) } - } - if noRoutesMatch { // no route conditions are matched, add resource logs to default exporters group group(groups, c.router.defaultConsumer, rlogs) diff --git a/connector/routingconnector/logs_test.go b/connector/routingconnector/logs_test.go index 344aa01e07ba..480d60443a61 100644 --- a/connector/routingconnector/logs_test.go +++ b/connector/routingconnector/logs_test.go @@ -481,6 +481,16 @@ func TestLogsConnectorDetailed(t *testing.T) { filepath.Join("testdata", "logs", "resource_context", "each_matches_one"), filepath.Join("testdata", "logs", "resource_context", "match_none_with_default"), filepath.Join("testdata", "logs", "resource_context", "match_none_without_default"), + filepath.Join("testdata", "logs", "log_context", "all_match_first_only"), + filepath.Join("testdata", "logs", "log_context", "all_match_last_only"), + filepath.Join("testdata", "logs", "log_context", "match_none_with_default"), + filepath.Join("testdata", "logs", "log_context", "match_none_without_default"), + filepath.Join("testdata", "logs", "log_context", "some_match_each_route"), + filepath.Join("testdata", "logs", "log_context", "with_resource_condition"), + filepath.Join("testdata", "logs", "log_context", "with_scope_condition"), + filepath.Join("testdata", "logs", "log_context", "with_resource_and_scope_conditions"), + filepath.Join("testdata", "logs", "mixed_context", "match_resource_then_logs"), + filepath.Join("testdata", "logs", "mixed_context", "match_logs_then_resource"), } for _, tt := range testCases { diff --git a/connector/routingconnector/metrics.go b/connector/routingconnector/metrics.go index 42c362cbe1dd..6bf9508a6ef2 100644 --- a/connector/routingconnector/metrics.go +++ b/connector/routingconnector/metrics.go @@ -73,7 +73,7 @@ func (c *metricsConnector) ConsumeMetrics(ctx context.Context, md pmetric.Metric noRoutesMatch := true for _, route := range c.router.routeSlice { - _, isMatch, err := route.statement.Execute(ctx, rtx) + _, isMatch, err := route.resourceStatement.Execute(ctx, rtx) if err != nil { if c.config.ErrorMode == ottl.PropagateError { return err diff --git a/connector/routingconnector/router.go b/connector/routingconnector/router.go index d9cc906b3564..aac7bb1b2324 100644 --- a/connector/routingconnector/router.go +++ b/connector/routingconnector/router.go @@ -14,6 +14,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/connector/routingconnector/internal/common" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottllog" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlresource" ) @@ -28,8 +29,9 @@ type consumerProvider[C any] func(...pipeline.ID) (C, error) // parameter C is expected to be one of: consumer.Traces, consumer.Metrics, or // consumer.Logs. type router[C any] struct { - logger *zap.Logger - parser ottl.Parser[ottlresource.TransformContext] + logger *zap.Logger + resourceParser ottl.Parser[ottlresource.TransformContext] + logParser ottl.Parser[ottllog.TransformContext] table []RoutingTableItem routes map[string]routingItem[C] @@ -47,23 +49,17 @@ func newRouter[C any]( provider consumerProvider[C], settings component.TelemetrySettings, ) (*router[C], error) { - parser, err := ottlresource.NewParser( - common.Functions[ottlresource.TransformContext](), - settings, - ) - - if err != nil { - return nil, err - } - r := &router[C]{ logger: settings.Logger, - parser: parser, table: table, routes: make(map[string]routingItem[C]), consumerProvider: provider, } + if err := r.buildParsers(table, settings); err != nil { + return nil, err + } + if err := r.registerConsumers(defaultPipelineIDs); err != nil { return nil, err } @@ -72,8 +68,48 @@ func newRouter[C any]( } type routingItem[C any] struct { - consumer C - statement *ottl.Statement[ottlresource.TransformContext] + consumer C + statementContext string + + resourceStatement *ottl.Statement[ottlresource.TransformContext] + logStatement *ottl.Statement[ottllog.TransformContext] +} + +func (r *router[C]) buildParsers(table []RoutingTableItem, settings component.TelemetrySettings) error { + var buildResource, buildLog bool + for _, item := range table { + switch item.Context { + case "", "resource": + buildResource = true + case "log": + buildLog = true + } + } + + var errs error + if buildResource { + parser, err := ottlresource.NewParser( + common.Functions[ottlresource.TransformContext](), + settings, + ) + if err == nil { + r.resourceParser = parser + } else { + errs = errors.Join(errs, err) + } + } + if buildLog { + parser, err := ottllog.NewParser( + common.Functions[ottllog.TransformContext](), + settings, + ) + if err == nil { + r.logParser = parser + } else { + errs = errors.Join(errs, err) + } + } + return errs } func (r *router[C]) registerConsumers(defaultPipelineIDs []pipeline.ID) error { @@ -94,8 +130,7 @@ func (r *router[C]) registerConsumers(defaultPipelineIDs []pipeline.ID) error { return nil } -// registerDefaultConsumer registers a consumer for the default -// pipelines configured +// registerDefaultConsumer registers a consumer for the default pipelines configured func (r *router[C]) registerDefaultConsumer(pipelineIDs []pipeline.ID) error { if len(pipelineIDs) == 0 { return nil @@ -121,18 +156,26 @@ func (r *router[C]) normalizeConditions() { } } -// registerRouteConsumers registers a consumer for the pipelines configured -// for each route +// registerRouteConsumers registers a consumer for the pipelines configured for each route func (r *router[C]) registerRouteConsumers() error { for _, item := range r.table { - statement, err := r.parser.ParseStatement(item.Statement) - if err != nil { - return err - } - route, ok := r.routes[key(item)] if !ok { - route.statement = statement + route.statementContext = item.Context + switch item.Context { + case "", "resource": + statement, err := r.resourceParser.ParseStatement(item.Statement) + if err != nil { + return err + } + route.resourceStatement = statement + case "log": + statement, err := r.logParser.ParseStatement(item.Statement) + if err != nil { + return err + } + route.logStatement = statement + } } else { pipelineNames := []string{} for _, pipeline := range item.Pipelines { @@ -157,5 +200,8 @@ func (r *router[C]) registerRouteConsumers() error { } func key(entry RoutingTableItem) string { - return entry.Statement + if entry.Context == "" || entry.Context == "resource" { + return entry.Statement + } + return "[" + entry.Context + "] " + entry.Statement } diff --git a/connector/routingconnector/testdata/logs/log_context/all_match_first_only/config.yaml b/connector/routingconnector/testdata/logs/log_context/all_match_first_only/config.yaml new file mode 100644 index 000000000000..e890865e53dc --- /dev/null +++ b/connector/routingconnector/testdata/logs/log_context/all_match_first_only/config.yaml @@ -0,0 +1,13 @@ +routing: + match_once: true + default_pipelines: + - logs/default + table: + - context: log + condition: attributes["logName"] != nil + pipelines: + - logs/0 + - context: log + condition: attributes["logName"] == "logY" + pipelines: + - logs/1 diff --git a/connector/routingconnector/testdata/logs/log_context/all_match_first_only/input.yaml b/connector/routingconnector/testdata/logs/log_context/all_match_first_only/input.yaml new file mode 100644 index 000000000000..63c6eada6cf9 --- /dev/null +++ b/connector/routingconnector/testdata/logs/log_context/all_match_first_only/input.yaml @@ -0,0 +1,141 @@ +resourceLogs: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 diff --git a/connector/routingconnector/testdata/logs/log_context/all_match_first_only/sink_0.yaml b/connector/routingconnector/testdata/logs/log_context/all_match_first_only/sink_0.yaml new file mode 100644 index 000000000000..63c6eada6cf9 --- /dev/null +++ b/connector/routingconnector/testdata/logs/log_context/all_match_first_only/sink_0.yaml @@ -0,0 +1,141 @@ +resourceLogs: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 diff --git a/connector/routingconnector/testdata/logs/log_context/all_match_last_only/config.yaml b/connector/routingconnector/testdata/logs/log_context/all_match_last_only/config.yaml new file mode 100644 index 000000000000..87873dd530db --- /dev/null +++ b/connector/routingconnector/testdata/logs/log_context/all_match_last_only/config.yaml @@ -0,0 +1,13 @@ +routing: + match_once: true + default_pipelines: + - logs/default + table: + - context: log + condition: attributes["logName"] == "logX" + pipelines: + - logs/0 + - context: log + condition: attributes["logName"] != nil + pipelines: + - logs/1 diff --git a/connector/routingconnector/testdata/logs/log_context/all_match_last_only/input.yaml b/connector/routingconnector/testdata/logs/log_context/all_match_last_only/input.yaml new file mode 100644 index 000000000000..63c6eada6cf9 --- /dev/null +++ b/connector/routingconnector/testdata/logs/log_context/all_match_last_only/input.yaml @@ -0,0 +1,141 @@ +resourceLogs: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 diff --git a/connector/routingconnector/testdata/logs/log_context/all_match_last_only/sink_1.yaml b/connector/routingconnector/testdata/logs/log_context/all_match_last_only/sink_1.yaml new file mode 100644 index 000000000000..63c6eada6cf9 --- /dev/null +++ b/connector/routingconnector/testdata/logs/log_context/all_match_last_only/sink_1.yaml @@ -0,0 +1,141 @@ +resourceLogs: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 diff --git a/connector/routingconnector/testdata/logs/log_context/match_none_with_default/config.yaml b/connector/routingconnector/testdata/logs/log_context/match_none_with_default/config.yaml new file mode 100644 index 000000000000..dacb340e9937 --- /dev/null +++ b/connector/routingconnector/testdata/logs/log_context/match_none_with_default/config.yaml @@ -0,0 +1,13 @@ +routing: + match_once: true + default_pipelines: + - logs/default + table: + - context: log + condition: attributes["logName"] == "logX" + pipelines: + - logs/0 + - context: log + condition: attributes["logName"] == "logY" + pipelines: + - logs/1 diff --git a/connector/routingconnector/testdata/logs/log_context/match_none_with_default/input.yaml b/connector/routingconnector/testdata/logs/log_context/match_none_with_default/input.yaml new file mode 100644 index 000000000000..63c6eada6cf9 --- /dev/null +++ b/connector/routingconnector/testdata/logs/log_context/match_none_with_default/input.yaml @@ -0,0 +1,141 @@ +resourceLogs: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 diff --git a/connector/routingconnector/testdata/logs/log_context/match_none_with_default/sink_default.yaml b/connector/routingconnector/testdata/logs/log_context/match_none_with_default/sink_default.yaml new file mode 100644 index 000000000000..63c6eada6cf9 --- /dev/null +++ b/connector/routingconnector/testdata/logs/log_context/match_none_with_default/sink_default.yaml @@ -0,0 +1,141 @@ +resourceLogs: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 diff --git a/connector/routingconnector/testdata/logs/log_context/match_none_without_default/config.yaml b/connector/routingconnector/testdata/logs/log_context/match_none_without_default/config.yaml new file mode 100644 index 000000000000..74264624fc67 --- /dev/null +++ b/connector/routingconnector/testdata/logs/log_context/match_none_without_default/config.yaml @@ -0,0 +1,12 @@ +routing: + match_once: true + # no default pipelines + table: + - context: log + condition: attributes["logName"] == "logX" + pipelines: + - logs/0 + - context: log + condition: attributes["logName"] == "logY" + pipelines: + - logs/1 diff --git a/connector/routingconnector/testdata/logs/log_context/match_none_without_default/input.yaml b/connector/routingconnector/testdata/logs/log_context/match_none_without_default/input.yaml new file mode 100644 index 000000000000..63c6eada6cf9 --- /dev/null +++ b/connector/routingconnector/testdata/logs/log_context/match_none_without_default/input.yaml @@ -0,0 +1,141 @@ +resourceLogs: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 diff --git a/connector/routingconnector/testdata/logs/log_context/some_match_each_route/config.yaml b/connector/routingconnector/testdata/logs/log_context/some_match_each_route/config.yaml new file mode 100644 index 000000000000..b830ca7e9450 --- /dev/null +++ b/connector/routingconnector/testdata/logs/log_context/some_match_each_route/config.yaml @@ -0,0 +1,13 @@ +routing: + match_once: true + default_pipelines: + - logs/default + table: + - context: log + condition: attributes["logName"] == "logA" and resource.attributes["resourceName"] == "resourceA" + pipelines: + - logs/0 + - context: log + condition: attributes["logName"] == "logB" and resource.attributes["resourceName"] == "resourceB" + pipelines: + - logs/1 diff --git a/connector/routingconnector/testdata/logs/log_context/some_match_each_route/input.yaml b/connector/routingconnector/testdata/logs/log_context/some_match_each_route/input.yaml new file mode 100644 index 000000000000..63c6eada6cf9 --- /dev/null +++ b/connector/routingconnector/testdata/logs/log_context/some_match_each_route/input.yaml @@ -0,0 +1,141 @@ +resourceLogs: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 diff --git a/connector/routingconnector/testdata/logs/log_context/some_match_each_route/sink_0.yaml b/connector/routingconnector/testdata/logs/log_context/some_match_each_route/sink_0.yaml new file mode 100644 index 000000000000..539ec42b1322 --- /dev/null +++ b/connector/routingconnector/testdata/logs/log_context/some_match_each_route/sink_0.yaml @@ -0,0 +1,53 @@ +resourceLogs: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 diff --git a/connector/routingconnector/testdata/logs/log_context/some_match_each_route/sink_1.yaml b/connector/routingconnector/testdata/logs/log_context/some_match_each_route/sink_1.yaml new file mode 100644 index 000000000000..ba61f2992fbf --- /dev/null +++ b/connector/routingconnector/testdata/logs/log_context/some_match_each_route/sink_1.yaml @@ -0,0 +1,53 @@ +resourceLogs: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 diff --git a/connector/routingconnector/testdata/logs/log_context/some_match_each_route/sink_default.yaml b/connector/routingconnector/testdata/logs/log_context/some_match_each_route/sink_default.yaml new file mode 100644 index 000000000000..ee4340abb2cc --- /dev/null +++ b/connector/routingconnector/testdata/logs/log_context/some_match_each_route/sink_default.yaml @@ -0,0 +1,105 @@ +resourceLogs: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 diff --git a/connector/routingconnector/testdata/logs/log_context/with_resource_and_scope_conditions/config.yaml b/connector/routingconnector/testdata/logs/log_context/with_resource_and_scope_conditions/config.yaml new file mode 100644 index 000000000000..26855ab4322d --- /dev/null +++ b/connector/routingconnector/testdata/logs/log_context/with_resource_and_scope_conditions/config.yaml @@ -0,0 +1,13 @@ +routing: + match_once: true + default_pipelines: + - logs/default + table: + - context: log + condition: resource.attributes["resourceName"] == "resourceB" and instrumentation_scope.name == "scopeA" and attributes["logName"] != nil + pipelines: + - logs/0 + - context: log + condition: attributes["logName"] == "logY" + pipelines: + - logs/1 diff --git a/connector/routingconnector/testdata/logs/log_context/with_resource_and_scope_conditions/input.yaml b/connector/routingconnector/testdata/logs/log_context/with_resource_and_scope_conditions/input.yaml new file mode 100644 index 000000000000..63c6eada6cf9 --- /dev/null +++ b/connector/routingconnector/testdata/logs/log_context/with_resource_and_scope_conditions/input.yaml @@ -0,0 +1,141 @@ +resourceLogs: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 diff --git a/connector/routingconnector/testdata/logs/log_context/with_resource_and_scope_conditions/sink_0.yaml b/connector/routingconnector/testdata/logs/log_context/with_resource_and_scope_conditions/sink_0.yaml new file mode 100644 index 000000000000..d42bbbcd478c --- /dev/null +++ b/connector/routingconnector/testdata/logs/log_context/with_resource_and_scope_conditions/sink_0.yaml @@ -0,0 +1,41 @@ +resourceLogs: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 diff --git a/connector/routingconnector/testdata/logs/log_context/with_resource_and_scope_conditions/sink_default.yaml b/connector/routingconnector/testdata/logs/log_context/with_resource_and_scope_conditions/sink_default.yaml new file mode 100644 index 000000000000..28fed8ee680e --- /dev/null +++ b/connector/routingconnector/testdata/logs/log_context/with_resource_and_scope_conditions/sink_default.yaml @@ -0,0 +1,111 @@ +resourceLogs: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 diff --git a/connector/routingconnector/testdata/logs/log_context/with_resource_condition/config.yaml b/connector/routingconnector/testdata/logs/log_context/with_resource_condition/config.yaml new file mode 100644 index 000000000000..1907cfd8cd0e --- /dev/null +++ b/connector/routingconnector/testdata/logs/log_context/with_resource_condition/config.yaml @@ -0,0 +1,13 @@ +routing: + match_once: true + default_pipelines: + - logs/default + table: + - context: log + condition: resource.attributes["resourceName"] == "resourceB" and attributes["logName"] != nil + pipelines: + - logs/0 + - context: log + condition: attributes["logName"] == "logY" + pipelines: + - logs/1 diff --git a/connector/routingconnector/testdata/logs/log_context/with_resource_condition/input.yaml b/connector/routingconnector/testdata/logs/log_context/with_resource_condition/input.yaml new file mode 100644 index 000000000000..63c6eada6cf9 --- /dev/null +++ b/connector/routingconnector/testdata/logs/log_context/with_resource_condition/input.yaml @@ -0,0 +1,141 @@ +resourceLogs: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 diff --git a/connector/routingconnector/testdata/logs/log_context/with_resource_condition/sink_0.yaml b/connector/routingconnector/testdata/logs/log_context/with_resource_condition/sink_0.yaml new file mode 100644 index 000000000000..28a5a7c8b0f5 --- /dev/null +++ b/connector/routingconnector/testdata/logs/log_context/with_resource_condition/sink_0.yaml @@ -0,0 +1,71 @@ +resourceLogs: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 diff --git a/connector/routingconnector/testdata/logs/log_context/with_resource_condition/sink_default.yaml b/connector/routingconnector/testdata/logs/log_context/with_resource_condition/sink_default.yaml new file mode 100644 index 000000000000..72f617672bf3 --- /dev/null +++ b/connector/routingconnector/testdata/logs/log_context/with_resource_condition/sink_default.yaml @@ -0,0 +1,71 @@ +resourceLogs: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 diff --git a/connector/routingconnector/testdata/logs/log_context/with_scope_condition/config.yaml b/connector/routingconnector/testdata/logs/log_context/with_scope_condition/config.yaml new file mode 100644 index 000000000000..1b6eeba670b4 --- /dev/null +++ b/connector/routingconnector/testdata/logs/log_context/with_scope_condition/config.yaml @@ -0,0 +1,13 @@ +routing: + match_once: true + default_pipelines: + - logs/default + table: + - context: log + condition: instrumentation_scope.name == "scopeB" and attributes["logName"] != nil + pipelines: + - logs/0 + - context: log + condition: attributes["logName"] == "logY" + pipelines: + - logs/1 diff --git a/connector/routingconnector/testdata/logs/log_context/with_scope_condition/input.yaml b/connector/routingconnector/testdata/logs/log_context/with_scope_condition/input.yaml new file mode 100644 index 000000000000..63c6eada6cf9 --- /dev/null +++ b/connector/routingconnector/testdata/logs/log_context/with_scope_condition/input.yaml @@ -0,0 +1,141 @@ +resourceLogs: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 diff --git a/connector/routingconnector/testdata/logs/log_context/with_scope_condition/sink_0.yaml b/connector/routingconnector/testdata/logs/log_context/with_scope_condition/sink_0.yaml new file mode 100644 index 000000000000..8c8745158e33 --- /dev/null +++ b/connector/routingconnector/testdata/logs/log_context/with_scope_condition/sink_0.yaml @@ -0,0 +1,81 @@ +resourceLogs: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 diff --git a/connector/routingconnector/testdata/logs/log_context/with_scope_condition/sink_default.yaml b/connector/routingconnector/testdata/logs/log_context/with_scope_condition/sink_default.yaml new file mode 100644 index 000000000000..71ca02311582 --- /dev/null +++ b/connector/routingconnector/testdata/logs/log_context/with_scope_condition/sink_default.yaml @@ -0,0 +1,81 @@ +resourceLogs: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 diff --git a/connector/routingconnector/testdata/logs/mixed_context/match_logs_then_resource/config.yaml b/connector/routingconnector/testdata/logs/mixed_context/match_logs_then_resource/config.yaml new file mode 100644 index 000000000000..14fc87417bf2 --- /dev/null +++ b/connector/routingconnector/testdata/logs/mixed_context/match_logs_then_resource/config.yaml @@ -0,0 +1,13 @@ +routing: + match_once: true + default_pipelines: + - logs/default + table: + - context: log + condition: attributes["logName"] == "logA" + pipelines: + - logs/0 + - context: resource + condition: attributes["resourceName"] == "resourceB" + pipelines: + - logs/1 diff --git a/connector/routingconnector/testdata/logs/mixed_context/match_logs_then_resource/input.yaml b/connector/routingconnector/testdata/logs/mixed_context/match_logs_then_resource/input.yaml new file mode 100644 index 000000000000..63c6eada6cf9 --- /dev/null +++ b/connector/routingconnector/testdata/logs/mixed_context/match_logs_then_resource/input.yaml @@ -0,0 +1,141 @@ +resourceLogs: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 diff --git a/connector/routingconnector/testdata/logs/mixed_context/match_logs_then_resource/sink_0.yaml b/connector/routingconnector/testdata/logs/mixed_context/match_logs_then_resource/sink_0.yaml new file mode 100644 index 000000000000..39604c6017d6 --- /dev/null +++ b/connector/routingconnector/testdata/logs/mixed_context/match_logs_then_resource/sink_0.yaml @@ -0,0 +1,105 @@ +resourceLogs: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 diff --git a/connector/routingconnector/testdata/logs/mixed_context/match_logs_then_resource/sink_1.yaml b/connector/routingconnector/testdata/logs/mixed_context/match_logs_then_resource/sink_1.yaml new file mode 100644 index 000000000000..ba61f2992fbf --- /dev/null +++ b/connector/routingconnector/testdata/logs/mixed_context/match_logs_then_resource/sink_1.yaml @@ -0,0 +1,53 @@ +resourceLogs: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 diff --git a/connector/routingconnector/testdata/logs/mixed_context/match_logs_then_resource/sink_default.yaml b/connector/routingconnector/testdata/logs/mixed_context/match_logs_then_resource/sink_default.yaml new file mode 100644 index 000000000000..b20626892e83 --- /dev/null +++ b/connector/routingconnector/testdata/logs/mixed_context/match_logs_then_resource/sink_default.yaml @@ -0,0 +1,53 @@ +resourceLogs: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 \ No newline at end of file diff --git a/connector/routingconnector/testdata/logs/mixed_context/match_resource_then_logs/config.yaml b/connector/routingconnector/testdata/logs/mixed_context/match_resource_then_logs/config.yaml new file mode 100644 index 000000000000..ab15a654b35a --- /dev/null +++ b/connector/routingconnector/testdata/logs/mixed_context/match_resource_then_logs/config.yaml @@ -0,0 +1,13 @@ +routing: + match_once: true + default_pipelines: + - logs/default + table: + - context: resource + condition: attributes["resourceName"] == "resourceA" + pipelines: + - logs/0 + - context: log + condition: attributes["logName"] == "logB" + pipelines: + - logs/1 diff --git a/connector/routingconnector/testdata/logs/mixed_context/match_resource_then_logs/input.yaml b/connector/routingconnector/testdata/logs/mixed_context/match_resource_then_logs/input.yaml new file mode 100644 index 000000000000..63c6eada6cf9 --- /dev/null +++ b/connector/routingconnector/testdata/logs/mixed_context/match_resource_then_logs/input.yaml @@ -0,0 +1,141 @@ +resourceLogs: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 diff --git a/connector/routingconnector/testdata/logs/mixed_context/match_resource_then_logs/sink_0.yaml b/connector/routingconnector/testdata/logs/mixed_context/match_resource_then_logs/sink_0.yaml new file mode 100644 index 000000000000..72f617672bf3 --- /dev/null +++ b/connector/routingconnector/testdata/logs/mixed_context/match_resource_then_logs/sink_0.yaml @@ -0,0 +1,71 @@ +resourceLogs: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 diff --git a/connector/routingconnector/testdata/logs/mixed_context/match_resource_then_logs/sink_1.yaml b/connector/routingconnector/testdata/logs/mixed_context/match_resource_then_logs/sink_1.yaml new file mode 100644 index 000000000000..ba61f2992fbf --- /dev/null +++ b/connector/routingconnector/testdata/logs/mixed_context/match_resource_then_logs/sink_1.yaml @@ -0,0 +1,53 @@ +resourceLogs: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logB + - key: logNameAgain + value: + stringValue: logB + body: + stringValue: logB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 diff --git a/connector/routingconnector/testdata/logs/mixed_context/match_resource_then_logs/sink_default.yaml b/connector/routingconnector/testdata/logs/mixed_context/match_resource_then_logs/sink_default.yaml new file mode 100644 index 000000000000..a2e7ef72f97e --- /dev/null +++ b/connector/routingconnector/testdata/logs/mixed_context/match_resource_then_logs/sink_default.yaml @@ -0,0 +1,53 @@ +resourceLogs: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeLogs: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeA + version: v0.1.0 + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + logRecords: + - attributes: + - key: logName + value: + stringValue: logA + - key: logNameAgain + value: + stringValue: logA + body: + stringValue: logA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scope: + name: scopeB + version: v0.1.0 diff --git a/connector/routingconnector/traces.go b/connector/routingconnector/traces.go index 73da17b7e3f1..98906fd82460 100644 --- a/connector/routingconnector/traces.go +++ b/connector/routingconnector/traces.go @@ -72,7 +72,7 @@ func (c *tracesConnector) ConsumeTraces(ctx context.Context, t ptrace.Traces) er noRoutesMatch := true for _, route := range c.router.routeSlice { - _, isMatch, err := route.statement.Execute(ctx, rtx) + _, isMatch, err := route.resourceStatement.Execute(ctx, rtx) if err != nil { if c.config.ErrorMode == ottl.PropagateError { return err