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

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


The following commit(s) were added to refs/heads/master by this push:
     new 8d860ec  fix: when route name is not set, it would be given the 
service name (#4020)
8d860ec is described below

commit 8d860ec675713e96228620f44376584d1db5e97f
Author: Shuyang Wu <[email protected]>
AuthorDate: Tue Apr 13 16:05:14 2021 +0800

    fix: when route name is not set, it would be given the service name (#4020)
---
 apisix/plugin.lua      |  2 ++
 t/plugin/prometheus2.t | 75 ++++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 75 insertions(+), 2 deletions(-)

diff --git a/apisix/plugin.lua b/apisix/plugin.lua
index 8af3dd7..835c2bb 100644
--- a/apisix/plugin.lua
+++ b/apisix/plugin.lua
@@ -416,6 +416,8 @@ local function merge_service_route(service_conf, route_conf)
 
     if route_conf.value.name then
         new_conf.value.name = route_conf.value.name
+    else
+        new_conf.value.name = nil
     end
 
     -- core.log.info("merged conf : ", core.json.delay_encode(new_conf))
diff --git a/t/plugin/prometheus2.t b/t/plugin/prometheus2.t
index 5437485..5749f2f 100644
--- a/t/plugin/prometheus2.t
+++ b/t/plugin/prometheus2.t
@@ -803,7 +803,7 @@ 
qr/apisix_bandwidth\{type="egress",route="route_name",service="service_name",con
 
 
 
-=== TEST 40: remove service name
+=== TEST 40: set route name but remove service name
 --- config
     location /t {
         content_by_lua_block {
@@ -854,11 +854,29 @@ 
qr/apisix_bandwidth\{type="egress",route="route_name",service="1",consumer="",no
 
 
 
-=== TEST 43: remove route name, but still set prefer_name to name
+=== TEST 43: set service name but remove route name
 --- 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": "service_name",
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:1980": 1
+                        },
+                        "type": "roundrobin"
+                    }
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+
             local code, body = t('/apisix/admin/routes/1',
                 ngx.HTTP_PUT,
                 [[{
@@ -882,6 +900,7 @@ 
qr/apisix_bandwidth\{type="egress",route="route_name",service="1",consumer="",no
 GET /t
 --- response_body
 passed
+passed
 --- no_error_log
 [error]
 
@@ -900,6 +919,58 @@ GET /hello
 --- request
 GET /apisix/prometheus/metrics
 --- response_body eval
+qr/apisix_bandwidth\{type="egress",route="1",service="service_name",consumer="",node="127.0.0.1"\}
 \d+/
+--- no_error_log
+[error]
+
+
+
+=== TEST 46: remove both name, but still set prefer_name to true
+--- 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,
+                    "plugins": {
+                        "prometheus": {
+                            "prefer_name": true
+                        }
+                    },
+                    "uri": "/hello"
+                }]]
+            )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 47: pipeline of client request
+--- request
+GET /hello
+--- error_code: 200
+--- no_error_log
+[error]
+
+
+
+=== TEST 48: fetch the prometheus metric data
+--- request
+GET /apisix/prometheus/metrics
+--- response_body eval
 
qr/apisix_bandwidth\{type="egress",route="1",service="1",consumer="",node="127.0.0.1"\}
 \d+/
 --- no_error_log
 [error]

Reply via email to