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

bug: script does not work #3663

Closed
tzssangglass opened this issue Feb 24, 2021 · 7 comments · Fixed by #3678
Closed

bug: script does not work #3663

tzssangglass opened this issue Feb 24, 2021 · 7 comments · Fixed by #3678
Assignees

Comments

@tzssangglass
Copy link
Member

Issue description

I used the script, but the script did not execute, see the following test case

use t::APISIX 'no_plan';

repeat_each(1);
log_level('info');
no_long_string();
no_root_location();

run_tests;

__DATA__

=== TEST 1: add services
--- config
    location /t {
        content_by_lua_block {
            local t = require("lib.test_admin").test
            local code, body = t('/apisix/admin/services/1',
                 ngx.HTTP_PUT,
                 [[{
                    "name": "script_test",
                    "upstream": {
                        "nodes": {
                            "127.0.0.1:1980": 1
                        },
                        "type": "roundrobin"
                    }
                }]]
                )

            if code >= 300 then
                ngx.status = code
            end
            ngx.say(body)
        }
    }
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]



=== TEST 2: route binding service and route has script
--- config
    location /t {
        content_by_lua_block {
            local t = require("lib.test_admin").test
            local code, body = t('/apisix/admin/routes/1',
                 ngx.HTTP_PUT,
                 [[{
                    "service_id": 1,
                    "script": "local _M = {} \n function _M.access(api_ctx) \n ngx.log(ngx.INFO,\"hit access phase\") \n end \nreturn _M",
                    "uri": "/hello"
                }]]
                )

            if code >= 300 then
                ngx.status = code
            end
            ngx.say(body)
        }
    }
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]



=== TEST 3: hit route and trigger script
--- request
GET /hello
--- response_body
hello world
--- error_log eval
qr/loaded script_obj: \{"access":"function: 0x[\w]+"\}/

based on the documentation for the script, I think the script should be executed because it is bound to the route and neither the route nor the service has plugins configured

bugs may appear in

local function merge_service_route(service_conf, route_conf)

maybe this function should be preceded by code like this before return

    if route_conf.value.script then
        new_conf.value.script = route_conf.value.script
    end

Environment

  • apisix version (cmd: apisix version): greater than 2.2, less than 2.3
  • OS (cmd: uname -a): Centos 7
  • OpenResty / Nginx version (cmd: nginx -V or openresty -V): openresty/1.19.3.1
  • etcd version, if have (cmd: run curl http://127.0.0.1:9090/v1/server_info to get the info from server-info API): {"etcdserver":"3.4.13","etcdcluster":"3.4.0"}
  • apisix-dashboard version, if have:

Minimal test code / Steps to reproduce the issue

What's the actual result? (including assertion message & call stack if applicable)

What's the expected result?

@spacewander
Copy link
Member

PR is welcome!

@tzssangglass
Copy link
Member Author

tzssangglass commented Feb 25, 2021

PR is welcome!

assign to me

@tzssangglass
Copy link
Member Author

According to the script documentation, on the route, script and plugin are mutually exclusive, so if there is script on the route and plugins on the service, and the route is bound to the service, do you need to execute both script and plugins?

@spacewander
Copy link
Member

The route one is preferred.

@tzssangglass
Copy link
Member Author

There is such a case: route has a script, service has a plugin, route is bound to service, then the service's plugin needs to be executed?
@membphis

@membphis
Copy link
Member

There is such a case: route has a script, service has a plugin, route is bound to service, then the service's plugin needs to be executed?
@membphis

for your case, only script can be executed.

@tzssangglass
Copy link
Member Author

got

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

Successfully merging a pull request may close this issue.

3 participants