Skip to content

Commit

Permalink
Resolve space name in statistics
Browse files Browse the repository at this point in the history
`crud.len` supports using space id instead of name. After this patch,
stats wrapper support mapping id to name.

Part of #224
  • Loading branch information
DifferentialOrange committed Dec 20, 2021
1 parent 5aeb43d commit 107f92a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
15 changes: 13 additions & 2 deletions crud/stats/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ local function wrap_tail(space_name, op, opts, start_time, call_status, ...)
end

local context_stats = utils.get_context_section('router_stats')
-- Describe local variables to use `goto`.
local space_not_found_msg, space

-- If space not exists, do not build a separate collector for it.
-- Call request for non-existing space will always result in error.
Expand All @@ -127,7 +129,7 @@ local function wrap_tail(space_name, op, opts, start_time, call_status, ...)
-- it is treated as unknown as well.
if status == 'error' and registry.is_unknown_space(space_name) then
if type(err) == 'table' and type(err.err) == 'string' then
local space_not_found_msg = utils.space_doesnt_exist_msg(space_name)
space_not_found_msg = utils.space_doesnt_exist_msg(space_name)
if string.find(err.err, space_not_found_msg) ~= nil then
registry.observe_space_not_found()
goto return_values
Expand All @@ -137,13 +139,22 @@ local function wrap_tail(space_name, op, opts, start_time, call_status, ...)
-- We can't rely only on parsing error value because space existence
-- is not always the first check in request validation.
-- Check explicitly if space do not exist.
local space = utils.get_space(space_name, vshard.router.routeall())
space = utils.get_space(space_name, vshard.router.routeall())
if space == nil then
registry.observe_space_not_found()
goto return_values
end
end

-- If space id is provided instead of name, resolve name.
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

registry.observe(latency, space_name, op, status)

if context_stats ~= nil then
Expand Down
1 change: 1 addition & 0 deletions test/entrypoint/srv_select.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package.preload['customers-storage'] = function()
},
if_not_exists = true,
engine = engine,
id = 542,
})
-- primary index
customers_space:create_index('id_index', {
Expand Down
1 change: 1 addition & 0 deletions test/entrypoint/srv_simple_operations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package.preload['customers-storage'] = function()
},
if_not_exists = true,
engine = engine,
id = 542,
})
customers_space:create_index('id', {
parts = { {field = 'id'} },
Expand Down
9 changes: 9 additions & 0 deletions test/integration/stats_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -560,3 +561,11 @@ for name, case in pairs(select_cases) do
'Expected count of map reduces planned')
end
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
9 changes: 9 additions & 0 deletions test/unit/stats_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -496,3 +497,11 @@ g.test_disable_stats_after_fetch_callback_get_do_not_break_call = function(g)

t.success('No unexpected errors')
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

0 comments on commit 107f92a

Please sign in to comment.