Allow counter names like counter-foo
Checking for a prefix "counter." is more correct than "counter" because the readers (repositories) assume the former prefix is there. Fixes gh-3801
This commit is contained in:
parent
a01a5db947
commit
9303efd435
|
@ -58,7 +58,7 @@ public class DefaultCounterService implements CounterService {
|
||||||
if (this.names.containsKey(metricName)) {
|
if (this.names.containsKey(metricName)) {
|
||||||
return this.names.get(metricName);
|
return this.names.get(metricName);
|
||||||
}
|
}
|
||||||
if (metricName.startsWith("counter") || metricName.startsWith("meter")) {
|
if (metricName.startsWith("counter.") || metricName.startsWith("meter.")) {
|
||||||
return metricName;
|
return metricName;
|
||||||
}
|
}
|
||||||
String name = "counter." + metricName;
|
String name = "counter." + metricName;
|
||||||
|
|
|
@ -16,16 +16,16 @@
|
||||||
|
|
||||||
package org.springframework.boot.actuate.metrics.writer;
|
package org.springframework.boot.actuate.metrics.writer;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Captor;
|
import org.mockito.Captor;
|
||||||
import org.mockito.runners.MockitoJUnitRunner;
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link DefaultCounterService}.
|
* Tests for {@link DefaultCounterService}.
|
||||||
*/
|
*/
|
||||||
|
@ -40,6 +40,22 @@ public class DefaultCounterServiceTests {
|
||||||
@Captor
|
@Captor
|
||||||
private ArgumentCaptor<Delta<Number>> captor;
|
private ArgumentCaptor<Delta<Number>> captor;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void incrementWithExistingCounter() {
|
||||||
|
this.service.increment("counter.foo");
|
||||||
|
verify(this.repository).increment(this.captor.capture());
|
||||||
|
assertEquals("counter.foo", this.captor.getValue().getName());
|
||||||
|
assertEquals(1L, this.captor.getValue().getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void incrementWithExistingNearlyCounter() {
|
||||||
|
this.service.increment("counter-foo");
|
||||||
|
verify(this.repository).increment(this.captor.capture());
|
||||||
|
assertEquals("counter.counter-foo", this.captor.getValue().getName());
|
||||||
|
assertEquals(1L, this.captor.getValue().getValue());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void incrementPrependsCounter() {
|
public void incrementPrependsCounter() {
|
||||||
this.service.increment("foo");
|
this.service.increment("foo");
|
||||||
|
|
Loading…
Reference in New Issue