Skip to content

Commit

Permalink
Fix API errors
Browse files Browse the repository at this point in the history
  • Loading branch information
yciabaud committed May 16, 2018
1 parent 5c8a546 commit bb7293b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 1 addition & 2 deletions api.lua
Expand Up @@ -16,8 +16,7 @@ return {
logger:logAdmin(plugin.config) logger:logAdmin(plugin.config)
end end


logger:collect() return logger:collect()
helpers.responses.send_HTTP_OK()
end end
} }
} }
8 changes: 8 additions & 0 deletions prometheus.lua
Expand Up @@ -39,6 +39,8 @@
-- https://github.com/knyar/nginx-lua-prometheus -- https://github.com/knyar/nginx-lua-prometheus
-- Released under MIT license. -- Released under MIT license.


local ngx_log = ngx.log
local NGX_ERR = ngx.ERR


-- Default set of latency buckets, 5ms to 10s: -- Default set of latency buckets, 5ms to 10s:
local DEFAULT_BUCKETS = {0.005, 0.01, 0.02, 0.03, 0.05, 0.075, 0.1, 0.2, 0.3, local DEFAULT_BUCKETS = {0.005, 0.01, 0.02, 0.03, 0.05, 0.075, 0.1, 0.2, 0.3,
Expand Down Expand Up @@ -268,6 +270,10 @@ end
function Prometheus.init(dict_name, prefix) function Prometheus.init(dict_name, prefix)
local self = setmetatable({}, Prometheus) local self = setmetatable({}, Prometheus)
self.dict = ngx.shared[dict_name or "kong_cache"] self.dict = ngx.shared[dict_name or "kong_cache"]
if self.dict == nil then
ngx_log(NGX_ERR, string.format("Prometheus: dictionary %s not available", dict_name or "kong_cache"))
return
end
self.help = {} self.help = {}
if prefix then if prefix then
self.prefix = prefix self.prefix = prefix
Expand Down Expand Up @@ -494,6 +500,7 @@ end
-- It will get the metrics from the dictionary, sort them, and expose them -- It will get the metrics from the dictionary, sort them, and expose them
-- aling with TYPE and HELP comments. -- aling with TYPE and HELP comments.
function Prometheus:collect() function Prometheus:collect()
ngx.status = 200
ngx.header.content_type = "text/plain" ngx.header.content_type = "text/plain"
if not self.initialized then if not self.initialized then
ngx.log(ngx.ERR, "Prometheus module has not been initialized") ngx.log(ngx.ERR, "Prometheus module has not been initialized")
Expand Down Expand Up @@ -528,6 +535,7 @@ function Prometheus:collect()
end end
end end
end end
return ngx.exit(200)
end end


return Prometheus return Prometheus

0 comments on commit bb7293b

Please sign in to comment.