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

feat(plugins) add log by lua capability #6944

Merged
merged 2 commits into from
Mar 23, 2021
Merged

feat(plugins) add log by lua capability #6944

merged 2 commits into from
Mar 23, 2021

Conversation

gszr
Copy link
Member

@gszr gszr commented Mar 22, 2021

Add capability to set new log fields, or unset existing fields, by
executing custom Lua code in the Log phase.

This feature uses the new PDK method kong.log.set_serialize_value,
as well as the new sandbox capability, both introduced in Kong 2.3.

Currently supported logging plugins:

  • file-log
  • Loggly
  • Syslog
  • tcp-log
  • udp-log
  • http-log

Not included in:

  • Datadog
  • Statsd

@gszr gszr added this to the 2.4 milestone Mar 22, 2021
@gszr gszr force-pushed the feat/customize-logs branch 2 times, most recently from ef84f1e to 634eedd Compare March 22, 2021 15:56
@gszr gszr marked this pull request as ready for review March 22, 2021 16:09
@gszr gszr added pr/please review pr/ready (but hold merge) No more concerns, but do not merge yet (probably a conflict of interest with another PR or release) labels Mar 22, 2021
@gszr gszr force-pushed the feat/customize-logs branch 2 times, most recently from 5be62ec to 4a4982b Compare March 22, 2021 21:17
@gszr gszr changed the base branch from master to next March 22, 2021 21:17
@@ -69,6 +73,12 @@ local FileLogHandler = {


function FileLogHandler:log(conf)
if conf.custom_fields_by_lua then
for key, expression in pairs(conf.custom_fields_by_lua) do
Copy link
Member

Choose a reason for hiding this comment

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

Slight concern on this usage of pairs inside a hot path. It can not be JIT compiled by LuaJIT and may result in slow execution. Any chance pairs can be avoided here?

It's not a blocker for the PR, but just making a note here so we remember to look into it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I will look into this after the beta.

Copy link
Contributor

Choose a reason for hiding this comment

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

the pairs loop goes around a sandbox(expression, ...); i don't think it could be considered a tight loop.

tangentially related: pairs() isn't an NYI because it's too complex, but because the interpreted version is faster in most cases. the downside is that it breaks surrounding traces, which is bad if there's tight code with high interpretation penalty (like FFI). for "wide" loops it's ok, the result will be a few more chained sidetraces.

kong/plugins/file-log/handler.lua Outdated Show resolved Hide resolved
@gszr gszr removed the pr/ready (but hold merge) No more concerns, but do not merge yet (probably a conflict of interest with another PR or release) label Mar 23, 2021
Add capability to set new fields, or unset existing fields, by
executing custom Lua code. This feature uses the new PDK method
`kong.log.set_serialize_value`, introduced in Kong 2.3.
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.

None yet

4 participants