You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/07/14 03:57:01 UTC

[GitHub] [apisix] tzssangglass commented on a change in pull request #4549: feat: enable balancer phase for plugins

tzssangglass commented on a change in pull request #4549:
URL: https://github.com/apache/apisix/pull/4549#discussion_r669261787



##########
File path: t/plugin/serverless.t
##########
@@ -679,3 +679,159 @@ GET /hello
 --- error_log
 default phase: access
 match uri /hello
+
+
+
+=== TEST 23: run in the balancer phase
+--- 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,
+                 [[{
+                    "plugins": {
+                        "serverless-pre-function": {
+                            "phase": "balancer",
+                            "functions" : ["return function(conf, ctx) ngx.req.set_header('X-SERVERLESS', ctx.balancer_ip) end"]
+                        }
+                    },
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.2:1979": 100000,
+                            "127.0.0.1:1980": 1
+                        },
+                        "type": "chash",
+                        "key": "remote_addr"
+                    },
+                    "uri": "/log_request"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 24: check plugin
+--- request
+GET /log_request
+--- skip_nginx: 4: < 1.19.3
+--- grep_error_log eval
+qr/(proxy request to \S+|x-serverless: [\d.]+)/
+--- grep_error_log_out
+proxy request to 127.0.0.2:1979
+proxy request to 127.0.0.1:1980
+x-serverless: 127.0.0.1
+
+
+
+=== TEST 25: exit in the balancer phase
+--- 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,
+                 [[{
+                    "plugins": {
+                        "serverless-pre-function": {
+                            "phase": "balancer",
+                            "functions" : ["return function(conf, ctx) ngx.exit(403) end"]
+                        }
+                    },
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.2:1979": 100000,
+                            "127.0.0.1:1980": 1
+                        },
+                        "type": "chash",
+                        "key": "remote_addr"
+                    },
+                    "uri": "/log_request"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 26: check plugin
+--- request
+GET /log_request
+--- error_code: 403
+--- no_error_log
+[error]
+
+
+
+=== TEST 27: ensure balancer phase run correct time
+--- 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,
+                 [[{
+                    "plugins": {
+                        "serverless-pre-function": {
+                            "phase": "balancer",
+                            "functions" : ["return function(conf, ctx) ngx.log(ngx.WARN, 'run balancer phase with ', ctx.balancer_ip) end"]
+                        }
+                    },
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.2:1979": 100000,
+                            "127.0.0.1:1980": 1
+                        },
+                        "type": "chash",
+                        "key": "remote_addr"
+                    },
+                    "uri": "/log_request"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 28: check plugin
+--- request
+GET /log_request
+--- grep_error_log eval
+qr/(run balancer phase with [\d.]+)/
+--- grep_error_log_out
+run balancer phase with 127.0.0.2

Review comment:
       I don't understand why there are two `run balancer phases with ……`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org