Skip to content

Commit

Permalink
fix: counter.inc should only allow incrementing by values greather th…
Browse files Browse the repository at this point in the history
…an zero
  • Loading branch information
Fox32 committed Sep 25, 2020
1 parent bde3bb5 commit 64cef4c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 5 deletions.
6 changes: 5 additions & 1 deletion prometheus_client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
## 0.4.1

- `counter.inc()` should only allow to increment by values greather than zero.

## 0.4.0+4

- Moved to new org [tentaclelabs](https://github.com/tentaclelabs)
- Moved to new org [tentaclelabs](https://github.com/tentaclelabs).


## 0.4.0+3
Expand Down
4 changes: 2 additions & 2 deletions prometheus_client/lib/src/prometheus_client/counter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class CounterChild {
/// Increment the [value] of the counter with labels by [amount].
/// Increments by one, if no amount is provided.
void inc([double amount = 1]) {
if (amount < 0) {
if (amount <= 0) {
throw ArgumentError.value(
amount, 'amount', 'Must be greater or equal to zero.');
amount, 'amount', 'Must be greater than zero.');
}

_value += amount;
Expand Down
2 changes: 1 addition & 1 deletion prometheus_client/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: prometheus_client
description: Dart implementation of the Prometheus client library providing metrics.
version: 0.4.0+4
version: 0.4.1
homepage: https://github.com/tentaclelabs/prometheus_client

environment:
Expand Down
6 changes: 6 additions & 0 deletions prometheus_client/test/prometheus_client_counter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ void main() {
expect(() => counter.inc(-42.0), throwsArgumentError);
});

test('Should not increment by zero', () {
final counter = Counter('my_metric', 'Help!');

expect(() => counter.inc(0.0), throwsArgumentError);
});

test('Should not allow to set label values if no labels were specified',
() {
final counter = Counter('my_metric', 'Help!');
Expand Down
4 changes: 4 additions & 0 deletions prometheus_client_shelf/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.4.1

No changes

## 0.4.0+4

- Moved to new org [tentaclelabs](https://github.com/tentaclelabs)
Expand Down
2 changes: 1 addition & 1 deletion prometheus_client_shelf/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: prometheus_client_shelf
description: Dart implementation of the Prometheus client library providing a shelf integration.
version: 0.4.0+4
version: 0.4.1
homepage: https://github.com/tentaclelabs/prometheus_client

environment:
Expand Down

0 comments on commit 64cef4c

Please sign in to comment.