Skip to content

After lua transformed , all int type values changed to float #5310

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

Closed
thomasdba opened this issue Dec 1, 2020 · 5 comments
Closed

After lua transformed , all int type values changed to float #5310

thomasdba opened this issue Dec 1, 2020 · 5 comments
Assignees
Labels
have: must We must have this feature, it is critical to the project's success. It is high priority. transform: lua Anything `lua` transform related type: bug A code related bug.

Comments

@thomasdba
Copy link

thomasdba commented Dec 1, 2020

Vector Version

0.10.0

...

Vector Configuration File

...
[transforms.lua]
  inputs = ["file"]
  type = "lua"
  version = "2"
  hooks.process = """
    function (event, emit)
      local cjson = require('cjson.safe')
      local str = event.log.message
      local msg = cjson.decode(str)
      if msg then
        msg['env_vars'] = cjson.encode(msg['env_vars'])
        msg['request']['headers'] = cjson.encode(msg['request']['headers'])
        msg['response']['headers'] = cjson.encode(msg['response']['headers'])
        msg['response']['body'] = cjson.encode(msg['response']['body'])
        msg['route']['paths'] = cjson.encode(msg['route']['paths'])
        msg['route']['protocols'] = cjson.encode(msg['route']['protocols'])
        msg['service']['tags'] = cjson.encode(msg['service']['tags'])
        for key, value in pairs(msg) do
          event.log[key] = value
        end
      end
      event.log.message = nil
      emit(event)
    end
  """

Debug Output

Expected Behavior

Actual Behavior

After using lua to transform , all int values were converted to float . for example status:200 is transformed to status: 200.0

Example Data

Additional Context

References

@thomasdba thomasdba added the type: bug A code related bug. label Dec 1, 2020
@binarylogic binarylogic added have: must We must have this feature, it is critical to the project's success. It is high priority. transform: lua Anything `lua` transform related labels Dec 1, 2020
@binarylogic
Copy link
Contributor

Thanks for reporting @thomasdba, we'll expedite a fix.

@ktff
Copy link
Contributor

ktff commented Apr 7, 2021

@thomasdba this is an issue of missing support for Lua 5.3 integers in cjson. You can see it mentioned here openresty/lua-cjson#3 and here mpx/lua-cjson#33, so I'll close this.

@ktff ktff closed this as completed Apr 7, 2021
@jszwedko
Copy link
Member

jszwedko commented Apr 7, 2021

@ktff thanks for investigating this. Could we add a note to the docs for the lua transform?

@ktff
Copy link
Contributor

ktff commented Apr 7, 2021

@jszwedko I'm not sure that we need to. This is a missing feature in cjson which the user needs to install separately from Vector and then explicitly load it to lua transform so I think it's the users responsibility to check for this.

@jszwedko
Copy link
Member

jszwedko commented Apr 7, 2021

@ktff aha, gotcha 👍 I missed that this was specific to cjson. I thought we were generally converting ints to floats in the Lua transform. Agreed that we don't need to document it then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
have: must We must have this feature, it is critical to the project's success. It is high priority. transform: lua Anything `lua` transform related type: bug A code related bug.
Projects
None yet
Development

No branches or pull requests

7 participants