Skip to content

Don't reset collectors when Cartridge roles hot reload #341

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

Merged
merged 5 commits into from
Jan 24, 2022
Merged
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: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
- Don't reset collectors when Cartridge roles hot reload

### Deprecated

- Metrics:
Expand Down
5 changes: 5 additions & 0 deletions metrics/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ if not registry then
end
rawset(_G, '__metrics_registry', registry)

local hotreload = package.loaded['cartridge.hotreload']
if hotreload ~= nil then
hotreload.whitelist_globals({'__metrics_registry'})
end

local function collectors()
return registry.collectors
end
Expand Down
3 changes: 2 additions & 1 deletion test/helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function helpers.entrypoint(name)
return path
end

function helpers.init_cluster()
function helpers.init_cluster(env)
local cluster = helpers.Cluster:new({
datadir = fio.tempdir(),
server_command = helpers.entrypoint('srv_basic'),
Expand All @@ -38,6 +38,7 @@ function helpers.init_cluster()
},
},
},
env = env,
})
cluster:start()
return cluster
Expand Down
40 changes: 36 additions & 4 deletions test/integration/cartridge_hotreload_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ local t = require('luatest')
local g = t.group()

local helpers = require('test.helper')
local utils = require('test.utils')

g.before_all(function()
t.skip_if(type(helpers) ~= 'table', 'Skip cartridge test')
helpers.skip_cartridge_version_less('2.3.0')
g.cluster = helpers.init_cluster()
g.cluster = helpers.init_cluster({TARANTOOL_ROLES_RELOAD_ALLOWED = 'true'})
end)

g.after_all(function()
Expand Down Expand Up @@ -57,9 +58,9 @@ end

local function reload_roles()
local main_server = g.cluster:server('main')
main_server.net_box:eval([[
require('cartridge.roles').reload()
]])
t.assert(main_server.net_box:eval([[
return require('cartridge.roles').reload()
]]))
end

g.test_cartridge_hotreload_set_export = function()
Expand Down Expand Up @@ -198,3 +199,34 @@ g.test_cartridge_hotreload_labels_from_config_and_set_labels = function()
t.assert_equals(obs.label_pairs.alias, 'main')
end
end

g.test_cartridge_hotreload_not_reset_collectors = function()
local main_server = g.cluster:server('main')
upload_config()

main_server:exec(function()
local metrics = require('cartridge').service_get('metrics')
metrics.gauge('hotreload_checker'):set(1)
end)

local resp = main_server:http_request('get', '/new-metrics', {raise = false})
t.assert_equals(resp.status, 200)

local obs = utils.find_metric('hotreload_checker', resp.json)
t.assert_covers(obs[1], {
metric_name = 'hotreload_checker',
value = 1,
})

reload_roles()

main_server = g.cluster:server('main')
resp = main_server:http_request('get', '/new-metrics', {raise = false})
t.assert_equals(resp.status, 200)

obs = utils.find_metric('hotreload_checker', resp.json)
t.assert_covers(obs[1], {
metric_name = 'hotreload_checker',
value = 1,
})
end