go-pdk icon indicating copy to clipboard operation
go-pdk copied to clipboard

Impossible to access kong.Router.GetService() from Log phase.

Open arubia opened this issue 2 years ago • 5 comments

kong 2.8.0 go-pdk v0.7.1

For the moment only it is possible to get kong.Router.GetService() information from Access phase and not from the Log phase. Is a possible bug of kong, because the documentation explains that is possible to get this information from the Log phase: https://docs.konghq.com/gateway/latest/pdk/kong.router/#kongrouterget_service

Any idea if this is a bug?

arubia avatar Jul 01 '22 15:07 arubia

I'm facing the exactly same problem when trying to access lots of methods from kong.Request in the log phase. I keep getting the error api disabled in the current context even though the data should be accessible according to Kong and NGINX docs

edjanmichiles-toast avatar Aug 18 '23 11:08 edjanmichiles-toast

Passing by to comment that it is still the case. For instance it fails for kong.Request on :

  • GetPath
  • GetMethod
  • GetQuery
  • ...

For some reason I tried to port a lua version to a Go version and everything that worked on the log phase about the request failed. The Response access seems to work as expected though.

Quick investigations about this error message lead me here : https://github.com/Kong/kong/blob/master/build/openresty/patches/ngx_lua-0.10.26_01-dyn_upstream_keepalive.patch#L1031-L1034 so I guess it's because the lua context is not matching the Go context (or something like this) ?

ImFlog avatar Feb 07 '24 16:02 ImFlog

This is a known limitation; Kong communicates with the plugin server through a Unix domain socket. The socket API we use for that is not available in the context where we run the Go plugin log handler (it is actually in the context of a timer). I will tag this one as an enhancement request for now. Thank you for the discussion over here!

gszr avatar Feb 22 '24 00:02 gszr

@gszr it would be great to add a disclaimer in the docs for this to let people know of this limitation. Specially because it's not only the .GetService() that doesn't work

edjanmichiles-toast avatar Feb 22 '24 10:02 edjanmichiles-toast

@edjanmichiles-toast Good call - we will work on that.

gszr avatar Feb 22 '24 14:02 gszr

Hey, I'm facing the same issue here using the latest go-pdk version (0.11.0). Is there any news on this topic? Also, no document update was made as far as I can tell, right?

garciasdos avatar Oct 04 '24 08:10 garciasdos