Skip to content

Commit 4b04408

Browse files
Set quantile value to nil if there are no samples provided for an age
Closes #303
1 parent 7652824 commit 4b04408

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
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 nil 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/quantile.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,11 @@ function quantile.Query(stream_obj, q)
270270
-- Fast path when there hasn't been enough data for a flush;
271271
-- this also yields better accuracy for small sets of data.
272272
local l = stream_obj.b_len
273+
274+
if l == 0 then
275+
return nil
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_equals(res, nil)
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_equals(res, nil)
160160

161161
quantile.Reset(Quantile)
162162

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

167167
g.test_quantile_insert_works_after_reset = function()

0 commit comments

Comments
 (0)