Skip to content

Commit dfdfb02

Browse files
committed
chore(deps): upgrade nginx-lua-prometheus to 0.20220527
1 parent ffe5da5 commit dfdfb02

6 files changed

Lines changed: 61 additions & 31 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3232
- Bump pcre to pcre2 10.47 [PR #1577](https://github.com/3scale/APIcast/pull/1577) [THREESCALE-14541](https://redhat.atlassian.net/browse/THREESCALE-14541)
3333
- Bump zlib to 1.3.1 [PR #1577](https://github.com/3scale/APIcast/pull/1577) [THREESCALE-12242](https://redhat.atlassian.net/browse/THREESCALE-12242)
3434
- Bump liquid-lua to 0.2.1 [PR #1590](https://github.com/3scale/APIcast/pull/1590)
35+
- Bump nginx-lua-prometheus to 0.20220527 [PR #1591](https://github.com/3scale/APIcast/pull/1591)
3536

3637
### Removed
3738

gateway/Roverfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ lyaml 6.2.8-1||production
2727
markdown 0.33-1|8c09109924b218aaecbfd4d4b1de538269c4d765|development
2828
mediator_lua 1.1.2-0||testing
2929
net-url 1.1-1|32acd84d06e16ddffc975adafce9cea26f3b2dd1|testing
30-
nginx-lua-prometheus 0.20181120-3|379c0a4d4d6f3c5b0eb93691fc7e14fff498e1ca|production
30+
nginx-lua-prometheus 0.20220527-1||production
3131
penlight 1.15.0-1||testing,development,production
3232
router 2.1-0||production
3333
say 1.4.1-3|45a3057e68c52b34ab59ef167efeb2340e356661|testing

gateway/apicast-scm-1.rockspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ dependencies = {
2121
'liquid == 0.2.1',
2222
'argparse',
2323
'penlight == 1.15.0',
24-
'nginx-lua-prometheus == 0.20181120',
24+
'nginx-lua-prometheus == 0.20220527',
2525
'lua-resty-jit-uuid',
2626
'lua-resty-ipmatcher',
2727
'lua-resty-openssl == 1.7.1'

gateway/src/apicast/executor.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ do
121121
-- Need to seed the UUID in init_worker.
122122
-- Ref: https://github.com/thibaultcha/lua-resty-jit-uuid/blob/c4c0004da0c4c4cdd23644a5472ea5c0d18decbb/README.md#usage
123123
uuid.seed()
124+
prometheus.init_worker()
124125

125126
local executed = {}
126127

gateway/src/apicast/prometheus.lua

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
1-
local prometheus = require('nginx.prometheus')
21
local assert = assert
32
local dict = 'prometheus_metrics'
43

54
if ngx.shared[dict] then
6-
local init = prometheus.init(dict)
7-
85
local metrics = { }
6+
local prometheus = require('prometheus').init(dict)
7+
98
local __call = function(_, type, name, ...)
109
local metric_name = assert(name, 'missing metric name')
1110

1211
if not metrics[metric_name] then
13-
metrics[metric_name] = init[assert(type, 'missing metric type')](init, metric_name, ...)
12+
metrics[metric_name] = prometheus[assert(type, 'missing metric type')](prometheus, metric_name, ...)
1413
end
1514

1615
return metrics[metric_name]
1716
end
1817

19-
return setmetatable({ }, { __call = __call, __index = init })
18+
local function init_worker()
19+
prometheus:init_worker()
20+
end
21+
22+
local function collect()
23+
prometheus:collect()
24+
end
25+
26+
return setmetatable({
27+
init_worker = init_worker,
28+
collect = collect,
29+
}, { __call = __call})
2030
else
2131
local noop = function() end
22-
return setmetatable({ collect = noop }, { __call = noop })
32+
local noop_metric = { inc = noop, set = noop, observe = noop, del = noop, reset = noop }
33+
local __call = function() return noop_metric end
34+
return setmetatable({ collect = noop, init_worker = noop }, { __call = __call })
2335
end

spec/prometheus_spec.lua

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11

22
describe('prometheus', function()
3-
before_each(function() package.loaded['apicast.prometheus'] = nil end)
3+
before_each(function()
4+
package.loaded['apicast.prometheus'] = nil
5+
package.loaded['prometheus'] = nil
6+
end)
47

58
describe('shared dictionary is missing', function()
69
before_each(function() ngx.shared.prometheus_metrics = nil end)
710

811
it('can be called', function()
9-
assert.is_nil(require('apicast.prometheus')())
12+
local prom = require('apicast.prometheus')
13+
local metric = prom()
14+
assert.is_not_nil(metric)
15+
assert.is_function(metric.inc)
1016
end)
1117

1218
it('can be collected', function()
@@ -15,37 +21,47 @@ describe('prometheus', function()
1521
end)
1622

1723
describe('shared dictionary is there', function()
24+
local saved_get_phase
25+
1826
before_each(function()
1927
ngx.shared.prometheus_metrics = {
20-
set = function() end,
21-
get_keys = function() return {} end
28+
set = function() return true end,
29+
safe_set = function() return true end,
30+
safe_add = function() return true end,
31+
incr = function() return 0 end,
32+
get = function() end,
33+
delete = function() return true end,
34+
get_keys = function() return {} end,
2235
}
36+
saved_get_phase = ngx.get_phase
37+
ngx.get_phase = function() return 'init' end
2338
end)
2439

25-
local prometheus
26-
local Prometheus
27-
28-
before_each(function()
29-
prometheus = assert(require('apicast.prometheus'))
30-
Prometheus = getmetatable(prometheus).__index
40+
after_each(function()
41+
ngx.get_phase = saved_get_phase
3142
end)
3243

33-
for _,metric_type in pairs{ 'counter', 'gauge', 'histogram' } do
34-
describe(metric_type, function()
35-
it('can be called', function()
36-
stub(Prometheus, metric_type)
37-
38-
prometheus(metric_type, 'some_metric')
44+
it('returns a callable wrapper', function()
45+
local prometheus = assert(require('apicast.prometheus'))
46+
local metric = prometheus('counter', 'test_metric', 'A test counter')
47+
assert.is_not_nil(metric)
48+
end)
3949

40-
assert.stub(Prometheus[metric_type]).was.called_with(Prometheus, 'some_metric')
41-
end)
42-
end)
43-
end
50+
it('caches metrics by name', function()
51+
local prometheus = assert(require('apicast.prometheus'))
52+
local m1 = prometheus('counter', 'cached_metric', 'A counter')
53+
local m2 = prometheus('counter', 'cached_metric', 'A counter')
54+
assert.are.equal(m1, m2)
55+
end)
4456

57+
it('exposes collect', function()
58+
local prometheus = assert(require('apicast.prometheus'))
59+
assert.is_function(prometheus.collect)
60+
end)
4561

46-
it('can be collected', function()
47-
ngx.header = { }
48-
assert.is_nil(require('apicast.prometheus'):collect())
62+
it('exposes init_worker', function()
63+
local prometheus = assert(require('apicast.prometheus'))
64+
assert.is_function(prometheus.init_worker)
4965
end)
5066
end)
5167

0 commit comments

Comments
 (0)