Skip to content

Conversation

@ilinas
Copy link
Contributor

@ilinas ilinas commented Mar 7, 2025

Summary

A variant of ring buffer / backtrace logging. Keeps events in a buffer until a trigger is encountered and the buffer is flushed. When the buffer is full, the oldest events are being dropped, and it works pretty much like the filter transform.

This is rewrite of my previous PR #21071 with the complexity and the scope reduced.

Change Type

  • Bug fix
  • New feature
  • Non-functional (chore, refactoring, docs)
  • Performance

Is this a breaking change?

  • Yes
  • No

How did you test this PR?

Sample configuration:

sources:
  log_generator:
    type: demo_logs
    format: json
    interval: 0.1

  trigger:
    type: demo_logs
    format: shuffle
    lines:
      - '{"message": "flush"}'
      - '{"message": "pass"}'
      - '{"message": "hello"}'
    interval: 1

transforms:
  parse_json:
    type: remap
    inputs:
      - log_generator
      - trigger
    source: ". = parse_json!(string!(.message))"

  window_transform:
    type: window
    inputs:
      - parse_json
    pass_when: '.message == "pass"'
    flush_when: '.message == "flush"'
    events_before: 3
    events_after: 2

sinks:
  output:
    type: console
    inputs:
      - window_transform
    encoding:
      codec: json

Does this PR include user facing changes?

  • Yes. Please add a changelog fragment based on our guidelines.
  • No. A maintainer will apply the "no-changelog" label to this PR.

Checklist

  • Please read our Vector contributor resources.
    • make check-all is a good command to run locally. This check is
      defined here. Some of these
      checks might not be relevant to your PR. For Rust changes, at the very least you should run:
      • cargo fmt --all
      • cargo clippy --workspace --all-targets -- -D warnings
      • cargo nextest run --workspace (alternatively, you can run cargo test --all)
  • If this PR introduces changes Vector dependencies (modifies Cargo.lock), please
    run dd-rust-license-tool write to regenerate the license inventory and commit the changes (if any). More details here.

References

@ilinas ilinas requested review from a team as code owners March 7, 2025 12:47
@github-actions github-actions bot added domain: transforms Anything related to Vector's transform components domain: external docs Anything related to Vector's external, public documentation labels Mar 7, 2025
@pront pront self-assigned this Mar 7, 2025
Copy link
Contributor

@joepeeples joepeeples left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple small line edit suggestions but otherwise LGTM, thanks!

Co-authored-by: Joe Peeples <joe.peeples@datadoghq.com>
@jorgehermo9
Copy link
Contributor

I think I liked more the gate name you proposed before! #15263 (comment)

@ilinas
Copy link
Contributor Author

ilinas commented Mar 12, 2025

I think I liked more the gate name you proposed before! #15263 (comment)

I chose a new name because I felt that gate could be a separate transform that implements open_when and close_when and does not use a buffer. Like a dynamic filter. In the end this proved not really useful in my infrastructure, so it never came to be. Well, not yet.

The window name is a reference to the sliding window technique, which I believe makes it easier to explain what it actually does.

@ilinas
Copy link
Contributor Author

ilinas commented Mar 13, 2025

Thank you for the review and edits @joepeeples.

I thought the original description of the transform was not great, so I decided to update it. Would you mind taking a look a the changes I made in commit 92ae4af?

@ilinas ilinas requested a review from joepeeples March 13, 2025 10:07
@ilinas
Copy link
Contributor Author

ilinas commented Mar 20, 2025

This is a real-life example of what the transform does.
window-transform-logs
The service is logging at debug level, and the transform is configured with pass_when: .level == "info" and flush_when: .level == "error".

@pront
Copy link
Member

pront commented Mar 26, 2025

This is a real-life example of what the transform does. window-transform-logs The service is logging at debug level, and the transform is configured with pass_when: .level == "info" and flush_when: .level == "error".

Thank you @ilinas. This PR is on my radar. I will do a proper review soon!

Copy link
Member

@pront pront left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thanks @ilinas. I left some comments, mostly nits.

@ilinas
Copy link
Contributor Author

ilinas commented Apr 9, 2025

I think this is the final version of the code.

@pront
Copy link
Member

pront commented Apr 10, 2025

I think this is the final version of the code.

Nice! I will do one more review but we can easily include this in the next release.

@pront
Copy link
Member

pront commented Apr 15, 2025

@ilinas this looks like a good first version!

@pront pront added this pull request to the merge queue Apr 15, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 15, 2025
@pront
Copy link
Member

pront commented Apr 15, 2025

Please git merge origin master (I tried to do it but your remote rejected the push)

@pront pront enabled auto-merge April 15, 2025 18:37
@ilinas
Copy link
Contributor Author

ilinas commented Apr 16, 2025

@pront I could use some help figuring out what is it failing on this time?

@pront
Copy link
Member

pront commented Apr 16, 2025

@pront I could use some help figuring out what is it failing on this time?

Not sure, you can try merging the latest origin/master just to re-trigger the CI checks. It would be easier to help if I could push to the remote.

@pront pront added this pull request to the merge queue Apr 16, 2025
Merged via the queue into vectordotdev:master with commit 3ea8c86 Apr 16, 2025
42 checks passed
@pront pront deleted the window-transform branch April 16, 2025 22:35
pront added a commit to gllb/vector that referenced this pull request Apr 22, 2025
* feat(new transform): Add window transform

* Fix spelling errors

* Reformat cue docs

* Apply documentation changes from code review

Co-authored-by: Joe Peeples <joe.peeples@datadoghq.com>

* Generate component docs

* Update transform description

* Add a more detailed changelog

* Rename config variables, update docs

---------

Co-authored-by: Joe Peeples <joe.peeples@datadoghq.com>
Co-authored-by: Pavlos Rontidis <pavlos.rontidis@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain: external docs Anything related to Vector's external, public documentation domain: transforms Anything related to Vector's transform components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ring buffer / backtrace event handling

4 participants