9090-- If quantile value is -Inf, try to decrease quantile tolerated error.
9191-- See https://github.com/tarantool/metrics/issues/189 for issue details.
9292--
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+ --
93108-- @treturn boolean Returns `true`.
94109--
95110function stats .enable (opts )
96111 checks ({
97112 driver = ' ?string' ,
98113 quantiles = ' ?boolean' ,
99114 quantile_tolerated_error = ' ?number' ,
115+ quantile_age_buckets_count = ' ?number' ,
116+ quantile_max_age_time = ' ?number' ,
100117 })
101118
102119 StatsError :assert (
@@ -122,10 +139,20 @@ function stats.enable(opts)
122139 opts .quantile_tolerated_error = stats .DEFAULT_QUANTILE_TOLERATED_ERROR
123140 end
124141
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+
125150 -- Do not reinit if called with same options.
126151 if internal .driver == opts .driver
127152 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
129156 return true
130157 end
131158
@@ -136,11 +163,15 @@ function stats.enable(opts)
136163
137164 internal :get_registry ().init {
138165 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 ,
140169 }
141170
142171 internal .quantiles = opts .quantiles
143172 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
144175
145176 return true
146177end
@@ -162,7 +193,9 @@ function stats.reset()
162193 internal :get_registry ().destroy ()
163194 internal :get_registry ().init {
164195 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 ,
166199 }
167200
168201 return true
@@ -184,6 +217,9 @@ function stats.disable()
184217 internal :get_registry ().destroy ()
185218 internal .driver = nil
186219 internal .quantiles = nil
220+ internal .quantile_tolerated_error = nil
221+ internal .quantile_age_buckets_count = nil
222+ internal .quantile_max_age_time = nil
187223
188224 return true
189225end
@@ -495,4 +531,10 @@ stats.internal = internal
495531--- Default metrics quantile precision.
496532stats .DEFAULT_QUANTILE_TOLERATED_ERROR = 1e-3
497533
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+
498540return stats
0 commit comments