1
+ local errors = require (' errors' )
2
+
1
3
local dev_checks = require (' crud.common.dev_checks' )
2
4
local op_module = require (' crud.stats.operation' )
3
5
local registry_common = require (' crud.stats.registry_common' )
4
6
local stash = require (' crud.stats.stash' )
5
7
6
8
local registry = {}
7
- local internal_registry = stash .get (' local_registry' )
9
+ local internal = stash .get (' local_registry' )
10
+ local StatsLocalError = errors .new_class (' StatsLocalError' , {capture_stack = false })
8
11
9
12
--- Initialize local metrics registry
10
13
--
11
14
-- Registries are not meant to used explicitly
12
15
-- by users, init is not guaranteed to be idempotent.
13
16
--
14
17
-- @function init
18
+ -- @tparam table opts
19
+ --
20
+ -- @tfield boolean quantiles
21
+ -- Quantiles is not supported for local, only `false` is valid.
15
22
--
16
23
-- @treturn boolean Returns true.
17
24
--
18
- function registry .init ()
19
- internal_registry .spaces = {}
20
- internal_registry .space_not_found = 0
25
+ function registry .init (opts )
26
+ dev_checks ({ quantiles = ' boolean' })
27
+
28
+ StatsLocalError :assert (opts .quantiles == false ,
29
+ " Quantiles are not supported for 'local' statistics registry" )
30
+
31
+ internal .registry = {}
32
+ internal .registry .spaces = {}
33
+ internal .registry .space_not_found = 0
21
34
22
35
return true
23
36
end
32
45
-- @treturn boolean Returns true.
33
46
--
34
47
function registry .destroy ()
35
- internal_registry = stash . reset ( ' local_registry ' )
48
+ internal . registry = nil
36
49
37
50
return true
38
51
end
@@ -58,10 +71,10 @@ function registry.get(space_name)
58
71
dev_checks (' ?string' )
59
72
60
73
if space_name ~= nil then
61
- return table .deepcopy (internal_registry .spaces [space_name ]) or {}
74
+ return table .deepcopy (internal . registry .spaces [space_name ]) or {}
62
75
end
63
76
64
- return table .deepcopy (internal_registry )
77
+ return table .deepcopy (internal . registry )
65
78
end
66
79
67
80
--- Check if space statistics are present in registry
76
89
function registry .is_unknown_space (space_name )
77
90
dev_checks (' string' )
78
91
79
- return internal_registry .spaces [space_name ] == nil
92
+ return internal . registry .spaces [space_name ] == nil
80
93
end
81
94
82
95
--- Increase requests count and update latency info
101
114
function registry .observe (latency , space_name , op , status )
102
115
dev_checks (' number' , ' string' , ' string' , ' string' )
103
116
104
- registry_common .init_collectors_if_required (internal_registry .spaces , space_name , op )
105
- local collectors = internal_registry .spaces [space_name ][op ][status ]
117
+ registry_common .init_collectors_if_required (internal . registry .spaces , space_name , op )
118
+ local collectors = internal . registry .spaces [space_name ][op ][status ]
106
119
107
120
collectors .count = collectors .count + 1
108
121
collectors .time = collectors .time + latency
118
131
-- @treturn boolean Returns true.
119
132
--
120
133
function registry .observe_space_not_found ()
121
- internal_registry . space_not_found = internal_registry .space_not_found + 1
134
+ internal . registry . space_not_found = internal . registry .space_not_found + 1
122
135
123
136
return true
124
137
end
@@ -142,8 +155,8 @@ function registry.observe_fetch(tuples_fetched, tuples_lookup, space_name)
142
155
dev_checks (' number' , ' number' , ' string' )
143
156
144
157
local op = op_module .SELECT
145
- registry_common .init_collectors_if_required (internal_registry .spaces , space_name , op )
146
- local collectors = internal_registry .spaces [space_name ][op ].details
158
+ registry_common .init_collectors_if_required (internal . registry .spaces , space_name , op )
159
+ local collectors = internal . registry .spaces [space_name ][op ].details
147
160
148
161
collectors .tuples_fetched = collectors .tuples_fetched + tuples_fetched
149
162
collectors .tuples_lookup = collectors .tuples_lookup + tuples_lookup
@@ -167,8 +180,8 @@ function registry.observe_map_reduces(count, space_name)
167
180
dev_checks (' number' , ' string' )
168
181
169
182
local op = op_module .SELECT
170
- registry_common .init_collectors_if_required (internal_registry .spaces , space_name , op )
171
- local collectors = internal_registry .spaces [space_name ][op ].details
183
+ registry_common .init_collectors_if_required (internal . registry .spaces , space_name , op )
184
+ local collectors = internal . registry .spaces [space_name ][op ].details
172
185
173
186
collectors .map_reduces = collectors .map_reduces + count
174
187
0 commit comments