Kong/kong-python-pdk

kong no data error while enabling the plugin

Closed this issue · 11 comments

I was trying to run the example py-hello plugin. I have already installed kong-pdk inside the kong image. After enabling the plugin I am getting the following error and all the requests are getting stuck.

2021/08/18 09:30:18 [error] 23#0: *14840 [kong] mp_rpc.lua:308 [py_hello] no data, client: 172.22.0.1, server: kong, request: "GET /my-app/ HTTP/1.1", host: "localhost:8000"

config:

plugins = bundled,py_hello
pluginserver_names = python
pluginserver_python_socket = /usr/local/kong/python_pluginserver.sock
pluginserver_python_start_cmd = /usr/local/bin/kong-python-pluginserver -d /usr/local/kong/python-plugins
pluginserver_python_query_cmd = /usr/local/bin/kong-python-pluginserver -d /usr/local/kong/python-plugins --dump-all-plugins

py-hello plugin is placed in /usr/local/kong/python-plugins directory
kong-python-pluginserver is available at path /usr/local/bin/kong-python-pluginserver

@abhisheksharma2805 Could you turn on debug logging in Kong for collecting more avaiable info?

@fffonion I tried running this with version 0.27, 0.26 and 0.24. Surprisingly the plugin is working for version 0.24. I have attached the log files for 0.27 and 0.24. I have also added some logs in the plugin which you can see in 0.24 log file at the end, which indicates the plugin is being initiated and called correctly.

kong_logs_pdk_0.24.txt
kong_logs_pdk_0.27.txt

Hi @abhisheksharma2805

Would you please:

  • check sock file name created in /usr/local/kong an compare with socket name set in your kong configuration file
  • increase verbose logging level
  • try to start your plugin manually directly from the shell (kong-python-pluginserver --socker-name XXXX --d XXX --dump-all-plugins -vvv .... )
  • try to test your configuration with the default py-hello plugin

Kind regards,
Mateusz

@mpromny Thanks for the suggestions. I have tried all the steps but still no luck.
I am using latest kong (2.5.0) with pdk 0.27 and python 3.6.8.

Custom kong image:

FROM kong:2.5.0
USER root
RUN apk update && apk add libffi-dev gcc g++ make musl-dev openldap-dev libressl-dev openssl lapack-dev openblas-dev libxml2-dev libxslt-dev postgresql-dev
RUN wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz
RUN tar -xvzf Python-3.6.8.tgz
WORKDIR Python-3.6.8
RUN ./configure
RUN make && make install
RUN ln -sf /usr/local/bin/python3.6 /usr/bin/python && ln -sf /usr/local/bin/pip3.6 /usr/bin/pip
RUN pip install --upgrade pip
# install external requirements - pip install -r requirements.txt
RUN pip install kong-pdk==0.27
COPY python-plugins/. /usr/local/kong/python-plugins
USER kong
WORKDIR /   

Kong configuration

plugins = bundled,py-hello
pluginserver_names = py
pluginserver_py_socket=/usr/local/kong/python_pluginserver.sock
pluginserver_py_start_cmd=/usr/local/bin/kong-python-pluginserver -d /usr/local/kong/python-plugins
pluginserver_py_query_cmd=/usr/local/bin/kong-python-pluginserver -d /usr/local/kong/python-plugins --dump-all-plugins

This same image and configuration works if I use kong-pdk==0.25

