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 2 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: 2 additions & 0 deletions apisix/plugins/prometheus/exporter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ function _M.log(conf, ctx)

metrics.bandwidth:inc(vars.bytes_sent,
gen_arr("egress", route_id, service_id, consumer_name, balancer_ip))

core.log.info("prometheus run report")
Copy link
Member

Choose a reason for hiding this comment

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

Can we check the result of prometheus instead of adding a new log just for testing?

Copy link
Member Author

Choose a reason for hiding this comment

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

this is not just for testing purposes. Currently, there is no log output when prometheus reports data. I think adding this log will also help developers watch it while developing and debugging.

what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

A hit will increase the metric:

metrics.status:inc(1,

There is no need to add another way.

end


Expand Down
57 changes: 57 additions & 0 deletions t/plugin/prometheus3.t
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,60 @@ 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
--- grep_error_log eval
qr/prometheus run \w+/
--- grep_error_log_out
prometheus run report