From ac38b6d23c8bc4b3173b9e759b58d9c91ac1e8ae Mon Sep 17 00:00:00 2001 From: Daniel Jaglowski Date: Thu, 24 Mar 2022 09:46:05 -0400 Subject: [PATCH] Remove '$' from field syntax (#364) * Remove '$' from field syntax * Enforce rule that body fields must start with 'body' --- docs/operators/add.md | 10 +- docs/operators/copy.md | 6 +- docs/operators/csv_parser.md | 4 +- docs/operators/filter.md | 6 +- docs/operators/json_parser.md | 4 +- docs/operators/metadata.md | 2 +- docs/operators/move.md | 8 +- docs/operators/recombine.md | 4 +- docs/operators/regex_parser.md | 8 +- docs/operators/remove.md | 10 +- docs/operators/retain.md | 12 +- docs/operators/router.md | 8 +- docs/operators/syslog_parser.md | 4 +- docs/operators/uri_parser.md | 4 +- docs/pipeline.md | 4 +- docs/types/expression.md | 8 +- docs/types/field.md | 20 +- entry/attribute_field.go | 4 +- entry/attribute_field_test.go | 4 +- entry/body_field.go | 52 ++++-- entry/body_field_test.go | 175 +++++++++++++----- entry/entry_test.go | 26 ++- entry/field.go | 12 +- entry/field_test.go | 112 +++++------ entry/resource_field.go | 4 +- entry/resource_field_test.go | 4 +- operator/helper/expr_string.go | 8 +- operator/helper/expr_string_test.go | 8 +- operator/helper/parser_test.go | 4 +- .../testdata/severity/parse_from_simple.yaml | 2 +- .../helper/testdata/severity/preserve_to.yaml | 2 +- .../helper/testdata/severity/severity.yaml | 3 +- operator/helper/testdata/time/parse_from.yaml | 2 +- .../helper/testdata/time/preserve_to.yaml | 2 +- operator/helper/transformer_test.go | 6 +- operator/parser/csv/testdata/basic.yaml | 2 +- operator/parser/csv/testdata/delimiter.yaml | 2 +- .../parser/csv/testdata/header_attribute.yaml | 2 +- operator/parser/csv/testdata/lazy_quotes.yaml | 2 +- operator/parser/csv/testdata/timestamp.yaml | 2 +- operator/parser/json/json_test.go | 8 +- .../json/testdata/parse_from_simple.yaml | 2 +- .../parser/json/testdata/parse_to_simple.yaml | 2 +- .../parser/json/testdata/preserve_to.yaml | 2 +- operator/parser/json/testdata/severity.yaml | 2 +- operator/parser/json/testdata/timestamp.yaml | 2 +- operator/parser/regex/regex_test.go | 8 +- .../regex/testdata/parse_from_simple.yaml | 2 +- .../regex/testdata/parse_to_simple.yaml | 2 +- .../parser/regex/testdata/preserve_to.yaml | 2 +- operator/parser/regex/testdata/severity.yaml | 2 +- operator/parser/regex/testdata/timestamp.yaml | 2 +- operator/parser/severity/severity_test.go | 4 +- operator/parser/syslog/syslog_test.go | 8 +- operator/parser/time/time_test.go | 10 +- operator/parser/trace/testdata/spanid.yaml | 4 +- .../parser/trace/testdata/trace_flags.yaml | 4 +- operator/parser/trace/testdata/traceid.yaml | 4 +- .../uri/testdata/parse_from_simple.yaml | 2 +- .../parser/uri/testdata/parse_to_simple.yaml | 2 +- operator/parser/uri/testdata/preserve_to.yaml | 2 +- operator/parser/uri/testdata/severity.yaml | 2 +- operator/parser/uri/testdata/timestamp.yaml | 2 +- operator/parser/uri/uri_test.go | 8 +- operator/transformer/add/add_test.go | 4 +- operator/transformer/add/config_test.go | 4 +- .../add/testdata/add_array_to_body.yaml | 2 +- .../add/testdata/add_attribute.yaml | 2 +- .../transformer/add/testdata/add_expr.yaml | 4 +- .../transformer/add/testdata/add_nest.yaml | 2 +- .../add/testdata/add_resource.yaml | 2 +- .../add/testdata/add_resource_expr.yaml | 4 +- .../transformer/add/testdata/add_value.yaml | 2 +- .../copy/testdata/attribute_to_body.yaml | 4 +- .../copy/testdata/attribute_to_resource.yaml | 4 +- .../copy/testdata/body_to_attribute.yaml | 4 +- .../copy/testdata/body_to_body.yaml | 4 +- operator/transformer/filter/filter_test.go | 10 +- operator/transformer/flatten/config_test.go | 4 +- .../flatten/{flaltten.go => flatten.go} | 2 +- operator/transformer/flatten/flatten_test.go | 2 +- .../flatten/testdata/flatten_attributes.yaml | 2 +- .../flatten/testdata/flatten_one_level.yaml | 2 +- .../testdata/flatten_second_level.yaml | 2 +- operator/transformer/move/config_test.go | 27 --- .../move/testdata/implicit_body_from.yaml | 3 - .../move/testdata/implicit_body_to.yaml | 3 - .../move/testdata/implicit_nested_key.yaml | 3 - .../move/testdata/move_attribute_to_body.yaml | 4 +- .../testdata/move_attribute_to_resource.yaml | 4 +- .../move/testdata/move_body_to_attribute.yaml | 4 +- .../move/testdata/move_body_to_body.yaml | 4 +- .../move_bracketed_attribute_to_resource.yaml | 4 +- .../testdata/move_double_nested_object.yaml | 4 +- .../testdata/move_from_nested_object.yaml | 4 +- .../move/testdata/move_nested.yaml | 4 +- .../testdata/move_nested_to_attribute.yaml | 4 +- .../testdata/move_nested_to_resource.yaml | 4 +- .../testdata/move_resource_to_attribute.yaml | 4 +- .../move/testdata/move_to_nested_object.yaml | 4 +- .../move/testdata/replace_body.yaml | 4 +- .../transformer/recombine/recombine_test.go | 16 +- operator/transformer/remove/rootable_field.go | 2 +- .../remove/testdata/remove_body.yaml | 2 +- .../testdata/remove_entire_attributes.yaml | 2 +- .../remove/testdata/remove_entire_body.yaml | 2 +- .../testdata/remove_entire_resource.yaml | 2 +- .../testdata/remove_single_attribute.yaml | 2 +- .../testdata/remove_single_resource.yaml | 2 +- .../restructure/restructure_test.go | 44 ++--- operator/transformer/retain/retain.go | 4 +- .../retain/testdata/retain_multi.yaml | 4 +- .../testdata/retain_multi_attribute.yaml | 4 +- .../testdata/retain_multi_resource.yaml | 4 +- .../retain/testdata/retain_one_of_each.yaml | 6 +- .../retain/testdata/retain_single.yaml | 2 +- .../testdata/retain_single_attribute.yaml | 2 +- .../testdata/retain_single_resource.yaml | 2 +- operator/transformer/router/config_test.go | 12 +- operator/transformer/router/router_test.go | 8 +- .../router/testdata/routes_attributes.yaml | 2 +- .../router/testdata/routes_default.yaml | 2 +- .../router/testdata/routes_multi.yaml | 6 +- .../router/testdata/routes_one.yaml | 2 +- 124 files changed, 501 insertions(+), 437 deletions(-) rename operator/transformer/flatten/{flaltten.go => flatten.go} (96%) delete mode 100644 operator/transformer/move/testdata/implicit_body_from.yaml delete mode 100644 operator/transformer/move/testdata/implicit_body_to.yaml delete mode 100644 operator/transformer/move/testdata/implicit_nested_key.yaml diff --git a/docs/operators/add.md b/docs/operators/add.md index 57f3d5d3..d20eb052 100644 --- a/docs/operators/add.md +++ b/docs/operators/add.md @@ -64,7 +64,7 @@ Add a value to the body using an expression ```yaml - type: add field: key2 - value: EXPR($.key1 + "_suffix") + value: EXPR(body.key1 + "_suffix") ``` @@ -150,7 +150,7 @@ Add a value to attributes ```yaml - type: add - field: $attributes.key2 + field: attributes.key2 value: val2 ``` @@ -193,7 +193,7 @@ Add a value to resource ```yaml - type: add - field: $resource.key2 + field: resource.key2 value: val2 ``` @@ -235,8 +235,8 @@ Add a value to resource using an expression ```yaml - type: add - field: $resource.key2 - value: EXPR($.key1 + "_suffix") + field: resource.key2 + value: EXPR(body.key1 + "_suffix") ```
diff --git a/docs/operators/copy.md b/docs/operators/copy.md index 6fc9fe2a..c9097e8c 100644 --- a/docs/operators/copy.md +++ b/docs/operators/copy.md @@ -21,7 +21,7 @@ Copy a value from the body to resource ```yaml - type: copy from: key - to: $resource.newkey + to: resource.newkey ```
@@ -64,7 +64,7 @@ Copy a value from the body to attributes ```yaml - type: copy from: key2 - to: $attributes.newkey + to: attributes.newkey ```
@@ -108,7 +108,7 @@ Copy a value from the body to attributes Copy a value from attributes to the body ```yaml - type: copy - from: $attributes.key + from: attributes.key to: newkey ``` diff --git a/docs/operators/csv_parser.md b/docs/operators/csv_parser.md index a034fdb4..72d113bc 100644 --- a/docs/operators/csv_parser.md +++ b/docs/operators/csv_parser.md @@ -12,8 +12,8 @@ The `csv_parser` operator parses the string-type field selected by `parse_from` | `header_attribute` | required when `header` not set | An attribute name to read the header field from, to support dynamic field names | | `delimiter` | `,` | A character that will be used as a delimiter. Values `\r` and `\n` cannot be used as a delimiter. | | `lazy_quotes` | `false` | If true, a quote may appear in an unquoted field and a non-doubled quote may appear in a quoted field. | -| `parse_from` | $body | The [field](/docs/types/field.md) from which the value will be parsed. | -| `parse_to` | $body | The [field](/docs/types/field.md) to which the value will be parsed. | +| `parse_from` | `body` | The [field](/docs/types/field.md) from which the value will be parsed. | +| `parse_to` | `body` | The [field](/docs/types/field.md) to which the value will be parsed. | | `preserve_to` | | Preserves the unparsed value at the specified [field](/docs/types/field.md). | | `on_error` | `send` | The behavior of the operator if it encounters an error. See [on_error](/docs/types/on_error.md). | | `timestamp` | `nil` | An optional [timestamp](/docs/types/timestamp.md) block which will parse a timestamp field before passing the entry to the output operator. | diff --git a/docs/operators/filter.md b/docs/operators/filter.md index 88151bff..a32b71d7 100644 --- a/docs/operators/filter.md +++ b/docs/operators/filter.md @@ -17,7 +17,7 @@ The `filter` operator filters incoming entries that match an expression. ```yaml - type: filter - expr: '$body.message matches "^LOG: .* END$"' + expr: 'body.message matches "^LOG: .* END$"' output: my_output ``` @@ -25,7 +25,7 @@ The `filter` operator filters incoming entries that match an expression. ```yaml - type: filter - expr: '$attributes.env == "production"' + expr: 'attributes.env == "production"' output: my_output ``` @@ -33,6 +33,6 @@ The `filter` operator filters incoming entries that match an expression. ```yaml - type: filter - expr: '$body.message == env("MY_ENV_VARIABLE")' + expr: 'body.message == env("MY_ENV_VARIABLE")' output: my_output ``` diff --git a/docs/operators/json_parser.md b/docs/operators/json_parser.md index 6fe3f219..0cd91ce1 100644 --- a/docs/operators/json_parser.md +++ b/docs/operators/json_parser.md @@ -8,8 +8,8 @@ The `json_parser` operator parses the string-type field selected by `parse_from` | --- | --- | --- | | `id` | `json_parser` | A unique identifier for the operator. | | `output` | Next in pipeline | The connected operator(s) that will receive all outbound entries. | -| `parse_from` | `$body` | The [field](/docs/types/field.md) from which the value will be parsed. | -| `parse_to` | `$body` | The [field](/docs/types/field.md) to which the value will be parsed. | +| `parse_from` | `body` | The [field](/docs/types/field.md) from which the value will be parsed. | +| `parse_to` | `body` | The [field](/docs/types/field.md) to which the value will be parsed. | | `preserve_to` | | Preserves the unparsed value at the specified [field](/docs/types/field.md). | | `on_error` | `send` | The behavior of the operator if it encounters an error. See [on_error](/docs/types/on_error.md). | | `if` | | An [expression](/docs/types/expression.md) that, when set, will be evaluated to determine whether this operator should be used for the given entry. This allows you to do easy conditional parsing without branching logic with routers. | diff --git a/docs/operators/metadata.md b/docs/operators/metadata.md index 4e734b59..39f27085 100644 --- a/docs/operators/metadata.md +++ b/docs/operators/metadata.md @@ -74,7 +74,7 @@ Configuration: - type: metadata output: metadata_receiver attributes: - environment: 'EXPR( $.environment == "production" ? "prod" : "dev" )' + environment: 'EXPR( body.environment == "production" ? "prod" : "dev" )' ```
diff --git a/docs/operators/move.md b/docs/operators/move.md index 5ca3d8c2..30ac2c5d 100644 --- a/docs/operators/move.md +++ b/docs/operators/move.md @@ -104,7 +104,7 @@ Move a value from the body to attributes ```yaml - type: move from: ip - to: $attributes.ip + to: attributes.ip ```
@@ -145,7 +145,7 @@ Replace the body with an individual value nested within the body ```yaml - type: move from: log - to: $body + to: body ```
@@ -184,7 +184,7 @@ Remove a layer from the body ```yaml - type: move from: wrapper - to: $body + to: body ```
@@ -232,7 +232,7 @@ Merge a layer to the body ```yaml - type: move from: object - to: $body + to: body ```
diff --git a/docs/operators/recombine.md b/docs/operators/recombine.md index c4cb6d94..53bfcc71 100644 --- a/docs/operators/recombine.md +++ b/docs/operators/recombine.md @@ -40,7 +40,7 @@ Configuration: - type: recombine combine_field: message combine_with: "" - is_last_entry: "$body.logtag == 'F'" + is_last_entry: "body.logtag == 'F'" overwrite_with: "newest" ``` @@ -101,7 +101,7 @@ This can be expressed with the following configuration: ```yaml - type: recombine combine_field: message - is_first_entry: $body.message matches "^[^\s]" + is_first_entry: body.message matches "^[^\s]" ``` Given the following input file: diff --git a/docs/operators/regex_parser.md b/docs/operators/regex_parser.md index c275a25b..27e96bd4 100644 --- a/docs/operators/regex_parser.md +++ b/docs/operators/regex_parser.md @@ -13,8 +13,8 @@ This operator makes use of [Go regular expression](https://github.com/google/re2 | `id` | `regex_parser` | A unique identifier for the operator. | | `output` | Next in pipeline | The connected operator(s) that will receive all outbound entries. | | `regex` | required | A [Go regular expression](https://github.com/google/re2/wiki/Syntax). The named capture groups will be extracted as fields in the parsed body. | -| `parse_from` | `$body` | The [field](/docs/types/field.md) from which the value will be parsed. | -| `parse_to` | `$body` | The [field](/docs/types/field.md) to which the value will be parsed. | +| `parse_from` | `body` | The [field](/docs/types/field.md) from which the value will be parsed. | +| `parse_to` | `body` | The [field](/docs/types/field.md) to which the value will be parsed. | | `preserve_to` | | Preserves the unparsed value at the specified [field](/docs/types/field.md). | | `on_error` | `send` | The behavior of the operator if it encounters an error. See [on_error](/docs/types/on_error.md). | | `if` | | An [expression](/docs/types/expression.md) that, when set, will be evaluated to determine whether this operator should be used for the given entry. This allows you to do easy conditional parsing without branching logic with routers. | @@ -162,7 +162,7 @@ Configuration: - type: regex_parser regex: '^Host=(?)$' parse_from: message - if: '$body.type == "hostname"' + if: 'body.type == "hostname"' ```
@@ -229,7 +229,7 @@ Configuration: - type: regex_parser regex: '^Host=(?)$' parse_from: message - if: '$body.type == "hostname"' + if: 'body.type == "hostname"' ```
diff --git a/docs/operators/remove.md b/docs/operators/remove.md index 652e119d..35c5b220 100644 --- a/docs/operators/remove.md +++ b/docs/operators/remove.md @@ -8,7 +8,7 @@ The `remove` operator removes a field from a record. | --- | --- | --- | | `id` | `remove` | A unique identifier for the operator. | | `output` | Next in pipeline | The connected operator(s) that will receive all outbound entries. | -| `field` | required | The [field](/docs/types/field.md) to remove. if '$attributes' or '$resource' is specified, all fields of that type will be removed. | +| `field` | required | The [field](/docs/types/field.md) to remove. if 'attributes' or 'resource' is specified, all fields of that type will be removed. | | `on_error` | `send` | The behavior of the operator if it encounters an error. See [on_error](/docs/types/on_error.md). | | `if` | | An [expression](/docs/types/expression.md) that, when set, will be evaluated to determine whether this operator should be used for the given entry. This allows you to do easy conditional parsing without branching logic with routers. | @@ -100,7 +100,7 @@ Remove an object from the body Remove a value from attributes ```yaml - type: remove - field: $attributes.otherkey + field: attributes.otherkey ```
@@ -142,7 +142,7 @@ Remove a value from attributes Remove a value from resource ```yaml - type: remove - field: $resource.otherkey + field: resource.otherkey ```
@@ -184,7 +184,7 @@ Remove a value from resource Remove all resource fields ```yaml - type: remove - field: $resource + field: resource ```
@@ -227,7 +227,7 @@ Remove all resource fields Remove all attributes ```yaml - type: remove - field: $attributes + field: attributes ```
diff --git a/docs/operators/retain.md b/docs/operators/retain.md index 82e33c1b..fd028547 100644 --- a/docs/operators/retain.md +++ b/docs/operators/retain.md @@ -115,8 +115,8 @@ Retain fields from resource ```yaml - type: retain fields: - - $resource.key1 - - $resource.key2 + - resource.key1 + - resource.key2 ```
@@ -165,8 +165,8 @@ Retain fields from attributes ```yaml - type: retain fields: - - $attributes.key1 - - $attributes.key2 + - attributes.key1 + - attributes.key2 ```
@@ -214,8 +214,8 @@ Retain fields from all sources ```yaml - type: retain fields: - - $resource.key1 - - $attributes.key3 + - resource.key1 + - attributes.key3 - key5 ``` diff --git a/docs/operators/router.md b/docs/operators/router.md index 75a9559b..0703469c 100644 --- a/docs/operators/router.md +++ b/docs/operators/router.md @@ -33,9 +33,9 @@ An entry that does not match any of the routes is dropped and not processed furt - type: router routes: - output: my_json_parser - expr: '$.format == "json"' + expr: 'body.format == "json"' - output: my_syslog_parser - expr: '$.format == "syslog"' + expr: 'body.format == "syslog"' ``` #### Drop entries based on content @@ -44,7 +44,7 @@ An entry that does not match any of the routes is dropped and not processed furt - type: router routes: - output: my_output - expr: '$.message matches "^LOG: .* END$"' + expr: 'body.message matches "^LOG: .* END$"' ``` #### Route with a default @@ -53,6 +53,6 @@ An entry that does not match any of the routes is dropped and not processed furt - type: router routes: - output: my_json_parser - expr: '$.format == "json"' + expr: 'body.format == "json"' default: catchall ``` diff --git a/docs/operators/syslog_parser.md b/docs/operators/syslog_parser.md index 83dec741..3d441e87 100644 --- a/docs/operators/syslog_parser.md +++ b/docs/operators/syslog_parser.md @@ -8,8 +8,8 @@ The `syslog_parser` operator parses the string-type field selected by `parse_fro | --- | --- | --- | | `id` | `syslog_parser` | A unique identifier for the operator. | | `output` | Next in pipeline | The connected operator(s) that will receive all outbound entries. | -| `parse_from` | `$body` | The [field](/docs/types/field.md) from which the value will be parsed. | -| `parse_to` | `$body` | The [field](/docs/types/field.md) to which the value will be parsed. | +| `parse_from` | `body` | The [field](/docs/types/field.md) from which the value will be parsed. | +| `parse_to` | `body` | The [field](/docs/types/field.md) to which the value will be parsed. | | `preserve_to` | | Preserves the unparsed value at the specified [field](/docs/types/field.md). | | `on_error` | `send` | The behavior of the operator if it encounters an error. See [on_error](/docs/types/on_error.md). | | `protocol` | required | The protocol to parse the syslog messages as. Options are `rfc3164` and `rfc5424`. | diff --git a/docs/operators/uri_parser.md b/docs/operators/uri_parser.md index 740ea200..4a274867 100644 --- a/docs/operators/uri_parser.md +++ b/docs/operators/uri_parser.md @@ -17,8 +17,8 @@ The `uri_parser` operator parses the string-type field selected by `parse_from` | --- | --- | --- | | `id` | `uri_parser` | A unique identifier for the operator. | | `output` | Next in pipeline | The connected operator(s) that will receive all outbound entries. | -| `parse_from` | `$body` | The [field](/docs/types/field.md) from which the value will be parsed. | -| `parse_to` | `$body` | The [field](/docs/types/field.md) to which the value will be parsed. | +| `parse_from` | `body` | The [field](/docs/types/field.md) from which the value will be parsed. | +| `parse_to` | `body` | The [field](/docs/types/field.md) to which the value will be parsed. | | `preserve_to` | | Preserves the unparsed value at the specified [field](/docs/types/field.md). | | `on_error` | `send` | The behavior of the operator if it encounters an error. See [on_error](/docs/types/on_error.md). | | `if` | | An [expression](/docs/types/expression.md) that, when set, will be evaluated to determine whether this operator should be used for the given entry. This allows you to do easy conditional parsing without branching logic with routers. | diff --git a/docs/pipeline.md b/docs/pipeline.md index 99736134..221c6541 100644 --- a/docs/pipeline.md +++ b/docs/pipeline.md @@ -144,9 +144,9 @@ pipeline: # Route based on log type - type: router routes: - - expr: '$body startsWith "ERROR"' + - expr: 'body startsWith "ERROR"' output: error_parser - - expr: '$body startsWith "INFO"' + - expr: 'body startsWith "INFO"' output: info_parser # Parse logs with format one diff --git a/docs/types/expression.md b/docs/types/expression.md index c9dd0930..f1e23243 100644 --- a/docs/types/expression.md +++ b/docs/types/expression.md @@ -7,10 +7,10 @@ being processed. For reference documentation of the expression language, see [here](https://github.com/antonmedv/expr/blob/master/docs/Language-Definition.md). Available to the expressions are a few special variables: -- `$body` contains the entry's body -- `$attributes` contains the entry's attributes -- `$resource` contains the entry's resource -- `$timestamp` contains the entry's timestamp +- `body` contains the entry's body +- `attributes` contains the entry's attributes +- `resource` contains the entry's resource +- `timestamp` contains the entry's timestamp - `env()` is a function that allows you to read environment variables ## Examples diff --git a/docs/types/field.md b/docs/types/field.md index 5aec9889..f46b90cf 100644 --- a/docs/types/field.md +++ b/docs/types/field.md @@ -6,13 +6,13 @@ Many [operators](/docs/operators/README.md) use fields in their configurations. Fields are `.`-delimited strings which allow you to select attributes or body on the entry. -Fields can be used to select body, resource, or attribute values. For values on the body, use the prefix `$body` such as `$body.my_value`. To select an attributes, prefix your field with `$attributes` such as with `$attributes.my_attribute`. For resource values, use the prefix `$resource`. +Fields can be used to select body, resource, or attribute values. For values on the body, use the prefix `body` such as `body.my_value`. To select an attributes, prefix your field with `attributes` such as with `attributes.my_attribute`. For resource values, use the prefix `resource`. -If a field contains a dot in it, a field can alternatively use bracket syntax for traversing through a map. For example, to select the key `k8s.cluster.name` on the entry's body, you can use the field `$body["k8s.cluster.name"]`. +If a field contains a dot in it, a field can alternatively use bracket syntax for traversing through a map. For example, to select the key `k8s.cluster.name` on the entry's body, you can use the field `body["k8s.cluster.name"]`. -Body fields can be nested arbitrarily deeply, such as `$body.my_value.my_nested_value`. +Body fields can be nested arbitrarily deeply, such as `body.my_value.my_nested_value`. -If a field does not start with `$resource`, `$attributes`, or `$body`, then `$body` is assumed. For example, `my_value` is equivalent to `$body.my_value`. +If a field does not start with `resource`, `attributes`, or `body`, then `body` is assumed. For example, `my_value` is equivalent to `body.my_value`. ## Examples @@ -25,9 +25,9 @@ Config: - add: field: "key3" value: "value3" - - remove: "$body.key2.nested_key1" + - remove: "body.key2.nested_key1" - add: - field: "$attributes.my_attribute" + field: "attributes.my_attribute" value: "my_attribute_value" ``` @@ -98,8 +98,8 @@ Given the following entry, we can use fields as follows: | Field | Refers to Value | | --- | --- | -| $body.message | `"Something happened."` | +| body.message | `"Something happened."` | | message | `"Something happened."` | -| $body.details.count | `100` | -| $attributes.env | `"prod"` | -| $resource.uuid | `"11112222-3333-4444-5555-666677778888"` | +| body.details.count | `100` | +| attributes.env | `"prod"` | +| resource.uuid | `"11112222-3333-4444-5555-666677778888"` | diff --git a/entry/attribute_field.go b/entry/attribute_field.go index 0cf131b0..8e524300 100644 --- a/entry/attribute_field.go +++ b/entry/attribute_field.go @@ -60,9 +60,9 @@ func (l AttributeField) Delete(entry *Entry) (interface{}, bool) { func (l AttributeField) String() string { if strings.Contains(l.key, ".") { - return fmt.Sprintf(`$attributes['%s']`, l.key) + return fmt.Sprintf(`attributes['%s']`, l.key) } - return "$attributes." + l.key + return "attributes." + l.key } // NewAttributeField will creat a new attribute field from a key diff --git a/entry/attribute_field_test.go b/entry/attribute_field_test.go index f90e976a..2ddd647a 100644 --- a/entry/attribute_field_test.go +++ b/entry/attribute_field_test.go @@ -195,12 +195,12 @@ func TestAttributeFieldString(t *testing.T) { { "Simple", AttributeField{"foo"}, - "$attributes.foo", + "attributes.foo", }, { "Empty", AttributeField{""}, - "$attributes.", + "attributes.", }, } diff --git a/entry/body_field.go b/entry/body_field.go index e0f6e229..ac197795 100644 --- a/entry/body_field.go +++ b/entry/body_field.go @@ -25,6 +25,16 @@ type BodyField struct { Keys []string } +// NewBodyField creates a new field from an ordered array of keys. +func NewBodyField(keys ...string) Field { + if keys == nil { + keys = []string{} + } + return Field{BodyField{ + Keys: keys, + }} +} + // Parent returns the parent of the current field. // In the case that the body field points to the root node, it is a no-op. func (f BodyField) Parent() BodyField { @@ -181,7 +191,11 @@ func (f *BodyField) UnmarshalJSON(raw []byte) error { return fmt.Errorf("the field is not a string: %s", err) } - *f = fromJSONDot(value) + field, err := fromJSONDot(value) + if err != nil { + return err + } + *f = *field return nil } @@ -198,7 +212,11 @@ func (f *BodyField) UnmarshalYAML(unmarshal func(interface{}) error) error { return fmt.Errorf("the field is not a string: %s", err) } - *f = fromJSONDot(value) + field, err := fromJSONDot(value) + if err != nil { + return err + } + *f = *field return nil } @@ -208,14 +226,21 @@ func (f BodyField) MarshalYAML() (interface{}, error) { } // fromJSONDot creates a field from JSON dot notation. -func fromJSONDot(value string) BodyField { - keys := strings.Split(value, ".") +func fromJSONDot(value string) (*BodyField, error) { + keys, err := splitField(value) + if err != nil { + return nil, err + } - if keys[0] == "$" || keys[0] == BodyPrefix { - keys = keys[1:] + if keys[0] == "$body" || keys[0] == "$" { + keys[0] = BodyPrefix } - return BodyField{keys} + if keys[0] != BodyPrefix { + return nil, fmt.Errorf("must start with 'body': %s", value) + } + + return &BodyField{keys[1:]}, nil } // toJSONDot returns the JSON dot notation for a field. @@ -232,14 +257,15 @@ func toJSONDot(field BodyField) string { } var b strings.Builder + b.WriteString(BodyPrefix) if containsDots { - b.WriteString(BodyPrefix) for _, key := range field.Keys { b.WriteString(`['`) b.WriteString(key) b.WriteString(`']`) } } else { + b.WriteString(".") for i, key := range field.Keys { if i != 0 { b.WriteString(".") @@ -250,13 +276,3 @@ func toJSONDot(field BodyField) string { return b.String() } - -// NewBodyField creates a new field from an ordered array of keys. -func NewBodyField(keys ...string) Field { - if keys == nil { - keys = []string{} - } - return Field{BodyField{ - Keys: keys, - }} -} diff --git a/entry/body_field_test.go b/entry/body_field_test.go index a4ee28c9..c0e9d0de 100644 --- a/entry/body_field_test.go +++ b/entry/body_field_test.go @@ -16,6 +16,7 @@ package entry import ( "encoding/json" + "fmt" "testing" "github.com/stretchr/testify/assert" @@ -313,55 +314,143 @@ func TestBodyFieldMerge(t *testing.T) { require.Equal(t, expected, entry.Body) } -func TestBodyFieldMarshalJSON(t *testing.T) { - bodyField := BodyField{Keys: []string{"test"}} - json, err := bodyField.MarshalJSON() - require.NoError(t, err) - require.Equal(t, []byte(`"test"`), json) -} +// TODO add more test cases +// 1. fields with dots `body["file.name"]` +// 2. fields with deprecated "$body" or "$." prefix +func TestBodyFieldMarshal(t *testing.T) { + cases := []struct { + name string + keys []string + jsonDot string + }{ + { + "standard", + []string{"test"}, + "body.test", + }, + { + "bracketed", + []string{"test.foo"}, + "body['test.foo']", + }, + { + "double_bracketed", + []string{"test.foo", "bar"}, + "body['test.foo']['bar']", + }, + } -func TestBodyFieldUnmarshalJSON(t *testing.T) { - fieldString := []byte(`"test"`) - var f BodyField - err := json.Unmarshal(fieldString, &f) - require.NoError(t, err) - require.Equal(t, BodyField{Keys: []string{"test"}}, f) -} + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + field := BodyField{Keys: tc.keys} + yaml, err := field.MarshalYAML() + require.NoError(t, err) + require.Equal(t, tc.jsonDot, yaml) -func TestBodyFieldUnmarshalJSONFailure(t *testing.T) { - invalidField := []byte(`{"key":"value"}`) - var f BodyField - err := json.Unmarshal(invalidField, &f) - require.Error(t, err) - require.Contains(t, err.Error(), "the field is not a string: json") + json, err := field.MarshalJSON() + require.NoError(t, err) + require.Equal(t, []byte(fmt.Sprintf(`"%s"`, tc.jsonDot)), json) + }) + } } -func TestBodyFieldMarshalYAML(t *testing.T) { - bodyField := BodyField{Keys: []string{"test"}} - yaml, err := bodyField.MarshalYAML() - require.NoError(t, err) - require.Equal(t, "test", yaml) -} +func TestBodyFieldUnmarshal(t *testing.T) { + cases := []struct { + name string + jsonDot string + keys []string + }{ + { + "standard", + "body.test", + []string{"test"}, + }, + { + "bracketed", + "body['test.foo']", + []string{"test.foo"}, + }, + { + "double_bracketed", + "body['test.foo']['bar']", + []string{"test.foo", "bar"}, + }, + { + "mixed", + "body['test.foo'].bar", + []string{"test.foo", "bar"}, + }, + { + "deprecated_prefix", + "$body.test", + []string{"test"}, + }, + { + "deprecated_prefix_bracketed", + "$body['test.foo']", + []string{"test.foo"}, + }, + { + "deprecated_shorthand", + "$.test", + []string{"test"}, + }, + { + "deprecated_shorthand_bracketed", + "$['test.foo']", + []string{"test.foo"}, + }, + } -func TestBodyFieldUnmarshalYAML(t *testing.T) { - invalidField := []byte("test") - var f BodyField - err := yaml.UnmarshalStrict(invalidField, &f) - require.NoError(t, err) - require.Equal(t, BodyField{Keys: []string{"test"}}, f) -} + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + var fy BodyField + err := yaml.UnmarshalStrict([]byte(tc.jsonDot), &fy) + require.NoError(t, err) + require.Equal(t, tc.keys, fy.Keys) -func TestBodyFieldUnmarshalYAMLFailure(t *testing.T) { - invalidField := []byte(`{"key":"value"}`) - var f BodyField - err := yaml.UnmarshalStrict(invalidField, &f) - require.Error(t, err) - require.Contains(t, err.Error(), "the field is not a string: yaml") + var fj BodyField + err = json.Unmarshal([]byte(fmt.Sprintf(`"%s"`, tc.jsonDot)), &fj) + require.NoError(t, err) + require.Equal(t, tc.keys, fy.Keys) + }) + } } -func TestBodyFieldFromJSONDot(t *testing.T) { - jsonDot := "$.test" - bodyField := fromJSONDot(jsonDot) - expectedField := BodyField{Keys: []string{"test"}} - require.Equal(t, expectedField, bodyField) +func TestBodyFieldUnmarshalFailure(t *testing.T) { + cases := []struct { + name string + invalid []byte + expectedErr string + }{ + { + "must_be_string", + []byte(`{"key":"value"}`), + "the field is not a string", + }, + { + "must_start_with_prefix", + []byte(`"test"`), + "must start with 'body'", + }, + { + "invalid_syntax", + []byte(`"test['foo'"`), + "found unclosed left bracket", + }, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + var fy BodyField + err := yaml.UnmarshalStrict(tc.invalid, &fy) + require.Error(t, err) + require.Contains(t, err.Error(), tc.expectedErr) + + var fj BodyField + err = json.Unmarshal(tc.invalid, &fj) + require.Error(t, err) + require.Contains(t, err.Error(), tc.expectedErr) + }) + } } diff --git a/entry/entry_test.go b/entry/entry_test.go index cd63d2c1..eca7acf2 100644 --- a/entry/entry_test.go +++ b/entry/entry_test.go @@ -200,32 +200,44 @@ func TestFieldFromString(t *testing.T) { expectedError bool }{ { - "SimpleBody", - "test", - Field{BodyField{[]string{"test"}}}, + "Body", + "body", + Field{BodyField{[]string{}}}, false, }, { "PrefixedBody", - "$.test", + "body.test", Field{BodyField{[]string{"test"}}}, false, }, { "FullPrefixedBody", - "$body.test", + "body.test", Field{BodyField{[]string{"test"}}}, false, }, { "SimpleAttribute", - "$attributes.test", + "attributes.test", Field{AttributeField{"test"}}, false, }, { "AttributesTooManyFields", - "$attributes.test.bar", + "attributes.test.bar", + Field{}, + true, + }, + { + "SimpleResource", + "resource.test", + Field{ResourceField{"test"}}, + false, + }, + { + "ResourceTooManyFields", + "resource.test.bar", Field{}, true, }, diff --git a/entry/field.go b/entry/field.go index 6733ebb6..2fb6fbf3 100644 --- a/entry/field.go +++ b/entry/field.go @@ -20,9 +20,9 @@ import ( ) const ( - AttributesPrefix = "$attributes" - ResourcePrefix = "$resource" - BodyPrefix = "$body" + AttributesPrefix = "attributes" + ResourcePrefix = "resource" + BodyPrefix = "body" ) // Field represents a potential field on an entry. @@ -79,10 +79,10 @@ func NewField(s string) (Field, error) { return Field{}, fmt.Errorf("resource fields cannot be nested") } return Field{ResourceField{split[1]}}, nil - case BodyPrefix, "$": - return Field{BodyField{split[1:]}}, nil + case BodyPrefix: + return NewBodyField(split[1:]...), nil default: - return Field{BodyField{split}}, nil + return Field{}, fmt.Errorf("unrecognized prefix") } } diff --git a/entry/field_test.go b/entry/field_test.go index 1c952ae7..b42a200b 100644 --- a/entry/field_test.go +++ b/entry/field_test.go @@ -30,22 +30,17 @@ func TestFieldUnmarshalJSON(t *testing.T) { }{ { "SimpleField", - []byte(`"test1"`), + []byte(`"body.test1"`), NewBodyField("test1"), }, { "ComplexField", - []byte(`"test1.test2"`), + []byte(`"body.test1.test2"`), NewBodyField("test1", "test2"), }, - { - "BodyShort", - []byte(`"$"`), - NewBodyField(), - }, { "BodyLong", - []byte(`"$body"`), + []byte(`"body"`), NewBodyField(), }, } @@ -78,17 +73,17 @@ func TestFieldMarshalJSON(t *testing.T) { { "SimpleField", NewBodyField("test1"), - []byte(`"test1"`), + []byte(`"body.test1"`), }, { "ComplexField", NewBodyField("test1", "test2"), - []byte(`"test1.test2"`), + []byte(`"body.test1.test2"`), }, { "BodyLong", NewBodyField(), - []byte(`"$body"`), + []byte(`"body"`), }, } @@ -108,36 +103,26 @@ func TestFieldUnmarshalYAML(t *testing.T) { input []byte expected Field }{ + { + "Root", + []byte(`"body"`), + NewBodyField(), + }, { "SimpleField", - []byte(`"test1"`), + []byte(`"body.test1"`), NewBodyField("test1"), }, { "UnquotedField", - []byte(`test1`), + []byte(`body.test1`), NewBodyField("test1"), }, { "ComplexField", - []byte(`"test1.test2"`), + []byte(`"body.test1.test2"`), NewBodyField("test1", "test2"), }, - { - "ComplexFieldWithRoot", - []byte(`"$.test1.test2"`), - NewBodyField("test1", "test2"), - }, - { - "BodyShort", - []byte(`"$"`), - NewBodyField(), - }, - { - "BodyLong", - []byte(`"$body"`), - NewBodyField(), - }, } for _, tc := range cases { @@ -165,55 +150,55 @@ func TestFieldMarshalYAML(t *testing.T) { input interface{} expected string }{ + { + "Body", + NewBodyField(), + "body\n", + }, { "SimpleField", NewBodyField("test1"), - "test1\n", + "body.test1\n", }, { "ComplexField", NewBodyField("test1", "test2"), - "test1.test2\n", - }, - { - "Body", - NewBodyField(), - "$body\n", + "body.test1.test2\n", }, { "FieldWithDots", NewBodyField("test.1"), - "$body['test.1']\n", + "body['test.1']\n", }, { "FieldWithDotsThenNone", NewBodyField("test.1", "test2"), - "$body['test.1']['test2']\n", + "body['test.1']['test2']\n", }, { "FieldWithNoDotsThenDots", NewBodyField("test1", "test.2"), - "$body['test1']['test.2']\n", + "body['test1']['test.2']\n", }, { "AttributeField", NewAttributeField("test1"), - "$attributes.test1\n", + "attributes.test1\n", }, { "AttributeFieldWithDots", NewAttributeField("test.1"), - "$attributes['test.1']\n", + "attributes['test.1']\n", }, { "ResourceField", NewResourceField("test1"), - "$resource.test1\n", + "resource.test1\n", }, { "ResourceFieldWithDots", NewResourceField("test.1"), - "$resource['test.1']\n", + "resource['test.1']\n", }, } @@ -236,25 +221,24 @@ func TestSplitField(t *testing.T) { }{ {"Simple", "test", []string{"test"}, false}, {"Sub", "test.case", []string{"test", "case"}, false}, - {"Root", "$", []string{"$"}, false}, - {"RootWithSub", "$body.field", []string{"$body", "field"}, false}, - {"RootWithTwoSub", "$body.field1.field2", []string{"$body", "field1", "field2"}, false}, + {"RootWithSub", "body.field", []string{"body", "field"}, false}, + {"RootWithTwoSub", "body.field1.field2", []string{"body", "field1", "field2"}, false}, {"BracketSyntaxSingleQuote", "['test']", []string{"test"}, false}, {"BracketSyntaxDoubleQuote", `["test"]`, []string{"test"}, false}, - {"RootSubBracketSyntax", `$body["test"]`, []string{"$body", "test"}, false}, - {"BracketThenDot", `$body["test1"].test2`, []string{"$body", "test1", "test2"}, false}, - {"BracketThenBracket", `$body["test1"]["test2"]`, []string{"$body", "test1", "test2"}, false}, - {"DotThenBracket", `$body.test1["test2"]`, []string{"$body", "test1", "test2"}, false}, - {"DotsInBrackets", `$body["test1.test2"]`, []string{"$body", "test1.test2"}, false}, - {"UnclosedBrackets", `$body["test1.test2"`, nil, true}, - {"UnclosedQuotes", `$body["test1.test2]`, nil, true}, - {"UnmatchedQuotes", `$body["test1.test2']`, nil, true}, - {"BracketAtEnd", `$body[`, nil, true}, - {"SingleQuoteAtEnd", `$body['`, nil, true}, - {"DoubleQuoteAtEnd", `$body["`, nil, true}, - {"BracketMissingQuotes", `$body[test]`, nil, true}, - {"CharacterBetweenBracketAndQuote", `$body["test"a]`, nil, true}, - {"CharacterOutsideBracket", `$body["test"]a`, nil, true}, + {"RootSubBracketSyntax", `body["test"]`, []string{"body", "test"}, false}, + {"BracketThenDot", `body["test1"].test2`, []string{"body", "test1", "test2"}, false}, + {"BracketThenBracket", `body["test1"]["test2"]`, []string{"body", "test1", "test2"}, false}, + {"DotThenBracket", `body.test1["test2"]`, []string{"body", "test1", "test2"}, false}, + {"DotsInBrackets", `body["test1.test2"]`, []string{"body", "test1.test2"}, false}, + {"UnclosedBrackets", `body["test1.test2"`, nil, true}, + {"UnclosedQuotes", `body["test1.test2]`, nil, true}, + {"UnmatchedQuotes", `body["test1.test2']`, nil, true}, + {"BracketAtEnd", `body[`, nil, true}, + {"SingleQuoteAtEnd", `body['`, nil, true}, + {"DoubleQuoteAtEnd", `body["`, nil, true}, + {"BracketMissingQuotes", `body[test]`, nil, true}, + {"CharacterBetweenBracketAndQuote", `body["test"a]`, nil, true}, + {"CharacterOutsideBracket", `body["test"]a`, nil, true}, } for _, tc := range cases { @@ -272,19 +256,19 @@ func TestSplitField(t *testing.T) { } func TestFieldFromStringInvalidSplit(t *testing.T) { - _, err := NewField("$resource[test]") + _, err := NewField("resource[test]") require.Error(t, err) require.Contains(t, err.Error(), "splitting field") } func TestFieldFromStringWithResource(t *testing.T) { - field, err := NewField(`$resource["test"]`) + field, err := NewField(`resource["test"]`) require.NoError(t, err) - require.Equal(t, "$resource.test", field.String()) + require.Equal(t, "resource.test", field.String()) } func TestFieldFromStringWithInvalidResource(t *testing.T) { - _, err := NewField(`$resource["test"]["key"]`) + _, err := NewField(`resource["test"]["key"]`) require.Error(t, err) require.Contains(t, err.Error(), "resource fields cannot be nested") } diff --git a/entry/resource_field.go b/entry/resource_field.go index d716ad82..a3b19779 100644 --- a/entry/resource_field.go +++ b/entry/resource_field.go @@ -60,9 +60,9 @@ func (r ResourceField) Delete(entry *Entry) (interface{}, bool) { func (r ResourceField) String() string { if strings.Contains(r.key, ".") { - return fmt.Sprintf(`$resource['%s']`, r.key) + return fmt.Sprintf(`resource['%s']`, r.key) } - return "$resource." + r.key + return "resource." + r.key } // NewResourceField will creat a new resource field from a key diff --git a/entry/resource_field_test.go b/entry/resource_field_test.go index adc02e0d..47d1bb32 100644 --- a/entry/resource_field_test.go +++ b/entry/resource_field_test.go @@ -195,12 +195,12 @@ func TestResourceFieldString(t *testing.T) { { "Simple", ResourceField{"foo"}, - "$resource.foo", + "resource.foo", }, { "Empty", ResourceField{""}, - "$resource.", + "resource.", }, } diff --git a/operator/helper/expr_string.go b/operator/helper/expr_string.go index 81f0c285..62c09e11 100644 --- a/operator/helper/expr_string.go +++ b/operator/helper/expr_string.go @@ -142,10 +142,10 @@ var envPool = sync.Pool{ func GetExprEnv(e *entry.Entry) map[string]interface{} { env := envPool.Get().(map[string]interface{}) env["$"] = e.Body - env["$body"] = e.Body - env["$attributes"] = e.Attributes - env["$resource"] = e.Resource - env["$timestamp"] = e.Timestamp + env["body"] = e.Body + env["attributes"] = e.Attributes + env["resource"] = e.Resource + env["timestamp"] = e.Timestamp return env } diff --git a/operator/helper/expr_string_test.go b/operator/helper/expr_string_test.go index f8213eba..b71a1a32 100644 --- a/operator/helper/expr_string_test.go +++ b/operator/helper/expr_string_test.go @@ -80,15 +80,15 @@ func TestExprString(t *testing.T) { ")EXPR(", }, { - "my EXPR( $.test )", + "my EXPR( body.test )", "my value", }, { - "my EXPR($.test )", + "my EXPR(body.test )", "my value", }, { - "my EXPR($.test)", + "my EXPR(body.test)", "my value", }, { @@ -96,7 +96,7 @@ func TestExprString(t *testing.T) { "my foo", }, { - "EXPR( $resource.id )", + "EXPR( resource.id )", "value", }, } diff --git a/operator/helper/parser_test.go b/operator/helper/parser_test.go index 82407f32..ab69265c 100644 --- a/operator/helper/parser_test.go +++ b/operator/helper/parser_test.go @@ -441,8 +441,8 @@ func TestMapStructureDecodeParserConfigWithHook(t *testing.T) { "id": "parser_config", "type": "test_type", "on_error": "send", - "parse_from": "$body.from", - "parse_to": "$body.to", + "parse_from": "body.from", + "parse_to": "body.to", "timestamp": map[string]interface{}{ "layout_type": "strptime", }, diff --git a/operator/helper/testdata/severity/parse_from_simple.yaml b/operator/helper/testdata/severity/parse_from_simple.yaml index 04947d32..d64bc1a2 100644 --- a/operator/helper/testdata/severity/parse_from_simple.yaml +++ b/operator/helper/testdata/severity/parse_from_simple.yaml @@ -1,2 +1,2 @@ type: severity_parser -parse_from: $.from +parse_from: body.from diff --git a/operator/helper/testdata/severity/preserve_to.yaml b/operator/helper/testdata/severity/preserve_to.yaml index 1298cfc9..ec60c230 100644 --- a/operator/helper/testdata/severity/preserve_to.yaml +++ b/operator/helper/testdata/severity/preserve_to.yaml @@ -1,2 +1,2 @@ type: severity_parser -preserve_to: aField +preserve_to: body.aField diff --git a/operator/helper/testdata/severity/severity.yaml b/operator/helper/testdata/severity/severity.yaml index 67687184..247f4f46 100644 --- a/operator/helper/testdata/severity/severity.yaml +++ b/operator/helper/testdata/severity/severity.yaml @@ -1,3 +1,2 @@ -type: severity_parser severity: - parse_from: severity_field + parse_from: body.severity_field diff --git a/operator/helper/testdata/time/parse_from.yaml b/operator/helper/testdata/time/parse_from.yaml index 8ea85493..17ade619 100644 --- a/operator/helper/testdata/time/parse_from.yaml +++ b/operator/helper/testdata/time/parse_from.yaml @@ -1 +1 @@ -parse_from: $.from +parse_from: body.from diff --git a/operator/helper/testdata/time/preserve_to.yaml b/operator/helper/testdata/time/preserve_to.yaml index 29d92c86..ef8f3799 100644 --- a/operator/helper/testdata/time/preserve_to.yaml +++ b/operator/helper/testdata/time/preserve_to.yaml @@ -1 +1 @@ -preserve_to: aField +preserve_to: body.aField diff --git a/operator/helper/transformer_test.go b/operator/helper/transformer_test.go index 0454c287..8095cf7c 100644 --- a/operator/helper/transformer_test.go +++ b/operator/helper/transformer_test.go @@ -179,19 +179,19 @@ func TestTransformerIf(t *testing.T) { }, { name: "EvaluatedTrue", - ifExpr: "$body == 'test'", + ifExpr: "body == 'test'", inputBody: "test", expected: "parsed", }, { name: "EvaluatedFalse", - ifExpr: "$body == 'notest'", + ifExpr: "body == 'notest'", inputBody: "test", expected: "test", }, { name: "FailingExpressionEvaluation", - ifExpr: "$body.test.noexist == 'notest'", + ifExpr: "body.test.noexist == 'notest'", inputBody: "test", expected: "test", errExpected: true, diff --git a/operator/parser/csv/testdata/basic.yaml b/operator/parser/csv/testdata/basic.yaml index b777b175..cf2a822b 100644 --- a/operator/parser/csv/testdata/basic.yaml +++ b/operator/parser/csv/testdata/basic.yaml @@ -1,3 +1,3 @@ type: csv_parser -parse_from: message +parse_from: body.message header: id,severity,message diff --git a/operator/parser/csv/testdata/delimiter.yaml b/operator/parser/csv/testdata/delimiter.yaml index 1a5bfc01..a412c7e6 100644 --- a/operator/parser/csv/testdata/delimiter.yaml +++ b/operator/parser/csv/testdata/delimiter.yaml @@ -1,4 +1,4 @@ type: csv_parser -parse_from: message +parse_from: body.message header: id,severity,message delimiter: "\t" diff --git a/operator/parser/csv/testdata/header_attribute.yaml b/operator/parser/csv/testdata/header_attribute.yaml index ed85f303..2fce6bea 100644 --- a/operator/parser/csv/testdata/header_attribute.yaml +++ b/operator/parser/csv/testdata/header_attribute.yaml @@ -1,4 +1,4 @@ type: csv_parser -parse_from: message +parse_from: body.message header_attribute: header_field delimiter: "\t" diff --git a/operator/parser/csv/testdata/lazy_quotes.yaml b/operator/parser/csv/testdata/lazy_quotes.yaml index 9af79c16..1df02860 100644 --- a/operator/parser/csv/testdata/lazy_quotes.yaml +++ b/operator/parser/csv/testdata/lazy_quotes.yaml @@ -1,4 +1,4 @@ type: csv_parser -parse_from: message +parse_from: body.message header: id,severity,message lazy_quotes: true diff --git a/operator/parser/csv/testdata/timestamp.yaml b/operator/parser/csv/testdata/timestamp.yaml index 143928ab..5b3af107 100644 --- a/operator/parser/csv/testdata/timestamp.yaml +++ b/operator/parser/csv/testdata/timestamp.yaml @@ -1,6 +1,6 @@ type: csv_parser header: timestamp_field,severity,message timestamp: - parse_from: timestamp_field + parse_from: body.timestamp_field layout_type: strptime layout: '%Y-%m-%d' diff --git a/operator/parser/json/json_test.go b/operator/parser/json/json_test.go index 066b5ec2..950e35d6 100644 --- a/operator/parser/json/json_test.go +++ b/operator/parser/json/json_test.go @@ -238,8 +238,8 @@ func TestJsonParserConfig(t *testing.T) { input := map[string]interface{}{ "id": "test", "type": "json_parser", - "parse_from": "$.from", - "parse_to": "$.to", + "parse_from": "body.from", + "parse_to": "body.to", "on_error": "send", } var actual JSONParserConfig @@ -252,8 +252,8 @@ func TestJsonParserConfig(t *testing.T) { input := `type: json_parser id: test on_error: "send" -parse_from: $.from -parse_to: $.to` +parse_from: body.from +parse_to: body.to` var actual JSONParserConfig err := yaml.Unmarshal([]byte(input), &actual) require.NoError(t, err) diff --git a/operator/parser/json/testdata/parse_from_simple.yaml b/operator/parser/json/testdata/parse_from_simple.yaml index 9f3e8dd1..e2abfae5 100644 --- a/operator/parser/json/testdata/parse_from_simple.yaml +++ b/operator/parser/json/testdata/parse_from_simple.yaml @@ -1,2 +1,2 @@ type: json_parser -parse_from: $.from +parse_from: body.from diff --git a/operator/parser/json/testdata/parse_to_simple.yaml b/operator/parser/json/testdata/parse_to_simple.yaml index 29fa74a0..3a6120e4 100644 --- a/operator/parser/json/testdata/parse_to_simple.yaml +++ b/operator/parser/json/testdata/parse_to_simple.yaml @@ -1,2 +1,2 @@ type: json_parser -parse_to: log +parse_to: body.log diff --git a/operator/parser/json/testdata/preserve_to.yaml b/operator/parser/json/testdata/preserve_to.yaml index 78de3bc0..4f5d0168 100644 --- a/operator/parser/json/testdata/preserve_to.yaml +++ b/operator/parser/json/testdata/preserve_to.yaml @@ -1,2 +1,2 @@ type: json_parser -preserve_to: aField +preserve_to: body.aField diff --git a/operator/parser/json/testdata/severity.yaml b/operator/parser/json/testdata/severity.yaml index 3358961a..c6e1cdb5 100644 --- a/operator/parser/json/testdata/severity.yaml +++ b/operator/parser/json/testdata/severity.yaml @@ -1,6 +1,6 @@ type: json_parser severity: - parse_from: severity_field + parse_from: body.severity_field mapping: critical: 5xx error: 4xx diff --git a/operator/parser/json/testdata/timestamp.yaml b/operator/parser/json/testdata/timestamp.yaml index 55ad1bff..8a3b0d15 100644 --- a/operator/parser/json/testdata/timestamp.yaml +++ b/operator/parser/json/testdata/timestamp.yaml @@ -1,5 +1,5 @@ type: json_parser timestamp: - parse_from: timestamp_field + parse_from: body.timestamp_field layout_type: strptime layout: '%Y-%m-%d' diff --git a/operator/parser/regex/regex_test.go b/operator/parser/regex/regex_test.go index 435a0a57..a8524533 100644 --- a/operator/parser/regex/regex_test.go +++ b/operator/parser/regex/regex_test.go @@ -161,8 +161,8 @@ func TestRegexParserConfig(t *testing.T) { "id": "test", "type": "regex_parser", "regex": "test123", - "parse_from": "$.from", - "parse_to": "$.to", + "parse_from": "body.from", + "parse_to": "body.to", "on_error": "send", } var actual RegexParserConfig @@ -177,8 +177,8 @@ type: regex_parser id: test on_error: "send" regex: "test123" -parse_from: $.from -parse_to: $.to` +parse_from: body.from +parse_to: body.to` var actual RegexParserConfig err := yaml.Unmarshal([]byte(input), &actual) require.NoError(t, err) diff --git a/operator/parser/regex/testdata/parse_from_simple.yaml b/operator/parser/regex/testdata/parse_from_simple.yaml index 103efaaa..55b77c6d 100644 --- a/operator/parser/regex/testdata/parse_from_simple.yaml +++ b/operator/parser/regex/testdata/parse_from_simple.yaml @@ -1,2 +1,2 @@ type: regex_parser -parse_from: "$.from" +parse_from: "body.from" diff --git a/operator/parser/regex/testdata/parse_to_simple.yaml b/operator/parser/regex/testdata/parse_to_simple.yaml index e7c3b7ae..55aef6ae 100644 --- a/operator/parser/regex/testdata/parse_to_simple.yaml +++ b/operator/parser/regex/testdata/parse_to_simple.yaml @@ -1,2 +1,2 @@ type: regex_parser -parse_to: "log" +parse_to: "body.log" diff --git a/operator/parser/regex/testdata/preserve_to.yaml b/operator/parser/regex/testdata/preserve_to.yaml index ce5588ff..0528f3c4 100644 --- a/operator/parser/regex/testdata/preserve_to.yaml +++ b/operator/parser/regex/testdata/preserve_to.yaml @@ -1,2 +1,2 @@ type: regex_parser -preserve_to: "aField" +preserve_to: "body.aField" diff --git a/operator/parser/regex/testdata/severity.yaml b/operator/parser/regex/testdata/severity.yaml index 4acaac48..de7a74fe 100644 --- a/operator/parser/regex/testdata/severity.yaml +++ b/operator/parser/regex/testdata/severity.yaml @@ -1,6 +1,6 @@ type: regex_parser severity: - parse_from: severity_field + parse_from: body.severity_field mapping: critical: 5xx error: 4xx diff --git a/operator/parser/regex/testdata/timestamp.yaml b/operator/parser/regex/testdata/timestamp.yaml index e7ed52de..8920f07b 100644 --- a/operator/parser/regex/testdata/timestamp.yaml +++ b/operator/parser/regex/testdata/timestamp.yaml @@ -1,5 +1,5 @@ type: regex_parser timestamp: - parse_from: timestamp_field + parse_from: body.timestamp_field layout_type: strptime layout: '%Y-%m-%d' diff --git a/operator/parser/severity/severity_test.go b/operator/parser/severity/severity_test.go index ce1e0c71..9954ae46 100644 --- a/operator/parser/severity/severity_test.go +++ b/operator/parser/severity/severity_test.go @@ -288,7 +288,7 @@ func TestSeverityParserConfig(t *testing.T) { input := map[string]interface{}{ "id": "test", "type": "severity_parser", - "parse_from": "$.from", + "parse_from": "body.from", "on_error": "send", "preset": "test", } @@ -303,7 +303,7 @@ func TestSeverityParserConfig(t *testing.T) { type: severity_parser id: test on_error: "send" -parse_from: $.from +parse_from: body.from preset: test ` var actual SeverityParserConfig diff --git a/operator/parser/syslog/syslog_test.go b/operator/parser/syslog/syslog_test.go index 1e1149e8..db81f9c3 100644 --- a/operator/parser/syslog/syslog_test.go +++ b/operator/parser/syslog/syslog_test.go @@ -76,8 +76,8 @@ func TestSyslogParserConfig(t *testing.T) { "id": "test", "type": "syslog_parser", "protocol": RFC3164, - "parse_from": "$.from", - "parse_to": "$.to", + "parse_from": "body.from", + "parse_to": "body.to", "on_error": "send", } var actual SyslogParserConfig @@ -92,8 +92,8 @@ type: syslog_parser id: test on_error: "send" protocol: rfc3164 -parse_from: $.from -parse_to: $.to` +parse_from: body.from +parse_to: body.to` var actual SyslogParserConfig err := yaml.Unmarshal([]byte(input), &actual) require.NoError(t, err) diff --git a/operator/parser/time/time_test.go b/operator/parser/time/time_test.go index 0df9e3ff..0f9336d8 100644 --- a/operator/parser/time/time_test.go +++ b/operator/parser/time/time_test.go @@ -58,7 +58,7 @@ func TestBuild(t *testing.T) { "basic", func() (*TimeParserConfig, error) { cfg := NewTimeParserConfig("test_id") - parseFrom, err := entry.NewField("app_time") + parseFrom, err := entry.NewField("body.app_time") if err != nil { return cfg, err } @@ -97,7 +97,7 @@ func TestProcess(t *testing.T) { "promote", func() (*TimeParserConfig, error) { cfg := NewTimeParserConfig("test_id") - parseFrom, err := entry.NewField("app_time") + parseFrom, err := entry.NewField("body.app_time") if err != nil { return nil, err } @@ -122,7 +122,7 @@ func TestProcess(t *testing.T) { "promote-and-preserve", func() (*TimeParserConfig, error) { cfg := NewTimeParserConfig("test_id") - parseFrom, err := entry.NewField("app_time") + parseFrom, err := entry.NewField("body.app_time") if err != nil { return nil, err } @@ -584,7 +584,7 @@ func TestTimeParserConfig(t *testing.T) { "on_error": "send", "layout": "Mon Jan 2 15:04:05 MST 2006", "layout_type": "gotime", - "parse_from": "$.from", + "parse_from": "body.from", } var actual TimeParserConfig err := helper.UnmarshalMapstructure(input, &actual) @@ -597,7 +597,7 @@ func TestTimeParserConfig(t *testing.T) { type: time_parser id: test_operator_id on_error: "send" -parse_from: $.from +parse_from: body.from layout_type: gotime layout: "Mon Jan 2 15:04:05 MST 2006" output: diff --git a/operator/parser/trace/testdata/spanid.yaml b/operator/parser/trace/testdata/spanid.yaml index c1e6d7fb..f653991b 100644 --- a/operator/parser/trace/testdata/spanid.yaml +++ b/operator/parser/trace/testdata/spanid.yaml @@ -1,4 +1,4 @@ type: trace_parser span_id: - parse_from: "app_span_id" - preserve_to: "orig_span_id" + parse_from: body.app_span_id + preserve_to: body.orig_span_id diff --git a/operator/parser/trace/testdata/trace_flags.yaml b/operator/parser/trace/testdata/trace_flags.yaml index 1945dd4f..448d2ef0 100644 --- a/operator/parser/trace/testdata/trace_flags.yaml +++ b/operator/parser/trace/testdata/trace_flags.yaml @@ -1,4 +1,4 @@ type: trace_parser trace_flags: - parse_from: "app_trace_flags_id" - preserve_to: "orig_race_flags_id" + parse_from: body.app_trace_flags_id + preserve_to: body.orig_race_flags_id diff --git a/operator/parser/trace/testdata/traceid.yaml b/operator/parser/trace/testdata/traceid.yaml index f90ceda6..e1a5fbe0 100644 --- a/operator/parser/trace/testdata/traceid.yaml +++ b/operator/parser/trace/testdata/traceid.yaml @@ -1,4 +1,4 @@ type: trace_parser trace_id: - parse_from: "app_trace_id" - preserve_to: "orig_trace_id" + parse_from: body.app_trace_id + preserve_to: body.orig_trace_id diff --git a/operator/parser/uri/testdata/parse_from_simple.yaml b/operator/parser/uri/testdata/parse_from_simple.yaml index 302dcdc6..b8700574 100644 --- a/operator/parser/uri/testdata/parse_from_simple.yaml +++ b/operator/parser/uri/testdata/parse_from_simple.yaml @@ -1,2 +1,2 @@ type: uri_parser -parse_from: "$.from" +parse_from: "body.from" diff --git a/operator/parser/uri/testdata/parse_to_simple.yaml b/operator/parser/uri/testdata/parse_to_simple.yaml index 73b72d64..9b51b7b1 100644 --- a/operator/parser/uri/testdata/parse_to_simple.yaml +++ b/operator/parser/uri/testdata/parse_to_simple.yaml @@ -1,2 +1,2 @@ type: uri_parser -parse_to: "log" +parse_to: "body.log" diff --git a/operator/parser/uri/testdata/preserve_to.yaml b/operator/parser/uri/testdata/preserve_to.yaml index b6898da7..8afe2be8 100644 --- a/operator/parser/uri/testdata/preserve_to.yaml +++ b/operator/parser/uri/testdata/preserve_to.yaml @@ -1,2 +1,2 @@ type: uri_parser -preserve_to: "aField" +preserve_to: "body.aField" diff --git a/operator/parser/uri/testdata/severity.yaml b/operator/parser/uri/testdata/severity.yaml index 3bee3212..f8893fba 100644 --- a/operator/parser/uri/testdata/severity.yaml +++ b/operator/parser/uri/testdata/severity.yaml @@ -1,6 +1,6 @@ type: uri_parser severity: - parse_from: severity_field + parse_from: body.severity_field mapping: critical: 5xx error: 4xx diff --git a/operator/parser/uri/testdata/timestamp.yaml b/operator/parser/uri/testdata/timestamp.yaml index 92626838..0476499f 100644 --- a/operator/parser/uri/testdata/timestamp.yaml +++ b/operator/parser/uri/testdata/timestamp.yaml @@ -1,5 +1,5 @@ type: uri_parser timestamp: - parse_from: timestamp_field + parse_from: body.timestamp_field layout_type: strptime layout: '%Y-%m-%d' diff --git a/operator/parser/uri/uri_test.go b/operator/parser/uri/uri_test.go index d70a5b4b..46095f80 100644 --- a/operator/parser/uri/uri_test.go +++ b/operator/parser/uri/uri_test.go @@ -740,8 +740,8 @@ func TestURIParserConfig(t *testing.T) { input := map[string]interface{}{ "id": "test", "type": "uri_parser", - "parse_from": "$.from", - "parse_to": "$.to", + "parse_from": "body.from", + "parse_to": "body.to", "on_error": "send", } var actual URIParserConfig @@ -755,8 +755,8 @@ func TestURIParserConfig(t *testing.T) { type: uri_parser id: test on_error: "send" -parse_from: $.from -parse_to: $.to` +parse_from: body.from +parse_to: body.to` var actual URIParserConfig err := yaml.Unmarshal([]byte(input), &actual) require.NoError(t, err) diff --git a/operator/transformer/add/add_test.go b/operator/transformer/add/add_test.go index f3701e34..c7249ff7 100644 --- a/operator/transformer/add/add_test.go +++ b/operator/transformer/add/add_test.go @@ -68,7 +68,7 @@ func TestProcessAndBuild(t *testing.T) { func() *AddOperatorConfig { cfg := defaultCfg() cfg.Field = entry.NewBodyField("new") - cfg.Value = `EXPR($.key + "_suffix")` + cfg.Value = `EXPR(body.key + "_suffix")` return cfg }(), newTestEntry, @@ -146,7 +146,7 @@ func TestProcessAndBuild(t *testing.T) { func() *AddOperatorConfig { cfg := defaultCfg() cfg.Field = entry.NewResourceField("new") - cfg.Value = `EXPR($.key + "_suffix")` + cfg.Value = `EXPR(body.key + "_suffix")` return cfg }(), newTestEntry, diff --git a/operator/transformer/add/config_test.go b/operator/transformer/add/config_test.go index 5a44e75b..344f277f 100644 --- a/operator/transformer/add/config_test.go +++ b/operator/transformer/add/config_test.go @@ -37,7 +37,7 @@ func TestGoldenConfig(t *testing.T) { Expect: func() *AddOperatorConfig { cfg := defaultCfg() cfg.Field = entry.NewBodyField("new") - cfg.Value = `EXPR($.key + "_suffix")` + cfg.Value = `EXPR(body.key + "_suffix")` return cfg }(), }, @@ -75,7 +75,7 @@ func TestGoldenConfig(t *testing.T) { Expect: func() *AddOperatorConfig { cfg := defaultCfg() cfg.Field = entry.NewResourceField("new") - cfg.Value = `EXPR($.key + "_suffix")` + cfg.Value = `EXPR(body.key + "_suffix")` return cfg }(), }, diff --git a/operator/transformer/add/testdata/add_array_to_body.yaml b/operator/transformer/add/testdata/add_array_to_body.yaml index 33361abc..3c86aca6 100644 --- a/operator/transformer/add/testdata/add_array_to_body.yaml +++ b/operator/transformer/add/testdata/add_array_to_body.yaml @@ -1,3 +1,3 @@ type: add -field: $body.new +field: body.new value: [1,2,3,4] diff --git a/operator/transformer/add/testdata/add_attribute.yaml b/operator/transformer/add/testdata/add_attribute.yaml index c6e186df..06a15839 100644 --- a/operator/transformer/add/testdata/add_attribute.yaml +++ b/operator/transformer/add/testdata/add_attribute.yaml @@ -1,3 +1,3 @@ type: add -field: $attributes.new +field: attributes.new value: newVal diff --git a/operator/transformer/add/testdata/add_expr.yaml b/operator/transformer/add/testdata/add_expr.yaml index d00a1fb7..0c7a7558 100644 --- a/operator/transformer/add/testdata/add_expr.yaml +++ b/operator/transformer/add/testdata/add_expr.yaml @@ -1,3 +1,3 @@ type: add -field: $body.new -value: EXPR($.key + "_suffix") +field: body.new +value: EXPR(body.key + "_suffix") diff --git a/operator/transformer/add/testdata/add_nest.yaml b/operator/transformer/add/testdata/add_nest.yaml index ad8c6f21..7b2fa50b 100644 --- a/operator/transformer/add/testdata/add_nest.yaml +++ b/operator/transformer/add/testdata/add_nest.yaml @@ -1,5 +1,5 @@ type: add -field: $body.new +field: body.new value: nest: key: val diff --git a/operator/transformer/add/testdata/add_resource.yaml b/operator/transformer/add/testdata/add_resource.yaml index 57848ab1..c2f0298c 100644 --- a/operator/transformer/add/testdata/add_resource.yaml +++ b/operator/transformer/add/testdata/add_resource.yaml @@ -1,3 +1,3 @@ type: add -field: $resource.new +field: resource.new value: newVal diff --git a/operator/transformer/add/testdata/add_resource_expr.yaml b/operator/transformer/add/testdata/add_resource_expr.yaml index 2eabfe60..13801ca8 100644 --- a/operator/transformer/add/testdata/add_resource_expr.yaml +++ b/operator/transformer/add/testdata/add_resource_expr.yaml @@ -1,3 +1,3 @@ type: add -field: $resource.new -value: EXPR($.key + "_suffix") +field: resource.new +value: EXPR(body.key + "_suffix") diff --git a/operator/transformer/add/testdata/add_value.yaml b/operator/transformer/add/testdata/add_value.yaml index b4e06bdd..d245fbd8 100644 --- a/operator/transformer/add/testdata/add_value.yaml +++ b/operator/transformer/add/testdata/add_value.yaml @@ -1,3 +1,3 @@ type: add -field: $body.new +field: body.new value: randomMessage diff --git a/operator/transformer/copy/testdata/attribute_to_body.yaml b/operator/transformer/copy/testdata/attribute_to_body.yaml index fa72c350..cf95820d 100644 --- a/operator/transformer/copy/testdata/attribute_to_body.yaml +++ b/operator/transformer/copy/testdata/attribute_to_body.yaml @@ -1,3 +1,3 @@ type: copy -from: $attributes.key -to: $body.key2 +from: attributes.key +to: body.key2 diff --git a/operator/transformer/copy/testdata/attribute_to_resource.yaml b/operator/transformer/copy/testdata/attribute_to_resource.yaml index b0d68d22..4d590800 100644 --- a/operator/transformer/copy/testdata/attribute_to_resource.yaml +++ b/operator/transformer/copy/testdata/attribute_to_resource.yaml @@ -1,3 +1,3 @@ type: copy -from: $attributes.key -to: $resource.key2 +from: attributes.key +to: resource.key2 diff --git a/operator/transformer/copy/testdata/body_to_attribute.yaml b/operator/transformer/copy/testdata/body_to_attribute.yaml index e7b5a163..13386533 100644 --- a/operator/transformer/copy/testdata/body_to_attribute.yaml +++ b/operator/transformer/copy/testdata/body_to_attribute.yaml @@ -1,3 +1,3 @@ type: copy -from: $body.key -to: $attributes.key2 +from: body.key +to: attributes.key2 diff --git a/operator/transformer/copy/testdata/body_to_body.yaml b/operator/transformer/copy/testdata/body_to_body.yaml index 7c0d90a7..65e19931 100644 --- a/operator/transformer/copy/testdata/body_to_body.yaml +++ b/operator/transformer/copy/testdata/body_to_body.yaml @@ -1,3 +1,3 @@ type: copy -from: $body.key -to: $body.key2 +from: body.key +to: body.key2 diff --git a/operator/transformer/filter/filter_test.go b/operator/transformer/filter/filter_test.go index f90bc899..6af2c3aa 100644 --- a/operator/transformer/filter/filter_test.go +++ b/operator/transformer/filter/filter_test.go @@ -46,7 +46,7 @@ func TestFilterOperator(t *testing.T) { "message": "test_message", }, }, - `$.message == "test_message"`, + `body.message == "test_message"`, true, }, { @@ -56,7 +56,7 @@ func TestFilterOperator(t *testing.T) { "message": "invalid", }, }, - `$.message == "test_message"`, + `body.message == "test_message"`, false, }, { @@ -69,7 +69,7 @@ func TestFilterOperator(t *testing.T) { "key": "value", }, }, - `$attributes.key == "value"`, + `attributes.key == "value"`, true, }, { @@ -79,7 +79,7 @@ func TestFilterOperator(t *testing.T) { "message": "test_message", }, }, - `$attributes.key == "value"`, + `attributes.key == "value"`, false, }, { @@ -132,7 +132,7 @@ func TestFilterOperator(t *testing.T) { func TestFilterDropRatio(t *testing.T) { cfg := NewFilterOperatorConfig("test") - cfg.Expression = `$.message == "test_message"` + cfg.Expression = `body.message == "test_message"` cfg.DropRatio = 0.5 op, err := cfg.Build(testutil.Logger(t)) require.NoError(t, err) diff --git a/operator/transformer/flatten/config_test.go b/operator/transformer/flatten/config_test.go index 5d7e123b..386547cc 100644 --- a/operator/transformer/flatten/config_test.go +++ b/operator/transformer/flatten/config_test.go @@ -63,11 +63,11 @@ func TestGoldenConfig(t *testing.T) { func() *FlattenOperatorConfig { cfg := defaultCfg() cfg.Field = entry.BodyField{ - Keys: []string{"$attributes", "errField"}, + Keys: []string{"attributes", "errField"}, } return cfg }(), - false, + true, }, } for _, tc := range cases { diff --git a/operator/transformer/flatten/flaltten.go b/operator/transformer/flatten/flatten.go similarity index 96% rename from operator/transformer/flatten/flaltten.go rename to operator/transformer/flatten/flatten.go index 7294ae5e..528e4e4d 100644 --- a/operator/transformer/flatten/flaltten.go +++ b/operator/transformer/flatten/flatten.go @@ -51,7 +51,7 @@ func (c FlattenOperatorConfig) Build(logger *zap.SugaredLogger) (operator.Operat return nil, err } - if strings.Contains(c.Field.String(), "$attributes") || strings.Contains(c.Field.String(), "$resource") { + if strings.Contains(c.Field.String(), "attributes") || strings.Contains(c.Field.String(), "resource") { return nil, fmt.Errorf("flatten: field cannot be a resource or attribute") } diff --git a/operator/transformer/flatten/flatten_test.go b/operator/transformer/flatten/flatten_test.go index e74a8f5c..de847389 100644 --- a/operator/transformer/flatten/flatten_test.go +++ b/operator/transformer/flatten/flatten_test.go @@ -254,7 +254,7 @@ func TestBuildAndProcess(t *testing.T) { func() *FlattenOperatorConfig { cfg := defaultCfg() cfg.Field = entry.BodyField{ - Keys: []string{"$resource", "invalid"}, + Keys: []string{"resource", "invalid"}, } return cfg }(), diff --git a/operator/transformer/flatten/testdata/flatten_attributes.yaml b/operator/transformer/flatten/testdata/flatten_attributes.yaml index 5b70c02c..0bbcf7f5 100644 --- a/operator/transformer/flatten/testdata/flatten_attributes.yaml +++ b/operator/transformer/flatten/testdata/flatten_attributes.yaml @@ -1,2 +1,2 @@ type: flatten -field: $attributes.errField +field: attributes.errField diff --git a/operator/transformer/flatten/testdata/flatten_one_level.yaml b/operator/transformer/flatten/testdata/flatten_one_level.yaml index c2600f21..428b1ce3 100644 --- a/operator/transformer/flatten/testdata/flatten_one_level.yaml +++ b/operator/transformer/flatten/testdata/flatten_one_level.yaml @@ -1,2 +1,2 @@ type: flatten -field: nested +field: body.nested diff --git a/operator/transformer/flatten/testdata/flatten_second_level.yaml b/operator/transformer/flatten/testdata/flatten_second_level.yaml index 0902b0a4..40d54943 100644 --- a/operator/transformer/flatten/testdata/flatten_second_level.yaml +++ b/operator/transformer/flatten/testdata/flatten_second_level.yaml @@ -1,2 +1,2 @@ type: flatten -field: nested.secondlevel +field: body.nested.secondlevel diff --git a/operator/transformer/move/config_test.go b/operator/transformer/move/config_test.go index 678d09b2..51b5c394 100644 --- a/operator/transformer/move/config_test.go +++ b/operator/transformer/move/config_test.go @@ -132,33 +132,6 @@ func TestGoldenConfig(t *testing.T) { return cfg }(), }, - { - Name: "implicit_body_from", - Expect: func() *MoveOperatorConfig { - cfg := defaultCfg() - cfg.From = entry.NewBodyField("implicitkey") - cfg.To = entry.NewAttributeField("new") - return cfg - }(), - }, - { - Name: "implicit_body_to", - Expect: func() *MoveOperatorConfig { - cfg := defaultCfg() - cfg.From = entry.NewAttributeField("new") - cfg.To = entry.NewBodyField("implicitkey") - return cfg - }(), - }, - { - Name: "implicit_nested_key", - Expect: func() *MoveOperatorConfig { - cfg := defaultCfg() - cfg.From = entry.NewAttributeField("new") - cfg.To = entry.NewBodyField("key", "key2") - return cfg - }(), - }, { Name: "replace_body", Expect: func() *MoveOperatorConfig { diff --git a/operator/transformer/move/testdata/implicit_body_from.yaml b/operator/transformer/move/testdata/implicit_body_from.yaml deleted file mode 100644 index 3779136e..00000000 --- a/operator/transformer/move/testdata/implicit_body_from.yaml +++ /dev/null @@ -1,3 +0,0 @@ -type: move -from: implicitkey -to: $attributes.new diff --git a/operator/transformer/move/testdata/implicit_body_to.yaml b/operator/transformer/move/testdata/implicit_body_to.yaml deleted file mode 100644 index 2dd2c786..00000000 --- a/operator/transformer/move/testdata/implicit_body_to.yaml +++ /dev/null @@ -1,3 +0,0 @@ -type: move -from: $attributes.new -to: implicitkey diff --git a/operator/transformer/move/testdata/implicit_nested_key.yaml b/operator/transformer/move/testdata/implicit_nested_key.yaml deleted file mode 100644 index 44200b05..00000000 --- a/operator/transformer/move/testdata/implicit_nested_key.yaml +++ /dev/null @@ -1,3 +0,0 @@ -type: move -from: $attributes.new -to: key.key2 diff --git a/operator/transformer/move/testdata/move_attribute_to_body.yaml b/operator/transformer/move/testdata/move_attribute_to_body.yaml index dafcdf20..c9ad6c5e 100644 --- a/operator/transformer/move/testdata/move_attribute_to_body.yaml +++ b/operator/transformer/move/testdata/move_attribute_to_body.yaml @@ -1,3 +1,3 @@ type: move -from: $attributes.new -to: $body.new +from: attributes.new +to: body.new diff --git a/operator/transformer/move/testdata/move_attribute_to_resource.yaml b/operator/transformer/move/testdata/move_attribute_to_resource.yaml index 25b76ca3..428c1334 100644 --- a/operator/transformer/move/testdata/move_attribute_to_resource.yaml +++ b/operator/transformer/move/testdata/move_attribute_to_resource.yaml @@ -1,3 +1,3 @@ type: move -from: $attributes.new -to: $resource.new +from: attributes.new +to: resource.new diff --git a/operator/transformer/move/testdata/move_body_to_attribute.yaml b/operator/transformer/move/testdata/move_body_to_attribute.yaml index d61d6f31..53dd381b 100644 --- a/operator/transformer/move/testdata/move_body_to_attribute.yaml +++ b/operator/transformer/move/testdata/move_body_to_attribute.yaml @@ -1,3 +1,3 @@ type: move -from: $body.key -to: $attributes.new +from: body.key +to: attributes.new diff --git a/operator/transformer/move/testdata/move_body_to_body.yaml b/operator/transformer/move/testdata/move_body_to_body.yaml index 598454b6..8132eeda 100644 --- a/operator/transformer/move/testdata/move_body_to_body.yaml +++ b/operator/transformer/move/testdata/move_body_to_body.yaml @@ -1,3 +1,3 @@ type: move -from: $body.key -to: $body.new +from: body.key +to: body.new diff --git a/operator/transformer/move/testdata/move_bracketed_attribute_to_resource.yaml b/operator/transformer/move/testdata/move_bracketed_attribute_to_resource.yaml index bde27975..486a619c 100644 --- a/operator/transformer/move/testdata/move_bracketed_attribute_to_resource.yaml +++ b/operator/transformer/move/testdata/move_bracketed_attribute_to_resource.yaml @@ -1,3 +1,3 @@ type: move -from: $attributes["dotted.field.name"] -to: $resource.new +from: attributes["dotted.field.name"] +to: resource.new diff --git a/operator/transformer/move/testdata/move_double_nested_object.yaml b/operator/transformer/move/testdata/move_double_nested_object.yaml index d2ac7930..4eeb6963 100644 --- a/operator/transformer/move/testdata/move_double_nested_object.yaml +++ b/operator/transformer/move/testdata/move_double_nested_object.yaml @@ -1,3 +1,3 @@ type: move -from: $body.nested.nested2 -to: $body.nested2 +from: body.nested.nested2 +to: body.nested2 diff --git a/operator/transformer/move/testdata/move_from_nested_object.yaml b/operator/transformer/move/testdata/move_from_nested_object.yaml index e050dc9b..f70f63b3 100644 --- a/operator/transformer/move/testdata/move_from_nested_object.yaml +++ b/operator/transformer/move/testdata/move_from_nested_object.yaml @@ -1,3 +1,3 @@ type: move -from: $body.nested.nestedkey -to: $body.unnestedkey +from: body.nested.nestedkey +to: body.unnestedkey diff --git a/operator/transformer/move/testdata/move_nested.yaml b/operator/transformer/move/testdata/move_nested.yaml index e7cb6b4e..d6e00b40 100644 --- a/operator/transformer/move/testdata/move_nested.yaml +++ b/operator/transformer/move/testdata/move_nested.yaml @@ -1,3 +1,3 @@ type: move -from: $body.nested -to: $body.NewNested +from: body.nested +to: body.NewNested diff --git a/operator/transformer/move/testdata/move_nested_to_attribute.yaml b/operator/transformer/move/testdata/move_nested_to_attribute.yaml index 3074fad7..0f08abc6 100644 --- a/operator/transformer/move/testdata/move_nested_to_attribute.yaml +++ b/operator/transformer/move/testdata/move_nested_to_attribute.yaml @@ -1,3 +1,3 @@ type: move -from: $body.nested -to: $attributes.NewNested +from: body.nested +to: attributes.NewNested diff --git a/operator/transformer/move/testdata/move_nested_to_resource.yaml b/operator/transformer/move/testdata/move_nested_to_resource.yaml index c4855ada..4d6f2b4e 100644 --- a/operator/transformer/move/testdata/move_nested_to_resource.yaml +++ b/operator/transformer/move/testdata/move_nested_to_resource.yaml @@ -1,3 +1,3 @@ type: move -from: $body.nested -to: $resource.NewNested +from: body.nested +to: resource.NewNested diff --git a/operator/transformer/move/testdata/move_resource_to_attribute.yaml b/operator/transformer/move/testdata/move_resource_to_attribute.yaml index 3c608346..d321bb78 100644 --- a/operator/transformer/move/testdata/move_resource_to_attribute.yaml +++ b/operator/transformer/move/testdata/move_resource_to_attribute.yaml @@ -1,3 +1,3 @@ type: move -from: $resource.new -to: $attributes.new +from: resource.new +to: attributes.new diff --git a/operator/transformer/move/testdata/move_to_nested_object.yaml b/operator/transformer/move/testdata/move_to_nested_object.yaml index 977330c7..a3546f15 100644 --- a/operator/transformer/move/testdata/move_to_nested_object.yaml +++ b/operator/transformer/move/testdata/move_to_nested_object.yaml @@ -1,3 +1,3 @@ type: move -from: $body.newnestedkey -to: $body.nested.newnestedkey +from: body.newnestedkey +to: body.nested.newnestedkey diff --git a/operator/transformer/move/testdata/replace_body.yaml b/operator/transformer/move/testdata/replace_body.yaml index c5e66cc1..bf40b527 100644 --- a/operator/transformer/move/testdata/replace_body.yaml +++ b/operator/transformer/move/testdata/replace_body.yaml @@ -1,3 +1,3 @@ type: move -from: nested -to: $body +from: body.nested +to: body diff --git a/operator/transformer/recombine/recombine_test.go b/operator/transformer/recombine/recombine_test.go index 26cc5c6e..c92cb914 100644 --- a/operator/transformer/recombine/recombine_test.go +++ b/operator/transformer/recombine/recombine_test.go @@ -108,7 +108,7 @@ func TestRecombineOperator(t *testing.T) { func() *RecombineOperatorConfig { cfg := NewRecombineOperatorConfig("") cfg.CombineField = entry.NewBodyField() - cfg.IsLastEntry = "$body == 'test2'" + cfg.IsLastEntry = "body == 'test2'" cfg.OutputIDs = []string{"fake"} return cfg }(), @@ -123,7 +123,7 @@ func TestRecombineOperator(t *testing.T) { func() *RecombineOperatorConfig { cfg := NewRecombineOperatorConfig("") cfg.CombineField = entry.NewBodyField() - cfg.IsFirstEntry = "$body == 'test1'" + cfg.IsFirstEntry = "body == 'test1'" cfg.OutputIDs = []string{"fake"} cfg.OverwriteWith = "newest" return cfg @@ -163,7 +163,7 @@ func TestRecombineOperator(t *testing.T) { func() *RecombineOperatorConfig { cfg := NewRecombineOperatorConfig("") cfg.CombineField = entry.NewBodyField() - cfg.IsFirstEntry = "$body == 'file1'" + cfg.IsFirstEntry = "body == 'file1'" cfg.OutputIDs = []string{"fake"} cfg.OverwriteWith = "newest" return cfg @@ -190,7 +190,7 @@ func TestRecombineOperator(t *testing.T) { cfg := NewRecombineOperatorConfig("") cfg.CombineField = entry.NewBodyField() cfg.CombineWith = "" - cfg.IsLastEntry = "$body == 'test2'" + cfg.IsLastEntry = "body == 'test2'" cfg.OutputIDs = []string{"fake"} return cfg }(), @@ -205,7 +205,7 @@ func TestRecombineOperator(t *testing.T) { func() *RecombineOperatorConfig { cfg := NewRecombineOperatorConfig("") cfg.CombineField = entry.NewBodyField() - cfg.IsLastEntry = "$body == 'end'" + cfg.IsLastEntry = "body == 'end'" cfg.OutputIDs = []string{"fake"} return cfg }(), @@ -225,7 +225,7 @@ func TestRecombineOperator(t *testing.T) { func() *RecombineOperatorConfig { cfg := NewRecombineOperatorConfig("") cfg.CombineField = entry.NewBodyField() - cfg.IsLastEntry = "$body == 'end'" + cfg.IsLastEntry = "body == 'end'" cfg.OutputIDs = []string{"fake"} cfg.SourceIdentifier = entry.NewAttributeField("custom_source") return cfg @@ -246,7 +246,7 @@ func TestRecombineOperator(t *testing.T) { func() *RecombineOperatorConfig { cfg := NewRecombineOperatorConfig("") cfg.CombineField = entry.NewBodyField() - cfg.IsLastEntry = "$body == 'end'" + cfg.IsLastEntry = "body == 'end'" cfg.OutputIDs = []string{"fake"} cfg.MaxSources = 1 return cfg @@ -265,7 +265,7 @@ func TestRecombineOperator(t *testing.T) { func() *RecombineOperatorConfig { cfg := NewRecombineOperatorConfig("") cfg.CombineField = entry.NewBodyField() - cfg.IsLastEntry = "$body == 'end'" + cfg.IsLastEntry = "body == 'end'" cfg.OutputIDs = []string{"fake"} cfg.MaxBatchSize = 2 return cfg diff --git a/operator/transformer/remove/rootable_field.go b/operator/transformer/remove/rootable_field.go index 30a4af23..a83ef3c0 100644 --- a/operator/transformer/remove/rootable_field.go +++ b/operator/transformer/remove/rootable_field.go @@ -22,7 +22,7 @@ import ( // RootableField represents a potential field on an entry. // It differs from a normal Field in that it allows users to -// specify `$resource` or `$attributes` with the intention +// specify `resource` or `attributes` with the intention // of referring to "all" fields within those groups. // It is used to get, set, and delete values at this field. // It is deserialized from JSON dot notation. diff --git a/operator/transformer/remove/testdata/remove_body.yaml b/operator/transformer/remove/testdata/remove_body.yaml index cb59448a..05f59097 100644 --- a/operator/transformer/remove/testdata/remove_body.yaml +++ b/operator/transformer/remove/testdata/remove_body.yaml @@ -1,2 +1,2 @@ type: remove -field: nested +field: body.nested diff --git a/operator/transformer/remove/testdata/remove_entire_attributes.yaml b/operator/transformer/remove/testdata/remove_entire_attributes.yaml index 570d0904..9b737ebf 100644 --- a/operator/transformer/remove/testdata/remove_entire_attributes.yaml +++ b/operator/transformer/remove/testdata/remove_entire_attributes.yaml @@ -1,2 +1,2 @@ type: remove -field: $attributes +field: attributes diff --git a/operator/transformer/remove/testdata/remove_entire_body.yaml b/operator/transformer/remove/testdata/remove_entire_body.yaml index 8bb60140..fe53cd07 100644 --- a/operator/transformer/remove/testdata/remove_entire_body.yaml +++ b/operator/transformer/remove/testdata/remove_entire_body.yaml @@ -1,2 +1,2 @@ type: remove -field: $body +field: body diff --git a/operator/transformer/remove/testdata/remove_entire_resource.yaml b/operator/transformer/remove/testdata/remove_entire_resource.yaml index be1c7b21..96052637 100644 --- a/operator/transformer/remove/testdata/remove_entire_resource.yaml +++ b/operator/transformer/remove/testdata/remove_entire_resource.yaml @@ -1,2 +1,2 @@ type: remove -field: $resource +field: resource diff --git a/operator/transformer/remove/testdata/remove_single_attribute.yaml b/operator/transformer/remove/testdata/remove_single_attribute.yaml index 77729cc7..e3e6f611 100644 --- a/operator/transformer/remove/testdata/remove_single_attribute.yaml +++ b/operator/transformer/remove/testdata/remove_single_attribute.yaml @@ -1,2 +1,2 @@ type: remove -field: $attributes.key +field: attributes.key diff --git a/operator/transformer/remove/testdata/remove_single_resource.yaml b/operator/transformer/remove/testdata/remove_single_resource.yaml index ca48b277..35a8c4db 100644 --- a/operator/transformer/remove/testdata/remove_single_resource.yaml +++ b/operator/transformer/remove/testdata/remove_single_resource.yaml @@ -1,2 +1,2 @@ type: remove -field: $resource.key +field: resource.key diff --git a/operator/transformer/restructure/restructure_test.go b/operator/transformer/restructure/restructure_test.go index 10a30dd3..1cbba6ee 100644 --- a/operator/transformer/restructure/restructure_test.go +++ b/operator/transformer/restructure/restructure_test.go @@ -83,7 +83,7 @@ func TestRestructureOperator(t *testing.T) { &OpAdd{ Field: entry.NewBodyField("new"), program: func() *vm.Program { - vm, err := expr.Compile(`$.key + "_suffix"`) + vm, err := expr.Compile(`body.key + "_suffix"`) require.NoError(t, err) return vm }(), @@ -232,11 +232,11 @@ func TestRestructureSerializeRoundtrip(t *testing.T) { op: Op{&OpAdd{ Field: entry.NewBodyField("new"), ValueExpr: func() *string { - s := `$.key + "_suffix"` + s := `body.key + "_suffix"` return &s }(), program: func() *vm.Program { - vm, err := expr.Compile(`$.key + "_suffix"`) + vm, err := expr.Compile(`body.key + "_suffix"`) require.NoError(t, err) return vm }(), @@ -261,7 +261,7 @@ func TestRestructureSerializeRoundtrip(t *testing.T) { name: "Flatten", op: Op{&OpFlatten{ Field: entry.BodyField{ - Keys: []string{"nested"}, + Keys: []string{"body", "nested"}, }, }}, }, @@ -297,18 +297,18 @@ id: my_restructure output: test_output ops: - add: - field: "message" + field: "body.message" value: "val" - add: - field: "message_suffix" - value_expr: "$.message + \"_suffix\"" - - remove: "message" + field: "body.message_suffix" + value_expr: "body.message + \"_suffix\"" + - remove: "body.message" - retain: - - "message_retain" - - flatten: "message_flatten" + - "body.message_retain" + - flatten: "body.message_flatten" - move: - from: "message1" - to: "message2" + from: "body.message1" + to: "body.message2" ` configJSON := ` @@ -318,26 +318,26 @@ ops: "output": "test_output", "ops": [{ "add": { - "field": "message", + "field": "body.message", "value": "val" } },{ "add": { - "field": "message_suffix", - "value_expr": "$.message + \"_suffix\"" + "field": "body.message_suffix", + "value_expr": "body.message + \"_suffix\"" } },{ - "remove": "message" + "remove": "body.message" },{ "retain": [ - "message_retain" + "body.message_retain" ] },{ - "flatten": "message_flatten" + "flatten": "body.message_flatten" },{ "move": { - "from": "message1", - "to": "message2" + "from": "body.message1", + "to": "body.message2" } }] }` @@ -362,11 +362,11 @@ ops: {&OpAdd{ Field: entry.NewBodyField("message_suffix"), ValueExpr: func() *string { - s := `$.message + "_suffix"` + s := `body.message + "_suffix"` return &s }(), program: func() *vm.Program { - vm, err := expr.Compile(`$.message + "_suffix"`) + vm, err := expr.Compile(`body.message + "_suffix"`) require.NoError(t, err) return vm }(), diff --git a/operator/transformer/retain/retain.go b/operator/transformer/retain/retain.go index 32b91457..42eb0391 100644 --- a/operator/transformer/retain/retain.go +++ b/operator/transformer/retain/retain.go @@ -60,11 +60,11 @@ func (c RetainOperatorConfig) Build(logger *zap.SugaredLogger) (operator.Operato for _, field := range c.Fields { typeCheck := field.String() - if strings.HasPrefix(typeCheck, "$resource") { + if strings.HasPrefix(typeCheck, "resource") { retainOp.AllResourceFields = true continue } - if strings.HasPrefix(typeCheck, "$attributes") { + if strings.HasPrefix(typeCheck, "attributes") { retainOp.AllAttributeFields = true continue } diff --git a/operator/transformer/retain/testdata/retain_multi.yaml b/operator/transformer/retain/testdata/retain_multi.yaml index 5c690874..89a5a596 100644 --- a/operator/transformer/retain/testdata/retain_multi.yaml +++ b/operator/transformer/retain/testdata/retain_multi.yaml @@ -1,4 +1,4 @@ type: retain fields: - - "key" - - "nested2" + - body.key + - body.nested2 diff --git a/operator/transformer/retain/testdata/retain_multi_attribute.yaml b/operator/transformer/retain/testdata/retain_multi_attribute.yaml index 9d7c97d6..92d94b58 100644 --- a/operator/transformer/retain/testdata/retain_multi_attribute.yaml +++ b/operator/transformer/retain/testdata/retain_multi_attribute.yaml @@ -1,4 +1,4 @@ type: retain fields: - - $attributes.key1 - - $attributes.key2 + - attributes.key1 + - attributes.key2 diff --git a/operator/transformer/retain/testdata/retain_multi_resource.yaml b/operator/transformer/retain/testdata/retain_multi_resource.yaml index 5ad7eb01..11b02a73 100644 --- a/operator/transformer/retain/testdata/retain_multi_resource.yaml +++ b/operator/transformer/retain/testdata/retain_multi_resource.yaml @@ -1,4 +1,4 @@ type: retain fields: - - $resource.key1 - - $resource.key2 + - resource.key1 + - resource.key2 diff --git a/operator/transformer/retain/testdata/retain_one_of_each.yaml b/operator/transformer/retain/testdata/retain_one_of_each.yaml index 00fe9388..278a5c00 100644 --- a/operator/transformer/retain/testdata/retain_one_of_each.yaml +++ b/operator/transformer/retain/testdata/retain_one_of_each.yaml @@ -1,5 +1,5 @@ type: retain fields: - - $resource.key1 - - $attributes.key3 - - $body.key + - resource.key1 + - attributes.key3 + - body.key diff --git a/operator/transformer/retain/testdata/retain_single.yaml b/operator/transformer/retain/testdata/retain_single.yaml index 13d6af24..83d8d595 100644 --- a/operator/transformer/retain/testdata/retain_single.yaml +++ b/operator/transformer/retain/testdata/retain_single.yaml @@ -1,3 +1,3 @@ type: retain fields: - - "key" + - body.key diff --git a/operator/transformer/retain/testdata/retain_single_attribute.yaml b/operator/transformer/retain/testdata/retain_single_attribute.yaml index 6397ec20..537ed1ff 100644 --- a/operator/transformer/retain/testdata/retain_single_attribute.yaml +++ b/operator/transformer/retain/testdata/retain_single_attribute.yaml @@ -1,3 +1,3 @@ type: retain fields: - - $attributes.key + - attributes.key diff --git a/operator/transformer/retain/testdata/retain_single_resource.yaml b/operator/transformer/retain/testdata/retain_single_resource.yaml index 9e251a1a..b52917ff 100644 --- a/operator/transformer/retain/testdata/retain_single_resource.yaml +++ b/operator/transformer/retain/testdata/retain_single_resource.yaml @@ -1,3 +1,3 @@ type: retain fields: - - $resource.key + - resource.key diff --git a/operator/transformer/router/config_test.go b/operator/transformer/router/config_test.go index 111d8066..a866e364 100644 --- a/operator/transformer/router/config_test.go +++ b/operator/transformer/router/config_test.go @@ -31,7 +31,7 @@ func TestRouterGoldenConfig(t *testing.T) { Expect: func() *RouterOperatorConfig { cfg := defaultCfg() newRoute := &RouterOperatorRouteConfig{ - Expression: `$.format == "json"`, + Expression: `body.format == "json"`, OutputIDs: []string{"my_json_parser"}, } cfg.Routes = append(cfg.Routes, newRoute) @@ -44,15 +44,15 @@ func TestRouterGoldenConfig(t *testing.T) { cfg := defaultCfg() newRoute := []*RouterOperatorRouteConfig{ { - Expression: `$.format == "json"`, + Expression: `body.format == "json"`, OutputIDs: []string{"my_json_parser"}, }, { - Expression: `$.format == "json"2`, + Expression: `body.format == "json"2`, OutputIDs: []string{"my_json_parser2"}, }, { - Expression: `$.format == "json"3`, + Expression: `body.format == "json"3`, OutputIDs: []string{"my_json_parser3"}, }, } @@ -72,7 +72,7 @@ func TestRouterGoldenConfig(t *testing.T) { cfg.Routes = []*RouterOperatorRouteConfig{ { - Expression: `$.format == "json"`, + Expression: `body.format == "json"`, OutputIDs: []string{"my_json_parser"}, AttributerConfig: attVal, }, @@ -85,7 +85,7 @@ func TestRouterGoldenConfig(t *testing.T) { Expect: func() *RouterOperatorConfig { cfg := defaultCfg() newRoute := &RouterOperatorRouteConfig{ - Expression: `$.format == "json"`, + Expression: `body.format == "json"`, OutputIDs: []string{"my_json_parser"}, } cfg.Routes = append(cfg.Routes, newRoute) diff --git a/operator/transformer/router/router_test.go b/operator/transformer/router/router_test.go index dc04a102..8d0222dc 100644 --- a/operator/transformer/router/router_test.go +++ b/operator/transformer/router/router_test.go @@ -87,12 +87,12 @@ func TestRouterOperator(t *testing.T) { []*RouterOperatorRouteConfig{ { helper.NewAttributerConfig(), - `$.message == "non_match"`, + `body.message == "non_match"`, []string{"output1"}, }, { helper.NewAttributerConfig(), - `$.message == "test_message"`, + `body.message == "test_message"`, []string{"output2"}, }, }, @@ -110,7 +110,7 @@ func TestRouterOperator(t *testing.T) { []*RouterOperatorRouteConfig{ { helper.NewAttributerConfig(), - `$.message == "non_match"`, + `body.message == "non_match"`, []string{"output1"}, }, { @@ -119,7 +119,7 @@ func TestRouterOperator(t *testing.T) { "label-key": "label-value", }, }, - `$.message == "test_message"`, + `body.message == "test_message"`, []string{"output2"}, }, }, diff --git a/operator/transformer/router/testdata/routes_attributes.yaml b/operator/transformer/router/testdata/routes_attributes.yaml index af44478c..b8778879 100644 --- a/operator/transformer/router/testdata/routes_attributes.yaml +++ b/operator/transformer/router/testdata/routes_attributes.yaml @@ -1,6 +1,6 @@ type: router routes: - output: my_json_parser - expr: '$.format == "json"' + expr: 'body.format == "json"' attributes: key1: val1 diff --git a/operator/transformer/router/testdata/routes_default.yaml b/operator/transformer/router/testdata/routes_default.yaml index d0ae9276..8438e8cd 100644 --- a/operator/transformer/router/testdata/routes_default.yaml +++ b/operator/transformer/router/testdata/routes_default.yaml @@ -1,5 +1,5 @@ type: router routes: - output: my_json_parser - expr: '$.format == "json"' + expr: 'body.format == "json"' default: catchall diff --git a/operator/transformer/router/testdata/routes_multi.yaml b/operator/transformer/router/testdata/routes_multi.yaml index 3380214b..cbae3aa9 100644 --- a/operator/transformer/router/testdata/routes_multi.yaml +++ b/operator/transformer/router/testdata/routes_multi.yaml @@ -1,8 +1,8 @@ type: router routes: - output: my_json_parser - expr: '$.format == "json"' + expr: 'body.format == "json"' - output: my_json_parser2 - expr: '$.format == "json"2' + expr: 'body.format == "json"2' - output: my_json_parser3 - expr: '$.format == "json"3' + expr: 'body.format == "json"3' diff --git a/operator/transformer/router/testdata/routes_one.yaml b/operator/transformer/router/testdata/routes_one.yaml index 7f8a7970..96e17983 100644 --- a/operator/transformer/router/testdata/routes_one.yaml +++ b/operator/transformer/router/testdata/routes_one.yaml @@ -1,4 +1,4 @@ type: router routes: - output: my_json_parser - expr: '$.format == "json"' + expr: 'body.format == "json"'