Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(prometheus): conflict between global rule and route configure #6579

Merged
merged 7 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
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",
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the nginx-lua-prometheus need update ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Does the nginx-lua-prometheus need update ?

No, APISIX from 2.7 to master, nginx-lua-prometheus has only one version upgrade, and this upgrade of nginx-lua-prometheus is not related to the current issue.

https://github.com/knyar/nginx-lua-prometheus/blob/master/CHANGELOG.md#020220127

}


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+/
62 changes: 62 additions & 0 deletions t/plugin/prometheus3.t
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,65 @@ 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
--- error_code: 200
Copy link
Member

Choose a reason for hiding this comment

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

The error_code check here is redundant?




=== 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/