Skip to content

Commit cbe4a3e

Browse files
Add counter:reset method
1 parent 56220e9 commit cbe4a3e

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88
### Added
99
- collector's method `remove` to clear observations with given label pairs [#263](https://github.com/tarantool/metrics/issues/263)
10+
- `counter:reset()` method [#260](https://github.com/tarantool/metrics/issues/260)
1011

1112
## [0.10.0] - 2021-08-03
1213
### Changed

doc/monitoring/api_reference.rst

+4
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ Counter
6969

7070
Removes an observation with ``label_pairs``.
7171

72+
.. method:: reset(label_pairs)
73+
74+
Set an observation under ``label_pairs`` to 0.
75+
7276
:param table label_pairs: Table containing label names as keys,
7377
label values as values.
7478

metrics/collectors/counter.lua

+4
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ function Counter:inc(num, label_pairs)
99
Shared.inc(self, num, label_pairs)
1010
end
1111

12+
function Counter:reset(label_pairs)
13+
Shared.set(self, 0, label_pairs)
14+
end
15+
1216
return Counter

test/collectors_test.lua

+8-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ g.test_global_labels = function()
269269
t.assert_equals(obs_bucket_inf_hist_2.value, 1, "bucket +inf has 1 value: 2; observation global label has changed")
270270
end
271271

272-
273272
g.test_counter_remove_metric_by_label = function()
274273
local c = metrics.counter('cnt')
275274

@@ -303,3 +302,11 @@ g.test_gauge_remove_metric_by_label = function()
303302
{'gauge', 1, {label = 2}},
304303
})
305304
end
305+
306+
g.test_collector_reset = function()
307+
local c = metrics.counter('cnt', 'some counter')
308+
c:inc()
309+
t.assert_equals(c:collect()[1].value, 1)
310+
c:reset()
311+
t.assert_equals(c:collect()[1].value, 0)
312+
end

0 commit comments

Comments
 (0)