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

http-log plugin throws bad argument #4 to 'fmt' (number expected, got nil), context: ngx.timer #11931

Open
1 task done
philippsteinberg opened this issue Nov 6, 2023 · 12 comments

Comments

@philippsteinberg
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Kong version ($ kong version)

Kong 3.4

Current Behavior

Hi I try to send logs with the http-log plugin to an http endpoint via a post request.
To test the functionality I configured it liked described on the plugin docu page https://docs.konghq.com/hub/kong-inc/http-log/how-to/basic-example/ under Enable globally

plugins:
- name: http-log
  config:
    content_type: application/json
    http_endpoint: https://xxx
    method: POST
    flush_timeout: 2
    retry_count: 15
    timeout: 1000
    keepalive: 1000

When I start Kong with the config I see the following error in the logs:
[error] 2317#0: *13 [lua] job.lua:284: execute(): [timer-ng] failed to run timer queue 0dc6f45b-8f8d-40d2-a504-473544ee190b.https://xxx:POST:application/json:3000:60000:nil: ./http-log/handler.lua:135: bad argument #4 to 'fmt' (number expected, got nil), context: ngx.timer

After that I see no more logs from the plugin in the logs and no data is received at the endpoint

Expected Behavior

Plugin should work and send the request and response logs to the http endpoint

Steps To Reproduce

Configure the http-log plugin like described in the plugin page
https://docs.konghq.com/hub/kong-inc/http-log/how-to/basic-example/ under Enable globally

Anything else?

No response

@tzssangglass
Copy link
Member

[error] 2317#0: *13 [lua] job.lua:284: execute(): [timer-ng] failed to run timer queue 0dc6f45b-8f8d-40d2-a504-473544ee190b.https://xxx:POST:application/json:3000:60000:nil: ./http-log/handler.lua:135: bad argument #4 to 'fmt' (number expected, got nil), context: ngx.timer

looks like parsing your http_endpoint failed, can you show your http_endpoint?

@philippsteinberg
Copy link
Author

Here is the http_endpoint value. I try to send the data to logz.io
If I now see the issue it could be the : before the port that leads to the issue?

https://listener-eu.logz.io:8071?token=xxx&type=http-bulk

@tzssangglass tzssangglass self-assigned this Nov 7, 2023
@ghost ghost mentioned this issue Nov 7, 2023
3 tasks
@flrgh
Copy link
Contributor

flrgh commented Nov 7, 2023

Your endpoint has a query string but no path component. Instead of https://listener-eu.logz.io:8071?token=xxx&type=http-bulk, try https://listener-eu.logz.io:8071/?token=xxx&type=http-bulk.

@tzssangglass
Copy link
Member

I think we should fix url.parse

@tzssangglass
Copy link
Member

When I review the code of url.parse(), I found that it uses much string.gsub to do the regex match, so maybe we can choose or implate another function instead of url.parse()? cc @flrgh

@philippsteinberg
Copy link
Author

Your endpoint has a query string but no path component. Instead of https://listener-eu.logz.io:8071?token=xxx&type=http-bulk, try https://listener-eu.logz.io:8071/?token=xxx&type=http-bulk.

@flrgh Thanks for the hint this solved the issue for me.
Should I keep the issue open for tracking or should I close it?

@flrgh
Copy link
Contributor

flrgh commented Nov 8, 2023

Should I keep the issue open for tracking or should I close it?

I think we'll keep this open for tracking in case anyone else encounters this problem in the near future. Thank you for the report @philippsteinberg :)

@flrgh
Copy link
Contributor

flrgh commented Nov 8, 2023

When I review the code of url.parse(), I found that it uses much string.gsub to do the regex match, so maybe we can choose or implate another function instead of url.parse()? cc @flrgh

Agree, I think it can be improved. Ideally this work could be committed upstream to the luasocket project, but if we can't make it good enough without using OpenResty/LuaJIT features then maybe it can be a new function somewhere in the kong.tools.* namespace.

@tzssangglass
Copy link
Member

Agree, I think it can be improved. Ideally this work could be committed upstream to the luasocket project, but if we can't make it good enough without using OpenResty/LuaJIT features then maybe it can be a new function somewhere in the kong.tools.* namespace.

+1

@tzssangglass tzssangglass removed their assignment Nov 10, 2023
@chronolaw
Copy link
Contributor

@flrgh , should we create a internal ticket to track it? Perhaps in the future we will implement a function like you said.

@tzssangglass
Copy link
Member

tzssangglass commented Jan 17, 2024

upstream has fixed this by: lunarmodules/luasocket#418, but seems it has not released a new version containing this fix.

track this issue and try to implement a new function by KAG-3028

@the-erwin
Copy link

FYI, the same error is logged when there's authentication in the URL, the endpoint is Grafana Cloud:
"http_endpoint": "https://[number]:glc_[characters][email protected]/loki/api/v1/push",

All the best -Erwin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants