@@ -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/
@@ -177,11 +195,24 @@ local function wrap_pairs_gen(build_latency, space_name, op, gen, param, state)
177
195
end
178
196
179
197
local function wrap_tail (space_name , op , pairs , start_time , call_status , ...)
180
- dev_checks (' string' , ' string' , ' boolean' , ' number' , ' boolean' )
198
+ dev_checks (' string|number ' , ' string' , ' boolean' , ' number' , ' boolean' )
181
199
182
200
local finish_time = clock .monotonic ()
183
201
local latency = finish_time - start_time
184
202
203
+ -- If space id is provided instead of name, try to resolve name.
204
+ -- If resolve have failed, use id as string to observe space.
205
+ -- If using space id will be deprecated, remove this code as well,
206
+ -- see https://github.com/tarantool/crud/issues/255
207
+ if type (space_name ) ~= ' string' then
208
+ local name = resolve_space_name (space_name )
209
+ if name ~= nil then
210
+ space_name = name
211
+ else
212
+ space_name = tostring (space_name )
213
+ end
214
+ end
215
+
185
216
if call_status == false then
186
217
registry .observe (latency , space_name , op , ' error' )
187
218
error ((... ), 2 )
0 commit comments