Skip to content

Commit

Permalink
Add new metrics category: cpu extended
Browse files Browse the repository at this point in the history
  • Loading branch information
yngvar-antonsson committed Feb 3, 2025
1 parent 03d31c6 commit c01c732
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 31 deletions.
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]

### Added
- New metrics category in config: ``cpu_extended``.

### Fixed
- Use box.info.ro instead of box.cfg.read_only in replication metrics.

Expand Down
2 changes: 2 additions & 0 deletions metrics/tarantool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local utils = require('metrics.utils')
local const = require('metrics.const')

local default_metrics = {
-- category = {update: function, list: table},
network = require('metrics.tarantool.network'),
operations = require('metrics.tarantool.operations'),
system = require('metrics.tarantool.system'),
Expand All @@ -24,6 +25,7 @@ local default_metrics = {
clock = require('metrics.tarantool.clock'),
event_loop = require('metrics.tarantool.event_loop'),
config = require('metrics.tarantool.config'),
cpu_extended = require('metrics.psutils.cpu'),
}

local all_metrics_map = {}
Expand Down
79 changes: 48 additions & 31 deletions test/cfg_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,38 +127,55 @@ group.test_table_is_immutable = function(g)
end)
end

group.test_include = function(g)
g.server:exec(function()
local metrics = require('metrics')
local utils = require('test.utils') -- luacheck: ignore 431

metrics.cfg{
include = {'info'},
}

local default_metrics = metrics.collect{invoke_callbacks = true}
local uptime = utils.find_metric('tnt_info_uptime', default_metrics)
t.assert_not_equals(uptime, nil)
local memlua = utils.find_metric('tnt_info_memory_lua', default_metrics)
t.assert_equals(memlua, nil)
end)
end

group.test_exclude = function(g)
g.server:exec(function()
local metrics = require('metrics')
local utils = require('test.utils') -- luacheck: ignore 431

metrics.cfg{
exclude = {'memory'},
}
local matrix = {
-- {category: string, includes: string, excludes: string, linux_only: boolean}
{'info', 'tnt_info_uptime', 'tnt_info_memory_lua'},
{'cpu_extended', 'tnt_cpu_thread', 'tnt_info_memory_lua', true},
{'network', 'tnt_net_sent_total', 'tnt_info_memory_lua'},
{'operations', 'tnt_stats_op_total', 'tnt_info_memory_lua'},
{'system', 'tnt_cfg_current_time', 'tnt_info_memory_lua'},
{'replicas', 'tnt_replication_lsn', 'tnt_info_memory_lua'},
-- TODO: add more caterories
}

for _, row in ipairs(matrix) do
local category, include, exclude, linux_only = unpack(row)

group[('test_include_%s'):format(category)] = function(g)
g.server:exec(function()
t.skip_if(linux_only and jit.os ~= 'Linux', 'Linux is the only supported platform')
local metrics = require('metrics')
local utils = require('test.utils') -- luacheck: ignore 431

metrics.cfg{
include = {category},
}

local default_metrics = metrics.collect{invoke_callbacks = true}
local included = utils.find_metric(include, default_metrics)
t.assert_not_equals(included, nil)
local excluded = utils.find_metric(exclude, default_metrics)
t.assert_equals(excluded, nil)
end)
end
group[('test_exclude_%s'):format(category)] = function(g)
g.server:exec(function()
t.skip_if(linux_only and jit.os ~= 'Linux', 'Linux is the only supported platform')
local metrics = require('metrics')
local utils = require('test.utils') -- luacheck: ignore 431

metrics.cfg{
exclude = {category},
}

local default_metrics = metrics.collect{invoke_callbacks = true}
local uptime = utils.find_metric(exclude, default_metrics)
t.assert_not_equals(uptime, nil)
local memlua = utils.find_metric(include, default_metrics)
t.assert_equals(memlua, nil)
end)
end

local default_metrics = metrics.collect{invoke_callbacks = true}
local uptime = utils.find_metric('tnt_info_uptime', default_metrics)
t.assert_not_equals(uptime, nil)
local memlua = utils.find_metric('tnt_info_memory_lua', default_metrics)
t.assert_equals(memlua, nil)
end)
end

group.test_include_with_exclude = function(g)
Expand Down

0 comments on commit c01c732

Please sign in to comment.