diff --git a/t/lib/server.lua b/t/lib/server.lua index fe82408f4051..e34602c30234 100644 --- a/t/lib/server.lua +++ b/t/lib/server.lua @@ -28,7 +28,6 @@ function _M.hello1() ngx.say("hello1 world") end - function _M.server_port() ngx.print(ngx.var.server_port) end diff --git a/t/plugin/prometheus.t b/t/plugin/prometheus.t index a5f28f9c2007..4e99b84d4a95 100644 --- a/t/plugin/prometheus.t +++ b/t/plugin/prometheus.t @@ -534,3 +534,132 @@ GET /apisix/prometheus/metrics qr/.*apisix_http_overhead_bucket.*/ --- no_error_log [error] + + + +=== TEST 26: add service 3 to distinguish other services +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/services/3', + ngx.HTTP_PUT, + [[{ + "plugins": { + "prometheus": {} + }, + "upstream": { + "nodes": { + "127.0.0.1:1981": 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 27: add a route 4 to redirect /sleep1 +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/routes/4', + ngx.HTTP_PUT, + [[{ + "service_id": 3, + "uri": "/sleep1" + }]] + ) + + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } + } +--- request +GET /t +--- response_body +passed +--- no_error_log +[error] + + + +=== TEST 28: request from client to /sleep1 ( all hit) +--- pipelined_requests eval +["GET /sleep1", "GET /sleep1", "GET /sleep1"] +--- error_code eval +[200, 200, 200] +--- no_error_log +[error] + + + +=== TEST 29: fetch the prometheus metric data with `overhead`(the overhead < 1s) +--- request +GET /apisix/prometheus/metrics +--- response_body eval +qr/apisix_http_overhead_bucket.*service=\"3\".*le=\"00500.0.*/ +--- no_error_log +[error] + + + +=== TEST 30: delete route 4 +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/routes/4', + ngx.HTTP_DELETE + ) + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } + } +--- request +GET /t +--- response_body +passed +--- no_error_log +[error] + + + +=== TEST 31: delete service 3 +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/services/3', + ngx.HTTP_DELETE + ) + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } + } +--- request +GET /t +--- response_body +passed +--- no_error_log +[error]