Search in sources :

Example 1 with RegistryFactory

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);
}
Also used : RegistryFactory(io.helidon.metrics.api.RegistryFactory) MetricRegistry(org.eclipse.microprofile.metrics.MetricRegistry)

Example 2 with RegistryFactory

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));
}
Also used : Counter(org.eclipse.microprofile.metrics.Counter) RegistryFactory(io.helidon.metrics.api.RegistryFactory) MetricRegistry(org.eclipse.microprofile.metrics.MetricRegistry) MetricsSettings(io.helidon.metrics.api.MetricsSettings) Test(org.junit.jupiter.api.Test)

Example 3 with RegistryFactory

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);
}
Also used : RegistryFactory(io.helidon.metrics.api.RegistryFactory) Config(io.helidon.config.Config) MetricRegistry(org.eclipse.microprofile.metrics.MetricRegistry) Test(org.junit.jupiter.api.Test)

Example 4 with RegistryFactory

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);
}
Also used : RegistryFactory(io.helidon.metrics.api.RegistryFactory) MetricRegistry(org.eclipse.microprofile.metrics.MetricRegistry) MetricsSettings(io.helidon.metrics.api.MetricsSettings) Test(org.junit.jupiter.api.Test)

Example 5 with RegistryFactory

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)));
}
Also used : RegistryFactory(io.helidon.metrics.api.RegistryFactory) Test(org.junit.jupiter.api.Test) HelidonTest(io.helidon.microprofile.tests.junit5.HelidonTest)

Aggregations

RegistryFactory (io.helidon.metrics.api.RegistryFactory)6 MetricRegistry (org.eclipse.microprofile.metrics.MetricRegistry)5 Test (org.junit.jupiter.api.Test)5 MetricsSettings (io.helidon.metrics.api.MetricsSettings)3 Counter (org.eclipse.microprofile.metrics.Counter)2 Config (io.helidon.config.Config)1 HelidonTest (io.helidon.microprofile.tests.junit5.HelidonTest)1