use of io.helidon.metrics.api.RegistryFactory in project helidon by oracle.
the class MetricsSupport method postConfigureEndpoint.
/**
* Finish configuring metrics endpoint on the provided routing rules. This method
* just adds the endpoint {@code /metrics} (or appropriate one as
* configured). For simple routings, just register {@code MetricsSupport}
* instance. This method is exclusive to
* {@link #update(io.helidon.webserver.Routing.Rules)} (e.g. you should not
* use both, as otherwise you would register the endpoint twice)
*
* @param defaultRules routing rules for default routing (also accepts {@link io.helidon.webserver.Routing.Builder})
* @param serviceEndpointRoutingRules possibly different rules for the metrics endpoint routing
*/
@Override
protected void postConfigureEndpoint(Routing.Rules defaultRules, Routing.Rules serviceEndpointRoutingRules) {
// If metrics are disabled, the RegistryFactory will be the no-op, not the full-featured one.
if (rf instanceof io.helidon.metrics.RegistryFactory) {
io.helidon.metrics.RegistryFactory fullRF = (io.helidon.metrics.RegistryFactory) rf;
Registry app = fullRF.getARegistry(MetricRegistry.Type.APPLICATION);
PeriodicExecutor.start();
// register the metric registry and factory to be available to all
MetricsContextHandler metricsContextHandler = new MetricsContextHandler(app, rf);
defaultRules.any(metricsContextHandler);
if (defaultRules != serviceEndpointRoutingRules) {
serviceEndpointRoutingRules.any(metricsContextHandler);
}
configureVendorMetrics(null, defaultRules);
}
prepareMetricsEndpoints(context(), serviceEndpointRoutingRules);
}
use of io.helidon.metrics.api.RegistryFactory in project helidon by oracle.
the class TestDisableEntireRegistry method testVendorRegistryEnabled.
@Test
void testVendorRegistryEnabled() {
MetricsSettings metricsSettings = MetricsSettings.create(metricsConfig);
assertThat("Vendor registry is enabled", metricsSettings.registrySettings(MetricRegistry.Type.VENDOR).isEnabled(), is(true));
io.helidon.metrics.api.RegistryFactory registryFactory = RegistryFactory.create(metricsSettings);
MetricRegistry vendorRegistry = registryFactory.getRegistry(MetricRegistry.Type.VENDOR);
Counter vendorCounter = vendorRegistry.counter("shouldUpdate");
vendorCounter.inc();
assertThat("Counter in enabled vendor registry", vendorCounter.getCount(), is(1L));
}
use of io.helidon.metrics.api.RegistryFactory in project helidon by oracle.
the class TestSettingsAndConfig method checkRegistryWithEnabledConfig.
@Test
void checkRegistryWithEnabledConfig() {
Config metricsConfig = Config.just(ConfigSources.create(METRICS_ENABLED_SETTINGS)).get("metrics");
RegistryFactory registryFactory = RegistryFactory.create(metricsConfig);
MetricRegistry metricRegistry = registryFactory.getRegistry(MetricRegistry.Type.APPLICATION);
checkCounterValueAfterInc(metricRegistry, "counter-enabled-via-config", 1L);
}
use of io.helidon.metrics.api.RegistryFactory in project helidon by oracle.
the class TestSettingsAndConfig method checkRegistryWithDisabledSettings.
@Test
void checkRegistryWithDisabledSettings() {
MetricsSettings metricsSettings = MetricsSettings.builder().enabled(false).build();
RegistryFactory registryFactory = RegistryFactory.create(metricsSettings);
MetricRegistry metricRegistry = registryFactory.getRegistry(MetricRegistry.Type.APPLICATION);
checkCounterValueAfterInc(metricRegistry, "counter-disabled-via-settings", 0L);
}
use of io.helidon.metrics.api.RegistryFactory in project helidon by oracle.
the class TestDisabledMetrics method ensureRegistryFactoryIsMinimal.
@Test
void ensureRegistryFactoryIsMinimal() {
// Invoking getInstance() should retrieve the factory previously initialized as disabled.
RegistryFactory rf = RegistryFactory.getInstance();
assertThat("RegistryFactory type", rf, not(instanceOf(io.helidon.metrics.RegistryFactory.class)));
}
Aggregations