Skip to content

Commit 23d8391

Browse files
Set quantile value to NAN if there are no samples provided for an age
Closes #303
1 parent 7652824 commit 23d8391

File tree

6 files changed

+19
-5
lines changed

6 files changed

+19
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
- Throw an error when http_middelware is processing a wrong handler [#199](https://github.com/tarantool/metrics/issues/199)
1717
- cartridge issues metric fails before cartridge.cfg() call [#298](https://github.com/tarantool/metrics/issues/298)
1818

19+
### Changed
20+
- quantile metric is NAN if no samples provided for an age [#303](https://github.com/tarantool/metrics/issues/303)
21+
1922
## [0.10.0] - 2021-08-03
2023
### Changed
2124
- metrics registry refactoring to search with `O(1)` [#188](https://github.com/tarantool/metrics/issues/188)

metrics-scm-1.rockspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ build = {
3131
['metrics.collectors.counter'] = 'metrics/collectors/counter.lua',
3232
['metrics.collectors.gauge'] = 'metrics/collectors/gauge.lua',
3333
['metrics.collectors.histogram'] = 'metrics/collectors/histogram.lua',
34+
['metrics.const'] = 'metrics/const.lua',
3435
['metrics.plugins.graphite'] = 'metrics/plugins/graphite.lua',
3536
['metrics.plugins.prometheus'] = 'metrics/plugins/prometheus.lua',
3637
['metrics.plugins.json'] = 'metrics/plugins/json.lua',

metrics/const.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
return {
2+
INF = math.huge,
3+
NAN = math.huge * 0,
4+
}

metrics/init.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
local checks = require('checks')
44
local log = require('log')
55

6+
local Const = require('metrics.const')
67
local Registry = require('metrics.registry')
78

89
local Counter = require('metrics.collectors.counter')
@@ -108,8 +109,8 @@ return {
108109
histogram = histogram,
109110
summary = summary,
110111

111-
INF = math.huge,
112-
NAN = math.huge * 0,
112+
INF = Const.INF,
113+
NAN = Const.NAN,
113114

114115
clear = clear,
115116
collectors = collectors,

metrics/quantile.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local ffi = require('ffi')
2+
local const = require('metrics.const')
23

34
local quantile = {}
45

@@ -270,6 +271,10 @@ function quantile.Query(stream_obj, q)
270271
-- Fast path when there hasn't been enough data for a flush;
271272
-- this also yields better accuracy for small sets of data.
272273
local l = stream_obj.b_len
274+
if l == 0 then
275+
return const.NAN
276+
end
277+
273278
local i = math.modf(l * q)
274279
stream_obj:maybe_sort()
275280
return stream_obj.b[i]

test/quantile_test.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ g.test_query_on_empty_quantile = function()
146146

147147
local res = quantile.Query(emptyQuantile, 0.99)
148148

149-
t.assert_equals(res, math.huge)
149+
t.assert_nan(res)
150150
end
151151

152152
g.test_reset = function()
@@ -156,12 +156,12 @@ g.test_reset = function()
156156
end
157157

158158
local res = quantile.Query(Quantile, 0.99)
159-
t.assert_not_equals(res, math.huge)
159+
t.assert_not_nan(res)
160160

161161
quantile.Reset(Quantile)
162162

163163
res = quantile.Query(Quantile, 0.99)
164-
t.assert_equals(res, math.huge)
164+
t.assert_nan(res)
165165
end
166166

167167
g.test_quantile_insert_works_after_reset = function()

0 commit comments

Comments
 (0)