Skip to content

Commit d58e4d2

Browse files
Satbekoleg-jukovec
authored andcommitted
schema: add schema needs upgrade metric
Metric checks whether schema needs an upgrade. Value 1 means upgrade required, 0 means schema up-to-date. Closes TNTP-4904
1 parent 8432839 commit d58e4d2

File tree

5 files changed

+77
-2
lines changed

5 files changed

+77
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010

1111
- `tnt_memory` metric.
1212
- `tnt_memory_virt` metric.
13+
- `tnt_schema_needs_upgrade` metric.
1314

1415
### Changed
1516

doc/monitoring/metrics_reference.rst

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,23 @@ General instance information:
2323
* - ``tnt_read_only``
2424
- Indicates if the instance is in read-only mode (``1`` if true, ``0`` if false)
2525

26-
.. _metrics-reference-memory_general:
26+
.. _metrics-reference-schema:
27+
28+
Schema
29+
------
30+
31+
Schema state metrics.
32+
33+
.. container:: table
34+
35+
.. list-table::
36+
:widths: 25 75
37+
:header-rows: 0
38+
39+
* - ``tnt_schema_needs_upgrade``
40+
- Indicates if the instance schema requires an upgrade (``1`` when upgrade is needed, ``0`` when schema is up to date)
41+
42+
.. _metrics-reference-instance:
2743

2844
Instance metrics
2945
----------------
@@ -45,7 +61,7 @@ These metrics can be used to monitor instance CPU and RAM usage.
4561
* - ``tnt_memory_virt``
4662
- Virtual memory size in bytes used by Tarantool instance (available on Linux).
4763

48-
.. _metrics-reference-instance:
64+
.. _metrics-reference-memory_general:
4965

5066
Memory general
5167
--------------

metrics/tarantool.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ local default_metrics = {
2727
event_loop = require('metrics.tarantool.event_loop'),
2828
config = require('metrics.tarantool.config'),
2929
cpu_extended = require('metrics.psutils.cpu'),
30+
schema = require('metrics.tarantool.schema')
3031
}
3132

3233
local all_metrics_map = {}

metrics/tarantool/schema.lua

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
local utils = require('metrics.utils')
2+
-- luacheck: globals box
3+
4+
local collectors_list = {}
5+
6+
local metric_name = 'schema_needs_upgrade'
7+
8+
local needs_upgrade_status = {
9+
[true] = 1,
10+
[false] = 0,
11+
}
12+
13+
local function update_schema_metrics()
14+
if not utils.box_is_configured() then
15+
return
16+
end
17+
18+
local ok, needs_upgrade = pcall(box.schema_needs_upgrade)
19+
if not ok then
20+
ok, needs_upgrade = pcall(box.internal.schema_needs_upgrade)
21+
end
22+
23+
if ok then
24+
collectors_list[metric_name] = utils.set_gauge(metric_name, 'Schema needs upgrade',
25+
needs_upgrade_status[needs_upgrade], nil, nil, {default = true})
26+
end
27+
end
28+
29+
return {
30+
update = update_schema_metrics,
31+
list = collectors_list,
32+
}

test/tarantool/schema_test.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require('strict').on()
2+
3+
local t = require('luatest')
4+
local g = t.group()
5+
6+
local utils = require('test.utils')
7+
8+
g.before_all(utils.create_server)
9+
10+
g.after_all(utils.drop_server)
11+
12+
g.test_needs_upgrade = function(cg)
13+
cg.server:exec(function()
14+
local metrics = require('metrics')
15+
local schema = require('metrics.tarantool.schema')
16+
local utils = require('test.utils') -- luacheck: ignore 431
17+
18+
metrics.enable_default_metrics()
19+
schema.update()
20+
local default_metrics = metrics.collect()
21+
local schema_needs_upgrade_metric = utils.find_metric('tnt_schema_needs_upgrade', default_metrics)
22+
t.assert(schema_needs_upgrade_metric)
23+
t.assert_type(schema_needs_upgrade_metric[1].value, 'number')
24+
end)
25+
end

0 commit comments

Comments
 (0)