Skip to content

Commit

Permalink
Add election_leader_idle metric (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
yngvar-antonsson authored Nov 8, 2023
1 parent 8196f38 commit ba9726d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
(`metrics.cfg{include={'all'}}` can be used instead of `metrics.cfg{include='all'}`,
`metrics.cfg{exclude={'all'}}` can be used instead of `metrics.cfg{include='none'}`)

- `tnt_election_leader_idle` metric.

## [1.0.0] - 2023-05-22
### Changed

Expand Down
3 changes: 3 additions & 0 deletions doc/monitoring/metrics_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,9 @@ Shows the current state of a replica set node in regards to leader election.
* - ``tnt_election_term``
- Current election term.

* - ``tnt_election_leader_idle``
- Time in seconds since the last interaction with the known leader.

Memtx
-----

Expand Down
6 changes: 6 additions & 0 deletions metrics/tarantool/info.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ local function update_info_metrics()
collectors_list.election_term =
utils.set_gauge('election_term', 'Current election term',
info.election.term, nil, nil, {default = true})

if info.election.leader_idle ~= nil then
collectors_list.election_leader_idle =
utils.set_gauge('election_leader_idle', 'Current idle for elected leader',
info.election.leader_idle, nil, nil, {default = true})
end
end
end

Expand Down
23 changes: 23 additions & 0 deletions test/tarantool/info_metrics_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,26 @@ g.test_election = function(cg)
t.assert_type(tnt_election_term[1].value, 'number')
end)
end

g.test_election_leader_idle = function(cg)
t.skip_if(utils.is_version_less(_TARANTOOL, '2.10.0'),
'Tarantool version is must be v2.10.0 or greater')

cg.server:exec(function()
box.cfg{election_mode = 'candidate'}
local metrics = require('metrics')
local info = require('metrics.tarantool.info')
local utils = require('test.utils') -- luacheck: ignore 431

metrics.enable_default_metrics()
info.update()
local default_metrics = metrics.collect()

local tnt_election_leader_idle = utils.find_metric(
'tnt_election_leader_idle', default_metrics
)
t.assert(tnt_election_leader_idle)
t.assert_type(tnt_election_leader_idle[1].value, 'number')
box.cfg{election_mode = 'off'}
end)
end

0 comments on commit ba9726d

Please sign in to comment.