90
90
-- If quantile value is -Inf, try to decrease quantile tolerated error.
91
91
-- See https://github.com/tarantool/metrics/issues/189 for issue details.
92
92
--
93
+ -- @number[opt=2] opts.quantile_age_buckets_count
94
+ -- Count of summary quantile buckets.
95
+ -- See tarantool/metrics summary API for details:
96
+ -- https://www.tarantool.io/ru/doc/latest/book/monitoring/api_reference/#summary
97
+ -- Increasing the value smoothes time window move,
98
+ -- but consumes additional memory and CPU.
99
+ --
100
+ -- @number[opt=60] opts.quantile_max_age_time
101
+ -- Duration of each bucket’s lifetime in seconds.
102
+ -- See tarantool/metrics summary API for details:
103
+ -- https://www.tarantool.io/ru/doc/latest/book/monitoring/api_reference/#summary
104
+ -- Smaller bucket lifetime results in smaller time window for quantiles,
105
+ -- but more CPU is spent on bucket rotation. If your application has low request
106
+ -- frequency, increase the value to reduce the amount of `-nan` gaps in quantile values.
107
+ --
93
108
-- @treturn boolean Returns `true`.
94
109
--
95
110
function stats .enable (opts )
96
111
checks ({
97
112
driver = ' ?string' ,
98
113
quantiles = ' ?boolean' ,
99
114
quantile_tolerated_error = ' ?number' ,
115
+ quantile_age_buckets_count = ' ?number' ,
116
+ quantile_max_age_time = ' ?number' ,
100
117
})
101
118
102
119
StatsError :assert (
@@ -122,10 +139,20 @@ function stats.enable(opts)
122
139
opts .quantile_tolerated_error = stats .DEFAULT_QUANTILE_TOLERATED_ERROR
123
140
end
124
141
142
+ if opts .quantile_age_buckets_count == nil then
143
+ opts .quantile_age_buckets_count = stats .DEFAULT_QUANTILE_AGE_BUCKET_COUNT
144
+ end
145
+
146
+ if opts .quantile_max_age_time == nil then
147
+ opts .quantile_max_age_time = stats .DEFAULT_QUANTILE_MAX_AGE_TIME
148
+ end
149
+
125
150
-- Do not reinit if called with same options.
126
151
if internal .driver == opts .driver
127
152
and internal .quantiles == opts .quantiles
128
- and internal .quantile_tolerated_error == opts .quantile_tolerated_error then
153
+ and internal .quantile_tolerated_error == opts .quantile_tolerated_error
154
+ and internal .quantile_age_buckets_count == opts .quantile_age_buckets_count
155
+ and internal .quantile_max_age_time == opts .quantile_max_age_time then
129
156
return true
130
157
end
131
158
@@ -136,11 +163,15 @@ function stats.enable(opts)
136
163
137
164
internal :get_registry ().init {
138
165
quantiles = opts .quantiles ,
139
- quantile_tolerated_error = opts .quantile_tolerated_error
166
+ quantile_tolerated_error = opts .quantile_tolerated_error ,
167
+ quantile_age_buckets_count = opts .quantile_age_buckets_count ,
168
+ quantile_max_age_time = opts .quantile_max_age_time ,
140
169
}
141
170
142
171
internal .quantiles = opts .quantiles
143
172
internal .quantile_tolerated_error = opts .quantile_tolerated_error
173
+ internal .quantile_age_buckets_count = opts .quantile_age_buckets_count
174
+ internal .quantile_max_age_time = opts .quantile_max_age_time
144
175
145
176
return true
146
177
end
@@ -162,7 +193,9 @@ function stats.reset()
162
193
internal :get_registry ().destroy ()
163
194
internal :get_registry ().init {
164
195
quantiles = internal .quantiles ,
165
- quantile_tolerated_error = internal .quantile_tolerated_error
196
+ quantile_tolerated_error = internal .quantile_tolerated_error ,
197
+ quantile_age_buckets_count = internal .quantile_age_buckets_count ,
198
+ quantile_max_age_time = internal .quantile_max_age_time ,
166
199
}
167
200
168
201
return true
@@ -184,6 +217,9 @@ function stats.disable()
184
217
internal :get_registry ().destroy ()
185
218
internal .driver = nil
186
219
internal .quantiles = nil
220
+ internal .quantile_tolerated_error = nil
221
+ internal .quantile_age_buckets_count = nil
222
+ internal .quantile_max_age_time = nil
187
223
188
224
return true
189
225
end
@@ -495,4 +531,10 @@ stats.internal = internal
495
531
--- Default metrics quantile precision.
496
532
stats .DEFAULT_QUANTILE_TOLERATED_ERROR = 1e-3
497
533
534
+ --- Default metrics quantile bucket count.
535
+ stats .DEFAULT_QUANTILE_AGE_BUCKET_COUNT = 2
536
+
537
+ --- Default metrics quantile bucket lifetime.
538
+ stats .DEFAULT_QUANTILE_MAX_AGE_TIME = 60
539
+
498
540
return stats
0 commit comments