You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by me...@apache.org on 2020/02/27 08:15:06 UTC

[incubator-apisix] branch master updated: bugfix(prometheus): the balancer IP may be nil, use an empty string i… (#1166)

This is an automated email from the ASF dual-hosted git repository.

membphis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 0ee3c4b  bugfix(prometheus): the balancer IP may be nil, use an empty string i… (#1166)
0ee3c4b is described below

commit 0ee3c4be0e4616dcf10e8c0f6a68a74795879fea
Author: YuanSheng Wang <me...@gmail.com>
AuthorDate: Thu Feb 27 16:14:56 2020 +0800

    bugfix(prometheus): the balancer IP may be nil, use an empty string i… (#1166)
    
    * bugfix(prometheus): the balancer IP may be nil, use an empty string instead.
---
 lua/apisix/plugins/prometheus.lua          |  2 +-
 lua/apisix/plugins/prometheus/exporter.lua |  2 +-
 t/plugin/grpc-transcode.t                  |  2 --
 t/plugin/prometheus.t                      | 46 ++++++++++++++++++++++++++++++
 4 files changed, 48 insertions(+), 4 deletions(-)

diff --git a/lua/apisix/plugins/prometheus.lua b/lua/apisix/plugins/prometheus.lua
index d5f5cde..b87741a 100644
--- a/lua/apisix/plugins/prometheus.lua
+++ b/lua/apisix/plugins/prometheus.lua
@@ -26,7 +26,7 @@ local schema = {
 
 
 local _M = {
-    version = 0.1,
+    version = 0.2,
     priority = 500,
     name = plugin_name,
     init = exporter.init,
diff --git a/lua/apisix/plugins/prometheus/exporter.lua b/lua/apisix/plugins/prometheus/exporter.lua
index 81ff31e..06243f8 100644
--- a/lua/apisix/plugins/prometheus/exporter.lua
+++ b/lua/apisix/plugins/prometheus/exporter.lua
@@ -63,7 +63,7 @@ function _M.log(conf, ctx)
     local vars = ctx.var
 
     local route_id = ""
-    local balancer_ip = ctx.balancer_ip
+    local balancer_ip = ctx.balancer_ip or ""
     local service_id
 
     local matched_route = ctx.matched_route and ctx.matched_route.value
diff --git a/t/plugin/grpc-transcode.t b/t/plugin/grpc-transcode.t
index f778cc1..807305c 100644
--- a/t/plugin/grpc-transcode.t
+++ b/t/plugin/grpc-transcode.t
@@ -427,5 +427,3 @@ passed
 --- request
 GET /grpc_delay?name=apisix
 --- error_code: 504
-
-
diff --git a/t/plugin/prometheus.t b/t/plugin/prometheus.t
index 18fa3ed..52e55ee 100644
--- a/t/plugin/prometheus.t
+++ b/t/plugin/prometheus.t
@@ -413,3 +413,49 @@ GET /t
 passed
 --- no_error_log
 [error]
+
+
+
+=== TEST 20: set it in route with plugin `fault-injection`
+--- 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": {
+                        "prometheus": {},
+                        "fault-injection": {
+                            "abort": {
+                               "http_status": 200,
+                               "body": "Fault Injection!"
+                            }
+                        }
+                    },
+                    "uri": "/hello"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 21: pipeline of client request
+--- pipelined_requests eval
+["GET /hello", "GET /not_found", "GET /hello", "GET /hello"]
+--- error_code eval
+[200, 404, 200, 200]
+--- no_error_log
+[error]