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

Event type in lua is userdata, not table #1297

Closed
mikhno-s opened this issue Dec 2, 2019 · 5 comments · Fixed by #2000
Closed

Event type in lua is userdata, not table #1297

mikhno-s opened this issue Dec 2, 2019 · 5 comments · Fixed by #2000
Labels
transform: lua Anything `lua` transform related type: bug A code related bug.

Comments

@mikhno-s
Copy link

mikhno-s commented Dec 2, 2019

Hi!

Docs says that event has lua type table, I get userdata, hence, I cannot use pairs function.

My configuration:

OS: OS X 10.14.6
Vector ver.:vector 0.6.0-nightly (the same problem on v0.4.0 and 0.5.0, probably)

config.toml:

data_dir = "${PWD}/data"

[sources.in_err_logs]
    type = "file"
    include = ["./*.log"]
    glob_minimum_cooldown = 1000
    ignore_older = 86400
    max_read_bytes = 4096

    
[sources.in_err_logs.fingerprinting]
    strategy = "checksum"
    fingerprint_bytes = 16
    ignored_header_bytes = 0

[transforms.test]
    type = "lua"
    inputs = ["in_err_logs"]
    source = """
       print(type(event))
    """

[sinks.print_to_console]
  type = "console"
  inputs = ["test"]
  encoding = "json"

error.log:

{"MESSAGE":{"text":"error"}}

output:

$ vector --config config.toml
Dec 02 16:55:16.012  INFO vector: Log level "info" is enabled.
Dec 02 16:55:16.013  INFO vector: Loading config. path="config.toml"
Dec 02 16:55:16.031  INFO vector: Vector is starting. version="0.6.0" git_version="v0.5.0-198-ga6668b0" released="Mon, 02 Dec 2019 11:16:59 +0000" arch="x86_64"
Dec 02 16:55:16.038  INFO vector::topology: Running healthchecks.
Dec 02 16:55:16.038  INFO vector::topology: Starting source "in_err_logs"
Dec 02 16:55:16.039  INFO vector::topology: Starting transform "test"
Dec 02 16:55:16.039  INFO vector::topology::builder: Healthcheck: Passed.
Dec 02 16:55:16.039  INFO vector::topology: Starting sink "print_to_console"
Dec 02 16:55:16.040  INFO source{name=in_err_logs type=file}: vector::sources::file: Starting file server. include=["./*.log"] exclude=[]
Dec 02 16:55:16.042  INFO source{name=in_err_logs type=file}:file_server: file_source::file_server: Found file to watch. path="error.log" file_position=0
userdata
{"timestamp":"2019-12-02T14:55:16.044518Z","file":"error.log","host":"my-mac.local","message":"{\"MESSAGE\":{\"text\":\"error\"}}"}

As you can see print(type(event)) - printed userdata, not a table as I expected due to docs.

@binarylogic binarylogic added this to the Improve data processing milestone Dec 6, 2019
@binarylogic
Copy link
Contributor

Hi @mikhno-s, thanks for letting us know. We'll update the docs. Additionally, we're about to make a bunch of improvements to our lua integration so stay tuned!

@binarylogic binarylogic added domain: docs transform: lua Anything `lua` transform related type: bug A code related bug. labels Dec 6, 2019
@WillDrug
Copy link

WillDrug commented Dec 18, 2019

@binarylogic hey, I need to move nested fields around, so userdata field basically means I can't use vector at all, because there is no way to manipulate a dynamic set or fields (labels, for instance). With userdata event["root.nested.key"] is a string, for instance, but event["root.nested"] is nil.
Was there an update? If not, when can we expect one?

UPD: Alternatevily, there probably should be a way to manipulate event fields without scripting. Lua should be used for something complex, while simple rearranging should be done with add_field transform (or move_field\copy\etc)

@binarylogic
Copy link
Contributor

Hey @WillDrug, sorry about that and thanks for letting us know. We just started working through https://github.com/timberio/vector/milestone/23, where we expect to improve the lua (and javascript) integration considerably. I'd classify the current integration in a very MVP state, and this next pass will bring improvements like:

  1. Stricter type conversion.
  2. Actual nested data model representation.
  3. Native lua extensions.
  4. A variety of other performance and bug fixes.

@a-rodin is owning that project and I expect that we'll address this properly within 3-4 weeks. @a-rodin is there a simple workaround in the interim? Ideally, something that aligns with further changes we're going to make. If not, then we should have something within the timeframe stated.

@WillDrug
Copy link

@binarylogic well, after the update, at least pairs function works correctly, so if the matter is pressing we can use it (also, inspect). But for now we've decided to configure metadata at each source and use grokk for new fields

@ghost
Copy link

ghost commented Dec 18, 2019

I wanted suggest to use pairs to get all keys and then renaming the keys values correspondingly.

However, we do plan to change the nesting approach, so that the nested fields would be represented as nested tables instead of flat key values with dots.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
transform: lua Anything `lua` transform related type: bug A code related bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants