Closed janosi closed 5 years ago
Please be aware, that from now on my plugin stopped working on the old Kong versions, too. Most probably there is a bug in my environment, please do not investigate this case until I find the cause. Of course, I will immediately inform you about the result. In case you want to close this issue before that, I can understand that and please do it at your will.
We can close this issue. For any reason, from one day to another, the behavior of my solution started working differently with any Kong version. So, I am sure the reason is on my side.
@janosi "ip": "127.0.0.1", "port": 18830 Hello, Could please you tell me if the port 18830 was configured in stream_listen before you post http://10.98.19.169:8001/routes/?
Summary
My custom plugin that worked with Kong 1.0.3 does not work with 1.1.1.
It is a TCP plugin, working at preread phase. With Kong 1.0.3 I configured the route, service and plugin as follows:
curl -i -X POST http://10.98.19.169:8001/services/ -d 'name=fakeservice' -d 'url=tcp://127.0.0.1:28830' curl -i -X POST http://10.98.19.169:8001/routes/ -H 'Content-Type: application/json' -d '{"destinations":[{"ip": "127.0.0.1", "port": 18830}], "protocols":["tcp"], "name": "myproxy", "service":{"id":"02a7b466-cf52-4f75-bb4c-6069e0590772"}}' curl -i -X POST --url http://10.98.19.169:8001/routes/cca79d57-4fb9-4dfa-b742-443cfba79ad9/plugins/ --data 'name=myplugin'
With Kong 1.1.1 I turned off the DB usage and I use the following declarative config:
services:
routes:
Everything else (/etc/kong/kong.conf, my plugin code, the location of my plugin) is the same.
Here I attach the printouts of the API queries on Kong 1.1.1:
curl -XGET 10.98.19.169:8001/plugins {"next":null,"data":[{"created_at":1554468514,"config":{},"id":"f8b1a119-662c-4869-b5b9-d244d7589221","service":null,"name":myplugin","tags":null,"consumer":null,"run_on":"first","protocols":["tcp"],"route":{"id":"395bc64f-0000-451a-9654-f9028efd2578"},"enabled":true}]}
curl -XGET /routes {"next":null,"data":[{"tags":null,"created_at":1554465925,"sources":null,"id":"395bc64f-0000-451a-9654-f9028efd2578","service":{"id":"b936e1d8-9d83-488e-b09b-eb07cd00dce2"},"name":"myproxy","snis":null,"paths":null,"preserve_host":false,"regex_priority":0,"hosts":null,"updated_at":1554465925,"destinations":[{"ip":"127.0.0.1","port":18830}],"methods":null,"protocols":["tcp"],"strip_path":true}]}
curl -XGET /services {"next":null,"data":[{"host":"127.0.0.1","created_at":1554465925,"connect_timeout":60000,"id":"b936e1d8-9d83-488e-b09b-eb07cd00dce2","protocol":"tcp","name":"fakeservice","read_timeout":60000,"port":28830,"path":null,"updated_at":1554465925,"tags":null,"write_timeout":60000,"retries":5}]}
When I connect to Kong on the port defined in the route, my plugin grabs the downstream socket with ngx.req.socket(true) and it sends an initial mesage on the connection to the client. This message does not arrive to the client with Kong 1.1.1.
With Kong 1.1.1 and the config above all I get in the logs is:
2019/04/05 12:05:39 [info] 45#0: 57 client 127.0.0.1:36806 connected to 0.0.0.0:18830 127.0.0.1 [05/Apr/2019:12:06:09 +0000] TCP 200 0 0 30.001 2019/04/05 12:06:09 [error] 45#0: 57 failed to run log_by_lua*: /usr/local/share/lua/5.1/kong/runloop/plugins_iterator.lua:82: attempt to index field 'configured_plugins' (a nil value) stack traceback: /usr/local/share/lua/5.1/kong/runloop/plugins_iterator.lua:82: in function '(for generator)' /usr/local/share/lua/5.1/kong/init.lua:805: in function 'log' log_by_lua(nginx-kong-stream.conf:68):2: in function <log_by_lua(nginx-kong-stream.conf:68):1> while prereading client data, client: 127.0.0.1, server: 0.0.0.0:18830
Nothing else is in the log (debug level used). The startup log shows that my plugin is loaded:
2019/04/05 12:05:25 [debug] 1#0: [lua] plugins.lua:209: load_plugin(): Loading plugin: myplugin 2019/04/05 12:05:26 [debug] 1#0: stream [lua] plugins.lua:209: load_plugin(): Loading plugin: myplugin 2019/04/05 12:05:26 [debug] 46#0: 2 [lua] base_plugin.lua:13: init_worker(): executing plugin "myplugin-plugin": init_worker 2019/04/05 12:05:26 [debug] 45#0: 1 [lua] base_plugin.lua:13: init_worker(): executing plugin "myplugin-plugin": init_worker 2019/04/05 12:05:26 [debug] 46#0: 3 stream [lua] base_plugin.lua:13: init_worker(): executing plugin "myplugin-plugin": init_worker 2019/04/05 12:05:26 [debug] 45#0: 4 stream [lua] base_plugin.lua:13: init_worker(): executing plugin "myplugin-plugin": init_worker
Kong config (GET :8001/):
{"plugins":{"enabled_in_cluster":["myplugin"],"available_on_server":{"correlation-id":true,"pre-function":true,"cors":true,"rate-limiting":true,"loggly":true,"hmac-auth":true,"zipkin":true,"myplugin":true,"bot-detection":true,"azure-functions":true,"request-transformer":true,"oauth2":true,"response-transformer":true,"ip-restriction":true,"statsd":true,"jwt":true,"basic-auth":true,"key-auth":true,"http-log":true,"datadog":true,"tcp-log":true,"post-function":true,"prometheus":true,"acl":true,"kubernetes-sidecar-injector":true,"request-size-limiting":true,"response-ratelimiting":true,"udp-log":true,"file-log":true,"aws-lambda":true,"syslog":true,"ldap-auth":true,"request-termination":true}},"tagline":"Welcome to kong","configuration":{"plugins":["bundled","myplugin"],"client_ssl":false,"proxy_access_log":"\/dev\/stdout","trusted_ips":{},"prefix":"\/usr\/local\/kong","loaded_plugins":{"correlation-id":true,"pre-function":true,"cors":true,"ldap-auth":true,"loggly":true,"hmac-auth":true,"zipkin":true,"myplugin":true,"request-size-limiting":true,"azure-functions":true,"request-transformer":true,"oauth2":true,"response-transformer":true,"syslog":true,"statsd":true,"jwt":true,"basic-auth":true,"key-auth":true,"http-log":true,"datadog":true,"tcp-log":true,"post-function":true,"ip-restriction":true,"acl":true,"kubernetes-sidecar-injector":true,"response-ratelimiting":true,"prometheus":true,"udp-log":true,"file-log":true,"aws-lambda":true,"bot-detection":true,"rate-limiting":true,"request-termination":true},"cassandra_username":"kong","ssl_cert_key":"\/usr\/local\/kong\/ssl\/kong-default.key","admin_ssl_cert_key":"\/usr\/local\/kong\/ssl\/admin-kong-default.key","dns_resolver":{},"pg_user":"kong","mem_cache_size":"128m","cassandra_data_centers":["dc1:2","dc2:3"],"nginx_admin_directives":{},"nginx_http_directives":[{"value":"prometheus_metrics 5m","name":"lua_shared_dict"}],"pg_host":"127.0.0.1","nginx_acc_logs":"\/usr\/local\/kong\/logs\/access.log","proxy_listen":["0.0.0.0:8000","0.0.0.0:8443 ssl"],"declarative_config":"\/tmp\/kong.yml","client_ssl_cert_default":"\/usr\/local\/kong\/ssl\/kong-default.crt","cassandra_ssl":false,"db_update_frequency":5,"db_update_propagation":0,"stream_listen":["0.0.0.0:18830","127.0.0.1:38830"],"nginx_err_logs":"\/usr\/local\/kong\/logs\/error.log","cassandra_port":9042,"dns_order":["LAST","SRV","A","CNAME"],"dns_error_ttl":1,"headers":["server_tokens","latency_tokens"],"cassandra_lb_policy":"RequestRoundRobin","nginx_sproxy_directives":{},"origins":{},"database":"off","pg_database":"kong","nginx_worker_processes":"auto","lua_package_cpath":"","admin_acc_logs":"\/usr\/local\/kong\/logs\/admin_access.log","lua_package_path":"\/usr\/local\/share\/lua\/5.1\/?.lua;.\/?.lua;.\/?\/init.lua;;","nginx_pid":"\/usr\/local\/kong\/pids\/nginx.pid","upstream_keepalive":60,"cassandra_contact_points":["kong-database"],"admin_ssl_cert":"\/usr\/local\/kong\/ssl\/admin-kong-default.crt","nginx_conf":"\/usr\/local\/kong\/nginx.conf","admin_access_log":"\/dev\/stdout","lua_socket_pool_size":30,"cassandra_repl_factor":1,"proxy_listeners":[{"transparent":false,"ssl":false,"ip":"0.0.0.0","proxy_protocol":false,"port":8000,"http2":false,"listener":"0.0.0.0:8000"},{"transparent":false,"ssl":true,"ip":"0.0.0.0","proxy_protocol":false,"port":8443,"http2":false,"listener":"0.0.0.0:8443 ssl"}],"proxy_ssl_enabled":true,"dns_stale_ttl":4,"admin_ssl_cert_default":"\/usr\/local\/kong\/ssl\/admin-kong-default.crt","enabled_headers":{"latency_tokens":true,"X-Kong-Proxy-Latency":true,"Via":true,"server_tokens":true,"Server":true,"X-Kong-Upstream-Latency":true,"X-Kong-Upstream-Status":false},"ssl_ciphers":"ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256","pg_timeout":5000,"db_resurrect_ttl":30,"admin_ssl_enabled":true,"cassandra_consistency":"ONE","db_cache_ttl":0,"admin_error_log":"\/dev\/stderr","pg_ssl_verify":false,"dns_not_found_ttl":30,"pg_ssl":false,"error_default_type":"text\/plain","client_max_body_size":"0","cassandra_repl_strategy":"SimpleStrategy","kong_env":"\/usr\/local\/kong\/.kong_env","log_level":"debug","ssl_cipher_suite":"modern","nginx_proxy_directives":{},"nginx_kong_conf":"\/usr\/local\/kong\/nginx-kong.conf","cassandra_schema_consensus_timeout":10000,"dns_hostsfile":"\/etc\/hosts","admin_listeners":[{"transparent":false,"ssl":false,"ip":"0.0.0.0","proxy_protocol":false,"port":8001,"http2":false,"listener":"0.0.0.0:8001"},{"transparent":false,"ssl":true,"ip":"0.0.0.0","proxy_protocol":false,"port":8444,"http2":false,"listener":"0.0.0.0:8444 ssl"}],"lua_ssl_verify_depth":1,"ssl_cert":"\/usr\/local\/kong\/ssl\/kong-default.crt","real_ip_header":"X-Real-IP","admin_ssl_cert_key_default":"\/usr\/local\/kong\/ssl\/admin-kong-default.key","cassandra_ssl_verify":false,"dns_no_sync":false,"cassandra_timeout":5000,"real_ip_recursive":"off","proxy_error_log":"\/dev\/stderr","client_ssl_cert_key_default":"\/usr\/local\/kong\/ssl\/kong-default.key","nginx_daemon":"off","anonymous_reports":true,"nginx_stream_directives":{},"stream_listeners":[{"transparent":false,"port":18830,"ip":"0.0.0.0","proxy_protocol":false,"listener":"0.0.0.0:18830"},{"transparent":false,"port":38830,"ip":"127.0.0.1","proxy_protocol":false,"listener":"127.0.0.1:38830"}],"pg_port":5432,"nginx_kong_stream_conf":"\/usr\/local\/kong\/nginx-kong-stream.conf","client_body_buffer_size":"8k","ssl_preread_enabled":true,"nginx_optimizations":true,"ssl_cert_csr_default":"\/usr\/local\/kong\/ssl\/kong-default.csr","cassandra_keyspace":"kong","ssl_cert_default":"\/usr\/local\/kong\/ssl\/kong-default.crt","ssl_cert_key_default":"\/usr\/local\/kong\/ssl\/kong-default.key","admin_listen":["0.0.0.0:8001","0.0.0.0:8444 ssl"]},"version":"1.1.1","node_id":"4b514f4b-9e13-4ad4-93d8-bf0f6e6ce149","lua_version":"LuaJIT 2.1.0-beta3","prng_seeds":{"pid: 45":190192872406,"pid: 44":127122351751,"pid: 1":536206215176},"timers":{"pending":3,"running":0},"hostname":"kong"}
Could you please advise?