Kong / Kong/kong-python-pdk

Possibly malformed event payload

Open
#136 2 comments 0 reactions 1 assignee Claimed by @nowNick View on GitHub
bug
Dominant language
Python
Stars
48
Forks
16
PR merge metrics
No merged PRs in 30d

Description

Hiya,

I'm running into a sporadic issue with a custom Python plugin. Occasionally, it looks like the plugin server receives a malformed event to handle.

Kong Gateway: 3.3.0
Python-pdk: 0.36
Kong Ingress Controller: 2.10
Proxy env vars:
```
...
KONG_PLUGINS : bundled,my-plugin
KONG_PLUGINSERVER_MY_PLUGIN_QUERY_CMD : /home/kong/plugins/python/my_plugin.py -p /kong-prefix/ -d
KONG_PLUGINSERVER_MY_PLUGIN_SOCKET : /kong-prefix/my-plugin.sock
KONG_PLUGINSERVER_MY_PLUGIN_START_CMD : /home/kong/plugins/python/my_plugin.py -p /kong-prefix/ --no-lua-style -g
KONG_PREFIX : /kong-prefix/
...
```
Logs:
```
2023/10/26 18:08:35 [info] 2375#0: *311 [my-plugin:2377] INFO - [02:08:35] instance #1259 of my-plugin started, context: ngx.timer
2023/10/26 18:08:35 [info] 2375#0: *311 [my-plugin:2377] INFO - [02:08:35] instance #1260 of my-plugin started, context: ngx.timer
2023/10/26 18:08:35 [info] 2375#0: *311 [my-plugin:2377] ERROR - [02:08:35] rpc: #6285 exception: Traceback (most recent call last):, context: ngx.timer
2023/10/26 18:08:35 [info] 2375#0: *311 [my-plugin:2377] File "/usr/local/lib/python3.10/dist-packages/kong_pdk/listener.py", line 68, in handle, context: ngx.timer
2023/10/26 18:08:35 [info] 2375#0: *311 [my-plugin:2377] ret = getattr(self.ps, cmd_r)(*args), context: ngx.timer
2023/10/26 18:08:35 [info] 2375#0: *311 [my-plugin:2377] File "/usr/local/lib/python3.10/dist-packages/kong_pdk/server.py", line 54, in wrapper, context: ngx.timer
2023/10/26 18:08:35 [info] 2375#0: *311 [my-plugin:2377] raise ex, context: ngx.timer
2023/10/26 18:08:35 [info] 2375#0: *311 [my-plugin:2377] File "/usr/local/lib/python3.10/dist-packages/kong_pdk/server.py", line 51, in wrapper, context: ngx.timer
2023/10/26 18:08:35 [info] 2375#0: *311 [my-plugin:2377] r = fn(*args, **kwargs), context: ngx.timer
2023/10/26 18:08:35 [info] 2375#0: *311 [my-plugin:2377] File "/usr/local/lib/python3.10/dist-packages/kong_pdk/server.py", line 278, in handle_event, context: ngx.timer
2023/10/26 18:08:35 [info] 2375#0: *311 [my-plugin:2377] iid = event['InstanceId'], context: ngx.timer
2023/10/26 18:08:35 [info] 2375#0: *311 [my-plugin:2377] KeyError: 'InstanceId', context: ngx.timer
2023/10/26 18:08:35 [error] 2375#0: *188104 [kong] mp_rpc.lua:354 [my-plugin] 'InstanceId', client: 10.0.131.51, server: kong, request: "GET /foo HTTP/1.1", host: "bar"
```

The `KeyError: 'InstanceId'` makes me think that the error is from https://github.com/Kong/kong-python-pdk/blob/master/kong_pdk/server.py#L278, and that the `event` argument is sometimes malformed.

Any ideas? Please and thank you!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.