-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
metrics: introduce config alerts gauge
Since there is no full support of Tarantool 3 config instances in luatest yet (only treegen support in master), I had borrowed some test helpers from tarantool/crud [1]. 1. https://github.com/tarantool/crud/blob/98b120ef7095fa34525ef9d335a1458a2edf0cca/test/tarantool3_helpers Part of tarantool/grafana-dashboard#224
- Loading branch information
1 parent
4e15db9
commit 0fd973e
Showing
11 changed files
with
655 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
local utils = require('metrics.utils') | ||
|
||
local collectors_list = {} | ||
|
||
local function get_config_alerts(config_info) | ||
-- https://github.com/tarantool/tarantool/blob/319357d5973d15d08b8eda6a230eada08b710802/src/box/lua/config/utils/aboard.lua#L17-L18 | ||
local config_alerts = { | ||
warn = 0, | ||
error = 0, | ||
} | ||
|
||
for _, alert in pairs(config_info.alerts) do | ||
config_alerts[alert.type] = config_alerts[alert.type] + 1 | ||
end | ||
|
||
return config_alerts | ||
end | ||
|
||
local function update() | ||
if not utils.is_tarantool3() then | ||
return | ||
end | ||
|
||
-- Can migrate to box.info().config later | ||
-- https://github.com/tarantool/tarantool/commit/a1544d3bbc029c6fb2a148e580afe2b20e269b8d | ||
local config = require('config') | ||
local config_info = config:info() | ||
|
||
local config_alerts = get_config_alerts(config_info) | ||
|
||
for level, count in pairs(config_alerts) do | ||
collectors_list.config_alerts = utils.set_gauge( | ||
'config_alerts', | ||
'Tarantool 3 configuration alerts', | ||
count, | ||
{level = level}, | ||
nil, | ||
{default = true} | ||
) | ||
end | ||
end | ||
|
||
return { | ||
update = update, | ||
list = collectors_list, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
local t = require('luatest') | ||
local g = t.group() | ||
|
||
local fio = require('fio') | ||
local yaml = require('yaml') | ||
|
||
local utils = require('test.utils') | ||
local treegen = require('test.tarantool3_helpers.treegen') | ||
local server_helper = require('test.tarantool3_helpers.server') | ||
|
||
g.before_all(function(cg) | ||
cg.treegen = {} | ||
treegen.init(cg.treegen) | ||
end) | ||
|
||
g.after_all(function(cg) | ||
treegen.clean(cg.treegen) | ||
end) | ||
|
||
|
||
local default_config = { | ||
credentials = { | ||
users = { | ||
guest = { | ||
roles = {'super'}, | ||
}, | ||
replicator = { | ||
password = 'replicating', | ||
roles = {'replication'}, | ||
}, | ||
}, | ||
}, | ||
iproto = { | ||
advertise = { | ||
peer = { | ||
login = 'replicator', | ||
}, | ||
}, | ||
}, | ||
groups = { | ||
servers = { | ||
replicasets = { | ||
['server-001'] = { | ||
leader = 'server-001-a', | ||
instances = { | ||
['server-001-a'] = { | ||
iproto = { | ||
listen = {{uri = 'localhost:3301'}}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
replication = { | ||
failover = 'manual', | ||
}, | ||
metrics = { | ||
include = {'all'}, | ||
}, | ||
} | ||
|
||
local function write_config(cg, config) | ||
return treegen.write_script(cg.server_dir, 'config.yaml', yaml.encode(config)) | ||
end | ||
|
||
local function start_server(cg) | ||
t.skip_if(not utils.is_tarantool_3_config_supported(), | ||
'Skip since Tarantool 3 config is unsupported') | ||
|
||
cg.server_dir = treegen.prepare_directory(cg.treegen, {}, {}) | ||
local config_file = write_config(cg, default_config) | ||
|
||
cg.server = server_helper:new{ | ||
alias = 'server-001-a', | ||
config_file = config_file, | ||
chdir = cg.server_dir, | ||
} | ||
cg.server:start{wait_until_ready = true} | ||
end | ||
|
||
local function stop_server(cg) | ||
if cg.server ~= nil then | ||
cg.server:stop() | ||
cg.server = nil | ||
end | ||
|
||
if cg.server_dir ~= nil then | ||
fio.rmtree(cg.server_dir) | ||
cg.server_dir = nil | ||
end | ||
end | ||
|
||
local function reload_config(cg, config) | ||
write_config(cg, config) | ||
cg.server:exec(function() | ||
pcall(function() | ||
require('config'):reload() | ||
end) | ||
end) | ||
end | ||
|
||
local function assert_config_alerts_metrics(server, expected_values) | ||
local observations = server:exec(function() | ||
local metrics = require('metrics') | ||
metrics.invoke_callbacks() | ||
return metrics.collect() | ||
end) | ||
|
||
local warnings = utils.find_obs( | ||
'tnt_config_alerts', | ||
{level = 'warn', alias = 'server-001-a'}, | ||
observations | ||
) | ||
t.assert_equals(warnings.value, expected_values['warn']) | ||
|
||
local errors = utils.find_obs( | ||
'tnt_config_alerts', | ||
{level = 'error', alias = 'server-001-a'}, | ||
observations | ||
) | ||
t.assert_equals(errors.value, expected_values['error']) | ||
end | ||
|
||
|
||
g.before_test('test_config_alerts_if_healthy', start_server) | ||
g.after_test('test_config_alerts_if_healthy', stop_server) | ||
|
||
g.test_config_alerts_if_healthy = function(cg) | ||
assert_config_alerts_metrics(cg.server, {warn = 0, error = 0}) | ||
end | ||
|
||
|
||
g.before_test('test_config_alerts_if_minor_trouble', start_server) | ||
g.after_test('test_config_alerts_if_minor_trouble', stop_server) | ||
|
||
g.test_config_alerts_if_minor_trouble = function(cg) | ||
local config = table.deepcopy(default_config) | ||
config['credentials']['users']['user_one'] = {roles = {'role_two'}} | ||
reload_config(cg, config) | ||
|
||
assert_config_alerts_metrics(cg.server, {warn = 1, error = 0}) | ||
end | ||
|
||
|
||
g.before_test('test_config_alerts_if_critical_failure', start_server) | ||
g.after_test('test_config_alerts_if_critical_failure', stop_server) | ||
|
||
g.test_config_alerts_if_critical_failure = function(cg) | ||
local config = table.deepcopy(default_config) | ||
config['groups']['servers'] = {} | ||
reload_config(cg, config) | ||
|
||
assert_config_alerts_metrics(cg.server, {warn = 0, error = 1}) | ||
end | ||
|
||
|
||
g.before_test('test_config_alerts_if_unsupported', function(cg) | ||
t.skip_if(utils.is_tarantool_3_config_supported(), | ||
'Skip since Tarantool 3 config is supported') | ||
utils.create_server(cg) | ||
end) | ||
|
||
g.after_test('test_config_alerts_if_unsupported', function(cg) | ||
utils.drop_server(cg) | ||
cg.server = nil | ||
end) | ||
|
||
g.test_config_alerts_if_unsupported = function(cg) | ||
local observations = cg.server:exec(function() | ||
local metrics = require('metrics') | ||
metrics.invoke_callbacks() | ||
return metrics.collect() | ||
end) | ||
|
||
local alerts = utils.find_metric('tnt_config_alerts', observations) | ||
t.assert_equals(alerts, nil) | ||
end |
Oops, something went wrong.