Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Commit

Permalink
Treat gauge.update() parameter as new value, not delta (#463)
Browse files Browse the repository at this point in the history
In InMemoryMetricsFactory, upon updating the gauge, the argument
should be considered as the new value and not a variation to
the previous one. Resolves #459.

Signed-off-by: Mehrez Douaihy <[email protected]>
  • Loading branch information
mdouaihy authored and yurishkuro committed Jun 21, 2018
1 parent 331bc04 commit e76b6a9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public Gauge createGauge(final String name, final Map<String, String> tags) {
return new Gauge() {
@Override
public void update(long amount) {
value.addAndGet(amount);
value.getAndSet(amount);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,18 @@ public void metricNameIsUsedForGauge() {
}

@Test
public void gaugeValueIsIncreased() {
public void gaugeValueIsUpdated() {
Map<String, String> tags = Collections.singletonMap("foo", "bar");

InMemoryMetricsFactory inMemoryMetricsFactory = new InMemoryMetricsFactory();
Gauge gauge = inMemoryMetricsFactory.createGauge("thegauge", tags);
assertEquals(0, inMemoryMetricsFactory.getGauge("thegauge", tags));

gauge.update(1);

assertEquals(1, inMemoryMetricsFactory.getGauge("thegauge", tags));

gauge.update(2);
assertEquals(2, inMemoryMetricsFactory.getGauge("thegauge", tags));
}

@Test
Expand Down

0 comments on commit e76b6a9

Please sign in to comment.