Skip to content

Commit a827ab3

Browse files
Resolve space name from id in statistics
`crud.len` supports using space id instead of name. After this patch, stats wrapper support mapping id to name. Since using space id is a questionable pattern (see #255), this commit may be reverted later. Part of #224
1 parent 1a99f0d commit a827ab3

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

crud/stats/module.lua

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ function stats.get(space_name)
119119
end
120120

121121
local function wrap_tail(space_name, op, pairs, start_time, call_status, ...)
122-
dev_checks('string', 'string', 'boolean', 'number', 'boolean')
122+
dev_checks('string|number', 'string', 'boolean', 'number', 'boolean')
123123

124124
local finish_time = clock.monotonic()
125125
local latency = finish_time - start_time
@@ -168,6 +168,17 @@ local function wrap_tail(space_name, op, pairs, start_time, call_status, ...)
168168
end
169169
end
170170

171+
-- If space id is provided instead of name, resolve name.
172+
-- If using space id will be deprecated, remove this code as well,
173+
-- see https://github.com/tarantool/crud/issues/255
174+
if type(space_name) ~= 'string' then
175+
if space == nil then
176+
space = utils.get_space(space_name, vshard.router.routeall())
177+
end
178+
179+
space_name = space.name
180+
end
181+
171182
if context_stats ~= nil then
172183
if context_stats.map_reduces ~= nil then
173184
registry.observe_map_reduces(context_stats.map_reduces, space_name)

test/entrypoint/srv_stats.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ package.preload['customers-storage'] = function()
2323
},
2424
if_not_exists = true,
2525
engine = engine,
26+
id = 542,
2627
})
2728
-- primary index
2829
customers_space:create_index('id_index', {

test/integration/stats_test.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ local stats_registry_common = require('crud.stats.registry_common')
77
local g = t.group('stats_integration')
88
local helpers = require('test.helper')
99

10+
local space_id = 542
1011
local space_name = 'customers'
1112
local unknown_space_name = 'non_existing_space'
1213
local new_space_name = 'newspace'
@@ -637,6 +638,15 @@ for name, case in pairs(select_cases) do
637638
end
638639

639640

641+
g.test_resolve_name_from_id = function(g)
642+
local op = 'len'
643+
g.router:call('crud.len', { space_id })
644+
645+
local stats = g:get_stats(space_name)
646+
t.assert_not_equals(stats[op], nil, "Statistics is filled by name")
647+
end
648+
649+
640650
g.before_test(
641651
'test_role_reload_do_not_reset_observations',
642652
generate_stats)

test/unit/stats_test.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ local utils = require('crud.common.utils')
99
local g = t.group('stats_unit')
1010
local helpers = require('test.helper')
1111

12+
local space_id = 542
1213
local space_name = 'customers'
1314
local unknown_space_name = 'non_existing_space'
1415

@@ -528,3 +529,11 @@ g.test_map_reduce_increment = function(g)
528529
t.assert_equals(stats.spaces[space_name][op].details.map_reduces, inc,
529530
"Counter of map reduces incremented")
530531
end
532+
533+
g.test_resolve_name_from_id = function(g)
534+
local op = stats_module.op.LEN
535+
g.router:eval(call_wrapped, { 'return_true', stats_module.op.LEN, {}, space_id })
536+
537+
local stats = g:get_stats(space_name)
538+
t.assert_not_equals(stats[op], nil, "Statistics is filled by name")
539+
end

0 commit comments

Comments
 (0)