Skip to content
Open
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
3 changes: 2 additions & 1 deletion prometheus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,8 @@ function Prometheus.init(dict_name, options_or_prefix)
self.initialized = true

self:counter(self.error_metric_name, "Number of nginx-lua-prometheus errors")
self.dict:set(self.error_metric_name, 0)
-- init runs in every init_worker, including a respawned worker's
self.dict:add(self.error_metric_name, 0)
local err = self.key_index:add(self.error_metric_name, ERR_MSG_LRU_EVICTION)
if err then
self:log_error(err)
Expand Down
5 changes: 5 additions & 0 deletions prometheus_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ function TestPrometheus:testInit()
luaunit.assertEquals(self.dict:get("nginx_metric_errors_total"), 0)
luaunit.assertEquals(ngx.logs, nil)
end
function TestPrometheus:testInitKeepsErrorCount()
self.dict:set("nginx_metric_errors_total", 3)
require('prometheus').init('metrics')
luaunit.assertEquals(self.dict:get("nginx_metric_errors_total"), 3)
end
function TestPrometheus:testInitOptions()
self.dict = setmetatable({}, SimpleDict)
ngx.shared.metrics = self.dict
Expand Down