Skip to content

enhancement(lua transform): Implement all hooks and timers in version 2 #2126

Merged
56 commits merged intomasterfrom
lua-v2-hooks
Apr 7, 2020
Merged

enhancement(lua transform): Implement all hooks and timers in version 2 #2126
56 commits merged intomasterfrom
lua-v2-hooks

Conversation

@ghost
Copy link

@ghost ghost commented Mar 24, 2020

Closes #616, closes #1549, closes #2189.

Currently it implements only process hook, I want to put other hooks to a separate PR because it would involve changing the stream

This is based on top of work from #2095. I'm going to also update the documentation and add some example before merging this.

a-rodin added 3 commits March 24, 2020 16:30
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
@ghost ghost changed the title Lua v2 hooks enhancement(lua transform): Implement hooks.process in version 2 Mar 24, 2020
@ghost ghost added the needs: docs Needs documentation updates label Mar 24, 2020
@binarylogic binarylogic requested a review from Hoverbear March 25, 2020 03:17
a-rodin added 4 commits March 25, 2020 21:41
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
@ghost ghost requested a review from binarylogic as a code owner March 27, 2020 19:09
a-rodin added 6 commits March 30, 2020 17:31
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
[docs.configuration#environment-variables]: /docs/setup/configuration/#environment-variables
[docs.data-model.log#schema]: /docs/about/data-model/log/#schema
[docs.data-model.log]: /docs/about/data-model/log/
[docs.data-model.metric]: /docs/about/data-model/metric/
Copy link
Contributor

Choose a reason for hiding this comment

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

The inconsistent naming here is unfortunate. :(

Copy link
Author

Choose a reason for hiding this comment

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

I agree, it makes sense to use snake case everywhere.

result
}

// Used only in tests.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we #[cfg(test)] this?

Copy link
Author

Choose a reason for hiding this comment

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

These are part of the Transform trait, so it is necessary to provide at least some implementation for them.

Copy link
Contributor

@Hoverbear Hoverbear left a comment

Choose a reason for hiding this comment

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

Only a couple nits :)

a-rodin added 3 commits April 1, 2020 18:50
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
@ghost ghost requested a review from Hoverbear April 1, 2020 20:57
@ghost
Copy link
Author

ghost commented Apr 1, 2020

Now all three kinds of hooks, as well as timers, are implemented. I spent some time trying to put the runtime into a separate thread, because it is not robust to block Tokio thread. However, the current implementation runs on Tokio thread, so I think it is fine postpone moving the execution into a separate thread. I've created issue #2200 for this.

I'm going to tidy up the documentation tomorrow, but for now it is possible to consult the RFC for the description.

@binarylogic
Copy link
Contributor

Sounds good! I can help with the docs as well. Why don't you make a first pass then I'll review.

binarylogic and others added 4 commits April 1, 2020 17:09
Signed-off-by: binarylogic <bjohnson@binarylogic.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: binarylogic <bjohnson@binarylogic.com>
@binarylogic
Copy link
Contributor

binarylogic commented Apr 5, 2020

@a-rodin, I removed the source field documentation since it is not relevant for v2. I don't think we should cater to v1 since we'll be releasing shortly after merging this (assuming it is not blocked by anything major).

Edit: I've re-added this now that I understand it can be used as the single place for all Lua source.

Signed-off-by: binarylogic <bjohnson@binarylogic.com>
Signed-off-by: binarylogic <bjohnson@binarylogic.com>
Signed-off-by: binarylogic <bjohnson@binarylogic.com>
Signed-off-by: binarylogic <bjohnson@binarylogic.com>
Signed-off-by: binarylogic <bjohnson@binarylogic.com>
Signed-off-by: binarylogic <bjohnson@binarylogic.com>
@binarylogic
Copy link
Contributor

Ok, I've improved the configuration examples. As a side effect of doing this I fixed an option sorting bug that resulted in updating a number of other documentation pages.

Signed-off-by: binarylogic <bjohnson@binarylogic.com>
@lukesteensen
Copy link
Member

@lukesteensen is it ok if this transform accepts both logs and metrics? Isn't this currently blocked by #421?

There's no issue with accepting both logs and metrics. The question is really about having output_type return DataType::Any because there aren't many transforms or sinks that accept DataType::Any as their input. That means this transform itself would work fine, but you couldn't use it as input for much of anything.

A quick fix would be to add a config option to specify the output type and filter accordingly.

@binarylogic
Copy link
Contributor

binarylogic commented Apr 6, 2020

@a-rodin if we can address that final issue then we should be able to merge. If I recall, the proper fix is more involved and will need to be resolved separately (#1998 (comment)). You're also welcome to take a stab at solving this properly.

a-rodin added 3 commits April 6, 2020 23:19
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
@ghost
Copy link
Author

ghost commented Apr 6, 2020

Actually I feel like solving it properly might be not much harder than adding output_type config option and filtering to only the Lua transform. At least, for downstream transforms the filtering could be added quite easy at the topology building step by replacing input_rx here https://github.com/timberio/vector/blob/7d9ebc3d580eff9d12f31563306d0d8bf3285248/src/topology/builder.rs#L175

by input_rx.filter(|event| ...), where the filtering function can use the input type of the current transform. The signature of transform_stream would need to be changed to take a generic stream instead of just Receiver, but it should be easy.

I'm less familiar with sinks though, so I'll take a look at them.

@binarylogic
Copy link
Contributor

Yeah, depending on what you find I wouldn't mind considering fixing this correctly. That was on Luke's plate but he has more pressing issues he's addressing this week.

Signed-off-by: binarylogic <bjohnson@binarylogic.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
@ghost ghost requested a review from lukesteensen as a code owner April 7, 2020 13:52
Copy link
Member

@lukesteensen lukesteensen left a comment

Choose a reason for hiding this comment

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

Very clever! I should have thought of this myself 😄

Eventually, it would be nice to have this more isolated from topology building, skip filtering when we know it's not needed, etc. But this is very practical and should work quite well! 👏

| (Node::Transform { out_ty: ty1, .. }, Node::Transform { in_ty: ty2, .. })
| (Node::Transform { out_ty: ty1, .. }, Node::Sink { ty: ty2, .. }) => {
if ty1 != ty2 && ty2 != DataType::Any {
if ty1 != ty2 && ty1 != DataType::Any && ty2 != DataType::Any {
Copy link
Member

Choose a reason for hiding this comment

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

Did this not require any changes to the tests? I must have missed a case. Could be worth adding a quick one now.

Copy link
Author

@ghost ghost Apr 7, 2020

Choose a reason for hiding this comment

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

Actually, this was caught by a test. abf4f59 updated it.

Also, with cd5ff29 the filtering is skipped if the component supports any event type.

a-rodin added 4 commits April 7, 2020 17:34
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
@ghost ghost merged commit 0d0a8fa into master Apr 7, 2020
@binarylogic binarylogic deleted the lua-v2-hooks branch April 24, 2020 20:38
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lua multiplying calculation error Change execution model for lua transform Verify lua script compilation as part of config validation

4 participants