Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Ability to inject events into sources for unit testing #21223

Open
s-at-ik opened this issue Sep 6, 2024 · 1 comment
Open

Ability to inject events into sources for unit testing #21223

s-at-ik opened this issue Sep 6, 2024 · 1 comment
Labels
domain: unit tests Anything related to Vector's unit testing feature type: feature A value-adding code addition that introduce new functionality.

Comments

@s-at-ik
Copy link

s-at-ik commented Sep 6, 2024

A note for the community

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Use Cases

I would like to ensure a change in multiline patterns will not break known multiline logs.

Attempted Solutions

I've tried writing a test case with input of type raw and insert_at the source component. However that's not supported:

sources:
  test_source:
    type: file
    include:
      - /var/log/example.log
    multiline:
      start_pattern: '^#'
      mode: halt_before
      condition_pattern: '^#'
      timeout_ms: 100

sinks:
  console:
    type: console
    target: stdout
    inputs:
      - test_source
    encoding:
      codec: json

tests:
  - name: test 1
    inputs:
      - insert_at: test_source
        type: raw
        value: |-
          # line start 1
          foo
          bar
          # line start 2
          foo
          bar
    outputs:
      - extract_from: test_source
        conditions:
          - type: vrl
            source: |-
              assert_eq!(.message, "# line start 1\nfoo\nbar")
Running tests
2024-09-06T13:11:18.960534Z ERROR vector::unit_test: Failed to execute tests:
Failed to build test 'test 1':
  Invalid extract_from target in test 'test 1': 'test_source' does not exist.

(adding a dummy transform just yields the same error on the input)

Proposal

As seen in my attempt above, one way to test multilines would be to allow source components as input_at and extract_from targets. Not sure it makes sense in any other case beside multiline though.

References

No response

Version

vector 0.40.1 (x86_64-unknown-linux-gnu a9392b0 2024-08-26 14:35:19.223750502)

@s-at-ik s-at-ik added the type: feature A value-adding code addition that introduce new functionality. label Sep 6, 2024
@jszwedko
Copy link
Member

jszwedko commented Sep 6, 2024

Ah, yes, it isn't possible to provide inputs to sources for unit tests. Let me reword this title to be a bit broader.

As a workaround, instead of using the multiline config you could use a reduce transform, which would be unit testable.

@jszwedko jszwedko changed the title Ability to unit test multiline source components Ability to inject events into sources for unit testing Sep 6, 2024
@jszwedko jszwedko added the domain: unit tests Anything related to Vector's unit testing feature label Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain: unit tests Anything related to Vector's unit testing feature type: feature A value-adding code addition that introduce new functionality.
Projects
None yet
Development

No branches or pull requests

2 participants