diff --git a/crud/stats/module.lua b/crud/stats/module.lua index 3277ddf71..0a051d766 100644 --- a/crud/stats/module.lua +++ b/crud/stats/module.lua @@ -119,7 +119,7 @@ function stats.get(space_name) end local function wrap_tail(space_name, op, pairs, start_time, call_status, ...) - dev_checks('string', 'string', 'boolean', 'number', 'boolean') + dev_checks('string|number', 'string', 'boolean', 'number', 'boolean') local finish_time = clock.monotonic() local latency = finish_time - start_time @@ -168,6 +168,17 @@ local function wrap_tail(space_name, op, pairs, start_time, call_status, ...) end end + -- If space id is provided instead of name, resolve name. + -- If using space id will be deprecated, remove this code as well, + -- see https://github.com/tarantool/crud/issues/255 + if type(space_name) ~= 'string' then + if space == nil then + space = utils.get_space(space_name, vshard.router.routeall()) + end + + space_name = space.name + end + if context_stats ~= nil then if context_stats.map_reduces ~= nil then registry.observe_map_reduces(context_stats.map_reduces, space_name) diff --git a/test/entrypoint/srv_stats.lua b/test/entrypoint/srv_stats.lua index d9649b702..b8bd813fb 100755 --- a/test/entrypoint/srv_stats.lua +++ b/test/entrypoint/srv_stats.lua @@ -23,6 +23,7 @@ package.preload['customers-storage'] = function() }, if_not_exists = true, engine = engine, + id = 542, }) -- primary index customers_space:create_index('id_index', { diff --git a/test/integration/stats_test.lua b/test/integration/stats_test.lua index 6ee611e6a..464cd2318 100644 --- a/test/integration/stats_test.lua +++ b/test/integration/stats_test.lua @@ -7,6 +7,7 @@ local stats_registry_common = require('crud.stats.registry_common') local g = t.group('stats_integration') local helpers = require('test.helper') +local space_id = 542 local space_name = 'customers' local unknown_space_name = 'non_existing_space' local new_space_name = 'newspace' @@ -637,6 +638,15 @@ for name, case in pairs(select_cases) do end +g.test_resolve_name_from_id = function(g) + local op = 'len' + g.router:call('crud.len', { space_id }) + + local stats = g:get_stats(space_name) + t.assert_not_equals(stats[op], nil, "Statistics is filled by name") +end + + g.before_test( 'test_role_reload_do_not_reset_observations', generate_stats) diff --git a/test/unit/stats_test.lua b/test/unit/stats_test.lua index bc60a5b01..2df1d9fe7 100644 --- a/test/unit/stats_test.lua +++ b/test/unit/stats_test.lua @@ -9,6 +9,7 @@ local utils = require('crud.common.utils') local g = t.group('stats_unit') local helpers = require('test.helper') +local space_id = 542 local space_name = 'customers' local unknown_space_name = 'non_existing_space' @@ -528,3 +529,11 @@ g.test_map_reduce_increment = function(g) t.assert_equals(stats.spaces[space_name][op].details.map_reduces, inc, "Counter of map reduces incremented") end + +g.test_resolve_name_from_id = function(g) + local op = stats_module.op.LEN + g.router:eval(call_wrapped, { 'return_true', stats_module.op.LEN, {}, space_id }) + + local stats = g:get_stats(space_name) + t.assert_not_equals(stats[op], nil, "Statistics is filled by name") +end