Skip to content

Commit

Permalink
fix(prometheus): conflict between global rule and route configure (#6579
Browse files Browse the repository at this point in the history
)
  • Loading branch information
shuaijinchao authored Mar 15, 2022
1 parent 530fb4d commit 95439a2
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
1 change: 1 addition & 0 deletions apisix/plugins/prometheus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ local _M = {
name = plugin_name,
log = exporter.log,
schema = schema,
run_policy = "prefer_route",
}


Expand Down
2 changes: 1 addition & 1 deletion t/plugin/prometheus2.t
Original file line number Diff line number Diff line change
Expand Up @@ -924,4 +924,4 @@ GET /hello
--- request
GET /apisix/prometheus/metrics
--- response_body eval
qr/apisix_bandwidth\{type="egress",route="1",service="1",consumer="",node="127.0.0.1"\} \d+/
qr/apisix_bandwidth\{type="egress",route="1",service="service_name",consumer="",node="127.0.0.1"\} \d+/
61 changes: 61 additions & 0 deletions t/plugin/prometheus3.t
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,64 @@ plugins:
}
--- response_body_like eval
qr/apisix_batch_process_entries\{name="http logger",route_id="1",server_addr="127.0.0.1"\} \d+/
=== TEST 5: set prometheus plugin at both global rule and route
--- 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": {}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"uri": "/opentracing"
}]]
)
if code >= 300 then
ngx.status = code
return
end
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/global_rules/1',
ngx.HTTP_PUT,
[[{
"plugins": {
"prometheus": {}
}
}]]
)
if code >= 300 then
ngx.status = code
return
end
ngx.say(body)
}
}
--- response_body
passed
=== TEST 6: test prometheus plugin at both global rule and route
--- request
GET /opentracing
--- response_body
opentracing
=== TEST 7: fetch prometheus plugin at both global rule and route data
--- request
GET /apisix/prometheus/metrics
--- response_body eval
qr/apisix_http_status\{code="200",route="1",matched_uri="\/opentracing",matched_host="",service="",consumer="",node="127.0.0.1\"} 1/

0 comments on commit 95439a2

Please sign in to comment.