@abhisheksharma2805
I understand that it works with 0.25. Therefore I asked you to do the following steps:

  • check sock file name created in /usr/local/kong an compare with socket name set in your kong configuration file
    -- please start the service and past output from ls -al /usr/local/kong/python*
  • increase verbose logging level
    -- Have you done that (based on the posted configuration I don't think it has been done. -vvv parameter is missing)?
  • try to start your plugin manually directly from the shell (kong-python-pluginserver --socker-name XXXX --d XXX --dump-all-plugins -vvv .... )
    -- were you able to start python server from the shell? Is it working?
  • try to test your configuration with the default py-hello plugin
    -- Have you tried this approach? Have you updated the py-hello plugin?

@mpromny @fffonion Yes I have tried all the steps:

I am only trying to run the py-hello plugin as of now

  • socket filename is same as written in the config file - python_pluginserver.sock
  • I have set log_level=debug
  • I tried starting the plugin manually from the shell inside the container:
    kong-python-pluginserver -v --socket-name  pp.sock -d /usr/local/kong/python-plugins --dump-all-plugins
    
    This gave the following output but I cannot find the socket file pp.sock and I cannot see the plugin in the enabled list :
  DEBG - [22:18:17] loaded plugin "py-hello" from /usr/local/kong/python-plugins/py-hello.py
  [{"Name": "py-hello", "Phases": ["access"], "Priority": 0, "Schema": {"name": "py-hello", "fields": [{"config": {"type":
  "record", "fields": [{"message": {"type": "string"}}]}}]}}]
  • I also tried running the plugin inside the embedded server with the following configuration but still getting the no data error:
plugins = bundled,py-hello
pluginserver_names = py-hello
pluginserver_py_hello_socket=/usr/local/kong/py-hello.sock
pluginserver_py_hello_start_cmd=/usr/local/kong/python-plugins/py-hello.py
pluginserver_py_hello_query_cmd=/usr/local/kong/python-plugins/py-hello.py -d

@abhisheksharma2805
Thank you, got it.

Please set log_level=debug add and add -vvv to the configuration.

EDITED - I made a typo ( -vvv has been removed from pluginserver_py_query_cmd)

pluginserver_py_start_cmd= ...  -vvv
pluginserver_py_query_cmd= ... -d

Have you noticed anything in the log file?

Please verify whether py-server/py-hello works if you set:

def access(self, kong: kong):

instead of

def access(self, kong: kong.kong):
  1. If I enable -v option like this:
pluginserver_py_start_cmd=/usr/local/bin/kong-python-pluginserver -v -d /usr/local/kong/python-plugins
pluginserver_py_query_cmd=/usr/local/bin/kong-python-pluginserver -v -d /usr/local/kong/python-plugins --dump-all-plugins

I get the following error for both pdk 0.25 and 0.27

kong_1            | 2021/08/23 15:27:47 [debug] 1#0: [kong] process.lua:62 search config for pluginserver named: py
kong_1            | 2021/08/23 15:27:47 [error] 1#0: init_by_lua error: ...al/share/lua/5.1/kong/runloop/plugin_servers/process.lua:159: Not a plugin info table: 
kong_1            | /usr/local/bin/kong-python-pluginserver -v -d /usr/local/kong/python-plugins --dump-all-plugins
kong_1            | DEBG - [23:27:47] loaded plugin "py-hello" from /usr/local/kong/python-plugins/py-hello.py
kong_1            | [{"Name": "py-hello", "Phases": ["access"], "Priority": 0, "Schema": {"name": "py-hello", "fields": [{"config": {"type": "record", "fields": [{"message": {"type": "string"}}]}}]}}]
kong_1            | stack traceback:
kong_1            | 	[C]: in function 'error'
kong_1            | 	...al/share/lua/5.1/kong/runloop/plugin_servers/process.lua:159: in function 'ask_info'
kong_1            | 	...al/share/lua/5.1/kong/runloop/plugin_servers/process.lua:195: in function 'get_plugin_info'
kong_1            | 	...local/share/lua/5.1/kong/runloop/plugin_servers/init.lua:262: in function 'get_plugin'
kong_1            | 	...local/share/lua/5.1/kong/runloop/plugin_servers/init.lua:270: in function 'load_plugin'
kong_1            | 	/usr/local/share/lua/5.1/kong/db/dao/plugins.lua:136: in function 'load_plugin_handler'
kong_1            | 	/usr/local/share/lua/5.1/kong/db/dao/plugins.lua:221: in function 'load_plugin'
kong_1            | 	/usr/local/share/lua/5.1/kong/db/dao/plugins.lua:273: in function 'load_plugin_schemas'
kong_1            | 	/usr/local/share/lua/5.1/kong/init.lua:515: in function 'init'
kong_1            | 	init_by_lua:3: in main chunk
kong_1            | nginx: [error] init_by_lua error: ...al/share/lua/5.1/kong/runloop/plugin_servers/process.lua:159: Not a plugin info table: 
kong_1            | /usr/local/bin/kong-python-pluginserver -v -d /usr/local/kong/python-plugins --dump-all-plugins
kong_1            | DEBG - [23:27:47] loaded plugin "py-hello" from /usr/local/kong/python-plugins/py-hello.py
kong_1            | [{"Name": "py-hello", "Phases": ["access"], "Priority": 0, "Schema": {"name": "py-hello", "fields": [{"config": {"type": "record", "fields": [{"message": {"type": "string"}}]}}]}}]
  1. This works for both v0.25 and v0.27
    def access(self, kong: kong):
    but still getting the error in v0.27.
2021/08/23 15:25:58 [error] 25#0: *202 [kong] mp_rpc.lua:308 [py-hello] no data, client: 172.20.0.1, server: kong, request: "GET /my-app HTTP/1.1", host: "localhost:8000"

In v0.27, error is being thrown even before the constructor is called

@abhisheksharma2805

1)Sorry, I made a typo:

Please try this configuration:

  plugins: bundled, py-hello
  pluginserver_names: py
  pluginserver_py_socket: /usr/local/kong/python_pluginserver.sock
  pluginserver_py_start_cmd: /usr/local/bin/kong-python-pluginserver -p /usr/local/kong/ -d /scripts/directory -vvv
  pluginserver_py_query_cmd: /usr/local/bin/kong-python-pluginserver -p /usr/local/kong/ --dump-all-plugins -d /scripts/directory
  1. I cannot duplicate your error but I'm using different custom image. Kong 2.5 has been used as a base image but I've installed different packages and I have Python 3.8.

  2. To test whether you are able to start py-server manually, please execute the following commands:

/usr/local/bin/kong-python-pluginserver -p /usr/local/kong/ -d /scripts/directory -vvv &
/usr/local/bin/kong-python-pluginserver -p /usr/local/kong/ --dump-all-plugins -d /scripts/directory

This is interesting, @abhisheksharma2805 do you have any other (Lua) plugin on this route?
Just to verifying: does it work with stock python comes with alpine (apk add python3 py3-pip)?

Closing for inactivity, please re-open if necessary ; )