Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions t/lib/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ function _M.hello1()
ngx.say("hello1 world")
end

-- mock server for test the fix of overhead's value
function _M.hello4()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ngx.sleep(1)
ngx.say("hello4 world")
end

function _M.server_port()
ngx.print(ngx.var.server_port)
Expand Down
78 changes: 77 additions & 1 deletion t/plugin/prometheus.t
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ GET /t
{"error_msg":"failed to check the configuration of plugin prometheus err: additional properties forbidden, found invalid_property"}
--- no_error_log
[error]

---
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be useless, we can delete this line



=== TEST 10: set it in service (with wrong property)
Expand Down Expand Up @@ -534,3 +534,79 @@ 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 /hello4
--- 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": "/hello4"
}]]
)

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 /hello4 ( all hit, the hello4 sleep 1s)
--- pipelined_requests eval
["GET /hello4", "GET /hello4", "GET /hello4"]
--- 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]