@@ -6,6 +6,8 @@ local clock = require('clock')
6
6
local checks = require (' checks' )
7
7
local fiber = require (' fiber' )
8
8
local fun = require (' fun' )
9
+ local log = require (' log' )
10
+ local vshard = require (' vshard' )
9
11
10
12
local dev_checks = require (' crud.common.dev_checks' )
11
13
local stash = require (' crud.common.stash' )
@@ -109,6 +111,22 @@ function stats.get(space_name)
109
111
return registry .get (space_name )
110
112
end
111
113
114
+ local function resolve_space_name (space_id )
115
+ local replicasets = vshard .router .routeall ()
116
+ if next (replicasets ) == nil then
117
+ log .warn (' Failed to resolve space name for stats: no replicasets found' )
118
+ return nil
119
+ end
120
+
121
+ local space = utils .get_space (space_id , replicasets )
122
+ if space == nil then
123
+ log .warn (' Failed to resolve space name for stats: no space found for id %d' , space_id )
124
+ return nil
125
+ end
126
+
127
+ return space .name
128
+ end
129
+
112
130
-- Hack to set __gc for a table in Lua 5.1
113
131
-- See https://stackoverflow.com/questions/27426704/lua-5-1-workaround-for-gc-metamethod-for-tables
114
132
-- or https://habr.com/ru/post/346892/
@@ -179,11 +197,24 @@ local function wrap_pairs_gen(build_latency, space_name, op, gen, param, state)
179
197
end
180
198
181
199
local function wrap_tail (space_name , op , pairs , start_time , call_status , ...)
182
- dev_checks (' string' , ' string' , ' boolean' , ' number' , ' boolean' )
200
+ dev_checks (' string|number ' , ' string' , ' boolean' , ' number' , ' boolean' )
183
201
184
202
local finish_time = clock .monotonic ()
185
203
local latency = finish_time - start_time
186
204
205
+ -- If space id is provided instead of name, try to resolve name.
206
+ -- If resolve have failed, use id as string to observe space.
207
+ -- If using space id will be deprecated, remove this code as well,
208
+ -- see https://github.com/tarantool/crud/issues/255
209
+ if type (space_name ) ~= ' string' then
210
+ local name = resolve_space_name (space_name )
211
+ if name ~= nil then
212
+ space_name = name
213
+ else
214
+ space_name = tostring (space_name )
215
+ end
216
+ end
217
+
187
218
if call_status == false then
188
219
registry .observe (latency , space_name , op , ' error' )
189
220
error ((... ), 2 )
0 commit comments