Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apisix/plugins/prometheus/exporter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function _M.log(conf, ctx)

local overhead = latency
if ctx.var.upstream_response_time then
overhead = overhead - tonumber(ctx.var.upstream_response_time)
overhead = overhead - tonumber(ctx.var.upstream_response_time) * 1000
end
metrics.overhead:observe(overhead,
gen_arr("request", service_id, balancer_ip))
Expand Down
1 change: 0 additions & 1 deletion t/lib/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ function _M.hello1()
ngx.say("hello1 world")
end


function _M.server_port()
ngx.print(ngx.var.server_port)
end
Expand Down
129 changes: 129 additions & 0 deletions t/plugin/prometheus.t
Original file line number Diff line number Diff line change
Expand Up @@ -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]