Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make SE metrics default scope application instead of nothing #7666

Merged
merged 7 commits into from
Sep 26, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ curl -H 'Accept: application/json' -X GET http://localhost:8080/metrics

String output = response.as(String.class);

String expected = MetricsService.PERSONALIZED_GETS_COUNTER_NAME + "_total 1.0";
String expected = MetricsService.PERSONALIZED_GETS_COUNTER_NAME + "_total{scope=\"application\",} 1.0";
assertThat("Unable to find expected counter result " + expected + "; output is " + output,
output, containsString(expected));
response.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ interface ScopingConfigBlueprint {

/**
* Default scope value to associate with meters that are registered without an explicit setting; no setting means meters
* receive no default scope value.
* are assigned scope {@value io.helidon.metrics.api.Meter.Scope#DEFAULT}.
*
* @return default scope value
*/
@ConfiguredOption(key = "default")
@ConfiguredOption(key = "default", value = Meter.Scope.DEFAULT)
Optional<String> defaultValue();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,25 @@
import java.util.List;
import java.util.Set;

import io.helidon.common.testing.junit5.OptionalMatcher;
import io.helidon.metrics.api.Counter;
import io.helidon.metrics.api.Meter;
import io.helidon.metrics.api.MeterRegistry;
import io.helidon.metrics.api.Metrics;
import io.helidon.metrics.api.MetricsConfig;
import io.helidon.metrics.api.MetricsFactory;
import io.helidon.metrics.api.ScopingConfig;
import io.helidon.metrics.api.SystemTagsManager;
import io.helidon.metrics.api.Timer;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;

class TestScopeManagement {
Expand All @@ -42,7 +46,8 @@ class TestScopeManagement {
@ValueSource(booleans = {true, false})
void testExplicitScopeOnMetersWithNoDefaultScope(boolean scopeTagEnabled) {
MetricsConfig metricsConfig = MetricsConfig.builder()
.scoping(ScopingConfig.builder())
.scoping(ScopingConfig.builder()
.clearDefaultValue())
.build();
MeterRegistry reg = MetricsFactory.getInstance().globalRegistry();
SystemTagsManager.instance(metricsConfig);
Expand Down Expand Up @@ -127,4 +132,14 @@ void testExplicitScopeOnMetersWithDefaultScope(boolean scopeTagEnabled) {
hasItem((Meter) t1)
));
}

@Test
void checkDefaultScope() {
MetricsConfig metricsConfig = MetricsConfig.create(); // Make sure to use the defaults, not leftovers from earlier tests
MetricsFactory.getInstance().globalRegistry(metricsConfig);
SystemTagsManager.instance(metricsConfig);

Counter counter = Metrics.getOrCreate(Counter.builder("defaultScopedCounter"));
assertThat("Unspecified scope", counter.scope(), OptionalMatcher.optionalValue(is(Meter.Scope.DEFAULT)));
}
}