Search in sources :

Example 16 with HealthCheckRegistry

use of com.codahale.metrics.health.HealthCheckRegistry in project incubator-myriad by apache.

the class Main method initHealthChecks.

/**
 * Initializes health checks.
 *
 * @param injector
 */
private void initHealthChecks(Injector injector) {
    LOGGER.info("Initializing HealthChecks");
    healthCheckRegistry = new HealthCheckRegistry();
    healthCheckRegistry.register(MesosMasterHealthCheck.NAME, injector.getInstance(MesosMasterHealthCheck.class));
    healthCheckRegistry.register(ZookeeperHealthCheck.NAME, injector.getInstance(ZookeeperHealthCheck.class));
    healthCheckRegistry.register(MesosDriverHealthCheck.NAME, injector.getInstance(MesosDriverHealthCheck.class));
}
Also used : MesosMasterHealthCheck(org.apache.myriad.health.MesosMasterHealthCheck) HealthCheckRegistry(com.codahale.metrics.health.HealthCheckRegistry) MesosDriverHealthCheck(org.apache.myriad.health.MesosDriverHealthCheck) ZookeeperHealthCheck(org.apache.myriad.health.ZookeeperHealthCheck)

Example 17 with HealthCheckRegistry

use of com.codahale.metrics.health.HealthCheckRegistry in project HikariCP by brettwooldridge.

the class TestMetrics method testHealthChecks.

@Test
public void testHealthChecks() throws Exception {
    MetricRegistry metricRegistry = new MetricRegistry();
    HealthCheckRegistry healthRegistry = new HealthCheckRegistry();
    HikariConfig config = new HikariConfig();
    config.setMaximumPoolSize(10);
    config.setMetricRegistry(metricRegistry);
    config.setHealthCheckRegistry(healthRegistry);
    config.setPoolName("test");
    config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
    config.addHealthCheckProperty("connectivityCheckTimeoutMs", "1000");
    config.addHealthCheckProperty("expected99thPercentileMs", "100");
    try (HikariDataSource ds = new HikariDataSource(config)) {
        UtilityElf.quietlySleep(TimeUnit.SECONDS.toMillis(2));
        Connection connection = ds.getConnection();
        connection.close();
        connection = ds.getConnection();
        connection.close();
        SortedMap<String, Result> healthChecks = healthRegistry.runHealthChecks();
        Result connectivityResult = healthChecks.get("test.pool.ConnectivityCheck");
        Assert.assertTrue(connectivityResult.isHealthy());
        Result slaResult = healthChecks.get("test.pool.Connection99Percent");
        Assert.assertTrue(slaResult.isHealthy());
    }
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) MetricRegistry(com.codahale.metrics.MetricRegistry) HealthCheckRegistry(com.codahale.metrics.health.HealthCheckRegistry) Connection(java.sql.Connection) HikariConfig(com.zaxxer.hikari.HikariConfig) Result(com.codahale.metrics.health.HealthCheck.Result) Test(org.junit.Test)

Example 18 with HealthCheckRegistry

use of com.codahale.metrics.health.HealthCheckRegistry in project HikariCP by brettwooldridge.

the class TestMetrics method testSetters2.

@Test
public void testSetters2() throws Exception {
    HikariDataSource ds = new HikariDataSource();
    ds.setMaximumPoolSize(1);
    ds.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
    MetricRegistry metricRegistry = new MetricRegistry();
    HealthCheckRegistry healthRegistry = new HealthCheckRegistry();
    ds.setMetricRegistry(metricRegistry);
    ds.setHealthCheckRegistry(healthRegistry);
    // before the pool is started, we can set it any number of times...
    ds.setMetricRegistry(metricRegistry);
    ds.setHealthCheckRegistry(healthRegistry);
    try {
        Connection connection = ds.getConnection();
        connection.close();
        // after the pool is started, we cannot set it any more
        ds.setMetricRegistry(metricRegistry);
        Assert.fail("Should not have been allowed to set registry after pool started");
    } catch (IllegalStateException ise) {
    // pass
    } finally {
        ds.close();
    }
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) MetricRegistry(com.codahale.metrics.MetricRegistry) HealthCheckRegistry(com.codahale.metrics.health.HealthCheckRegistry) Connection(java.sql.Connection) Test(org.junit.Test)

Example 19 with HealthCheckRegistry

use of com.codahale.metrics.health.HealthCheckRegistry in project helios by spotify.

the class TotalHealthCheckGaugeTest method testOneFails.

@Test
public void testOneFails() {
    final HealthCheckRegistry registry = new HealthCheckRegistry();
    registry.register("pass1", stubHealthCheck(HealthCheck.Result.healthy()));
    registry.register("fail1", stubHealthCheck(HealthCheck.Result.unhealthy("error")));
    final TotalHealthCheckGauge gauge = new TotalHealthCheckGauge(registry);
    assertThat(gauge.getValue(), is(0));
}
Also used : HealthCheckRegistry(com.codahale.metrics.health.HealthCheckRegistry) Test(org.junit.Test)

Example 20 with HealthCheckRegistry

use of com.codahale.metrics.health.HealthCheckRegistry in project helios by spotify.

the class TotalHealthCheckGaugeTest method testAllHealthy.

@Test
public void testAllHealthy() {
    final HealthCheckRegistry registry = new HealthCheckRegistry();
    registry.register("pass1", stubHealthCheck(HealthCheck.Result.healthy()));
    registry.register("pass2", stubHealthCheck(HealthCheck.Result.healthy()));
    final TotalHealthCheckGauge gauge = new TotalHealthCheckGauge(registry);
    assertThat(gauge.getValue(), is(1));
}
Also used : HealthCheckRegistry(com.codahale.metrics.health.HealthCheckRegistry) Test(org.junit.Test)

Aggregations

HealthCheckRegistry (com.codahale.metrics.health.HealthCheckRegistry)31 Test (org.junit.Test)11 MetricRegistry (com.codahale.metrics.MetricRegistry)6 HealthCheck (com.codahale.metrics.health.HealthCheck)6 Test (org.junit.jupiter.api.Test)6 HikariDataSource (com.zaxxer.hikari.HikariDataSource)3 ServletContext (jakarta.servlet.ServletContext)3 ServletContext (javax.servlet.ServletContext)3 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)2 LoggingEvent (ch.qos.logback.classic.spi.LoggingEvent)2 Result (com.codahale.metrics.health.HealthCheck.Result)2 HealthCheckFilter (com.codahale.metrics.health.HealthCheckFilter)2 HealthCheckModule (com.codahale.metrics.json.HealthCheckModule)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ServletConfig (jakarta.servlet.ServletConfig)2 Connection (java.sql.Connection)2 ExecutorService (java.util.concurrent.ExecutorService)2 Connector (org.eclipse.jetty.server.Connector)2 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)2 Server (org.eclipse.jetty.server.Server)2