-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from csankhala/metrix_exposure_prefix
Added metricx.exposure.prefix configuration
- Loading branch information
Showing
4 changed files
with
97 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
plugins { | ||
id 'java' | ||
id 'maven' | ||
} | ||
|
||
group 'org.springframework.boot' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/java/org/springframework/metricx/config/MetricxConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.springframework.metricx.config; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import lombok.Getter; | ||
import lombok.NonNull; | ||
import lombok.Setter; | ||
|
||
@Configuration | ||
@Getter | ||
@Setter | ||
public class MetricxConfig { | ||
|
||
/** | ||
* IF exposurePrefix is configured 'counter' THEN | ||
* '/metricx' endpoint will publish metrics starting with 'counter only' | ||
* Default: empty, means publish all | ||
*/ | ||
@NonNull | ||
@Value("${metricx.exposure.prefix:}") | ||
private String exposurePrefix; | ||
} |
57 changes: 57 additions & 0 deletions
57
src/test/java/org/springframework/metricx/MetricxEndpointTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.springframework.metricx; | ||
|
||
import java.util.Map; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.springframework.metricx.config.MetricxConfig; | ||
|
||
import io.micrometer.core.instrument.simple.SimpleMeterRegistry; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertSame; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class MetricxEndpointTest { | ||
|
||
private MetricxEndpoint metricxEndpoint; | ||
private SimpleMeterRegistry registry; | ||
private MetricxConfig metricxConfig; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
registry = new SimpleMeterRegistry(); | ||
metricxConfig = new MetricxConfig(); | ||
metricxConfig.setExposurePrefix("counter"); | ||
metricxEndpoint = new MetricxEndpoint(registry, metricxConfig); | ||
} | ||
|
||
@Test | ||
public void metricx_shouldReturnEmptyMap_When_NoMetricRegistered() { | ||
assertTrue(metricxEndpoint.metricx().isEmpty()); | ||
} | ||
|
||
@Test | ||
public void metricx_shouldReturnAllMetricsRegistered() { | ||
registry.counter("counter.request.success").increment(); | ||
registry.counter("counter.request.fail").increment(); | ||
registry.counter("jvm.memory.used").increment(); | ||
|
||
Map<String, Double> metricx = metricxEndpoint.metricx(); | ||
assertSame(2, metricx.size()); | ||
assertEquals(1, metricx.get("counter.request.success").intValue()); | ||
assertEquals(1, metricx.get("counter.request.fail").intValue()); | ||
} | ||
|
||
@Test | ||
public void metricPattern() { | ||
registry.counter("counter.request.success").increment(); | ||
registry.counter("counter.response.success").increment(); | ||
registry.counter("jvm.memory.used").increment(); | ||
|
||
Map<String, Double> metricx = metricxEndpoint.metricPattern("counter.response.*"); | ||
|
||
assertSame(1, metricx.size()); | ||
assertEquals(1, metricx.get("counter.response.success").intValue()); | ||
} | ||
} |