vectordotdev / vector

A high-performance observability data pipeline.
https://vector.dev
Mozilla Public License 2.0
17.06k stars 1.48k forks source link

Delete root object changed behavior in 0.26.0 for vector test #15542

Open awangc opened 1 year ago

awangc commented 1 year ago

A note for the community

Problem

In vector 0.25.2, the following test case passes:

[transforms.test]
  type = "remap"
  inputs = ["not_used"]
  source = '''
    .vector = del(.)
    .log.level = "warn"
  '''

[[tests]]
  name = "test_vector"

  [[tests.inputs]]
    insert_at = "test"
    type = "log"
    log_fields.message = "Received one event."

  [[tests.outputs]]
     extract_from = "test"

    [[tests.outputs.conditions]]
      type = "vrl"
      source = '''
        assert_eq!(.log.level, "warn", "log level failure")
        assert_eq!(.vector.message, "Received one event.", "message failure")
     '''

but in 0.26.0 it fails with following error message

❯ vector260 test test.toml
Running tests
2022-12-12T13:30:04.416094Z ERROR vector::unit_test: Failed to execute tests:
Failed to build test 'test_vector':
  Transform "test":
  error[E642]: parent path segment rejects this mutation
    β”Œβ”€ :2:10
    β”‚
  2 β”‚     .log.level = "warn"
    β”‚     ---- ^^^^^ querying a field of a non-object type is unsupported
    β”‚     β”‚
    β”‚     this path resolves to a value of type undefined
    β”‚
    = try: change parent value to object, before assignment
    =
    =     .log = {}
    =     .log.level = "warn"
    =
    = see documentation about error handling at https://errors.vrl.dev/#handling
    = see language documentation at https://vrl.dev
    = try your code in the VRL REPL, learn more at https://vrl.dev/examples

Configuration

[transforms.test]
  type = "remap"
  inputs = ["not_used"]
  source = '''
    .vector = del(.)
    .log.level = "warn"
  '''

[[tests]]
  name = "test_vector"

  [[tests.inputs]]
    insert_at = "test"
    type = "log"
    log_fields.message = "Received one event."

  [[tests.outputs]]
     extract_from = "test"

    [[tests.outputs.conditions]]
      type = "vrl"
      source = '''
        assert_eq!(.log.level, "warn", "log level failure")
        assert_eq!(.vector.message, "Received one event.", "message failure")
     '''

Version

vector 0.26.0 (x86_64-apple-darwin c6b5bc2 2022-12-05)

Debug Output

❯ RUST_BACKTRACE=full vector260 -vvv  test test.toml
2022-12-12T13:32:09.192628Z  INFO vector::app: Internal log rate limit configured. internal_log_rate_secs=10
Running tests
2022-12-12T13:32:09.196264Z DEBUG vector::topology::builder: Building new source. component=test-source-8a402a30-a0bf-4384-b6e7-4c05d78a69b1
2022-12-12T13:32:09.196709Z DEBUG vector::topology::builder: Building new transform. component=test
2022-12-12T13:32:09.196991Z DEBUG vector::topology::builder: Building new sink. component=test-sink-8a402a30-a0bf-4384-b6e7-4c05d78a69b1
2022-12-12T13:32:09.197161Z ERROR vector::unit_test: Failed to execute tests:
Failed to build test 'test_vector':
  Transform "test":
  error[E642]: parent path segment rejects this mutation
    β”Œβ”€ :2:10
    β”‚
  2 β”‚     .log.level = "warn"
    β”‚     ---- ^^^^^ querying a field of a non-object type is unsupported
    β”‚     β”‚
    β”‚     this path resolves to a value of type undefined
    β”‚
    = try: change parent value to object, before assignment
    =
    =     .log = {}
    =     .log.level = "warn"
    =
    = see documentation about error handling at https://errors.vrl.dev/#handling
    = see language documentation at https://vrl.dev
    = try your code in the VRL REPL, learn more at https://vrl.dev/examples
  .

Example Data

No response

Additional Context

No reference to this behavior was made in the breaking changes upgrade guide of the release documentation https://vector.dev/highlights/2022-11-07-0-26-0-upgrade-guide/

References

No response

ypid-work commented 4 months ago

As @awangc already pointed out, this is not listed in the "breaking changes" of 0.26.0 which made this also very difficult for me to tackle. Rather it is in https://vector.dev/highlights/2022-08-16-0-24-0-upgrade-guide/#vrl-query-assignment but for me as user, 0.24.0 did not introduce this behavior:

$ for vector_version in 0.23.3 0.24.0 0.25.0 0.26.0; do echo "Running test with vector ${vector_version}:"; docker run --rm -ti -v ".:/opt/vector" "timberio/vector:${vector_version}-alpine" test /opt/vector/issue-15542.yml; done
Running test with vector 0.23.3:
Running tests
test Delete root object changed behavior in 0.26.0 for vector test #15542 ... passed
Running test with vector 0.24.0:
Running tests
test Delete root object changed behavior in 0.26.0 for vector test #15542 ... passed
Running test with vector 0.25.0:
Running tests
test Delete root object changed behavior in 0.26.0 for vector test #15542 ... passed
Running test with vector 0.26.0:
Running tests
2024-03-05T15:19:56.454903Z ERROR vector::unit_test: Failed to execute tests:
Failed to build test 'Delete root object changed behavior in 0.26.0 for vector test #15542':
  Transform "test": 
  error[E642]: parent path segment rejects this mutation
    β”Œβ”€ :2:6
    β”‚
  2 β”‚ .log.level = "warn"
    β”‚ ---- ^^^^^ querying a field of a non-object type is unsupported
    β”‚ β”‚
    β”‚ this path resolves to a value of type undefined
    β”‚
    = try: change parent value to object, before assignment
    =
    =     .log = {}
    =     .log.level = "warn"
    =
    = see documentation about error handling at https://errors.vrl.dev/#handling
    = see language documentation at https://vrl.dev
    = try your code in the VRL REPL, learn more at https://vrl.dev/examples
  .
---

transforms:
  test:
    type: remap
    inputs: [not_used]
    source: |-
      .vector = del(.)
      .log.level = "warn"

tests:
  - name: 'Delete root object changed behavior in 0.26.0 for vector test #15542'
    inputs:
      - insert_at: test
        type: log
        log_fields:
          message: Received one event.
    outputs:
      - extract_from: test
        conditions:
          - type: vrl
            source: |-
              assert_eq!(.log.level, "warn", "log level failure")
              assert_eq!(.vector.message, "Received one event.", "message failure")

https://github.com/vectordotdev/vrl/issues/118 cleared this up for me.

@JeanMertz Do you know why your feature is not active in 0.24.0 (where it is merged)? Does it make sense to move the docs of this breaking change to https://vector.dev/highlights/2022-11-07-0-26-0-upgrade-guide/?