private void logHealthChecks() { if (healthChecks.getNames().size() <= 1) { LOGGER.warn(String.format( "%n" + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!%n" + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!%n" + "! THIS APPLICATION HAS NO HEALTHCHECKS. THIS MEANS YOU WILL NEVER KNOW !%n" + "! IF IT DIES IN PRODUCTION, WHICH MEANS YOU WILL NEVER KNOW IF YOU'RE !%n" + "! LETTING YOUR USERS DOWN. YOU SHOULD ADD A HEALTHCHECK FOR EACH OF YOUR !%n" + "! APPLICATION'S DEPENDENCIES WHICH FULLY (BUT LIGHTLY) TESTS IT. !%n" + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!%n" + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" )); } LOGGER.debug("health checks = {}", healthChecks.getNames()); } }
@Before public void before() { when(configuration.getConfig(CorePlugin.class)).thenReturn(corePlugin); when(corePlugin.isStagemonitorActive()).thenReturn(true); Stagemonitor.reset(); Stagemonitor.setConfiguration(configuration); // assertFalse(Stagemonitor.isStarted()); for (String name : healthCheckRegistry.getNames()) { healthCheckRegistry.unregister(name); } }
@After public void after() { Stagemonitor.reset(); for (String name : healthCheckRegistry.getNames()) { healthCheckRegistry.unregister(name); } }
@Test public void testStartMonitoringNotActive() throws Exception { when(corePlugin.isStagemonitorActive()).thenReturn(false); final MeasurementSession measurementSession = new MeasurementSession("StagemonitorTest", "testHost", "testInstance"); Stagemonitor.reset(measurementSession); assertTrue(Stagemonitor.isDisabled()); assertFalse(Stagemonitor.isStarted()); assertTrue(Stagemonitor.getMeasurementSession().isInitialized()); assertThat(healthCheckRegistry.getNames()).doesNotContain("TestPlugin", "TestExceptionPlugin"); }
environment.healthChecks().getNames().forEach( name -> environment.metrics().register( "helios." + name + ".ok", new HealthCheckGauge(environment.healthChecks(), name)));
private void logHealthChecks() { if (healthChecks.getNames().size() <= 1) { LOGGER.warn(String.format( "%n" + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!%n" + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!%n" + "! THIS APPLICATION HAS NO HEALTHCHECKS. THIS MEANS YOU WILL NEVER KNOW !%n" + "! IF IT DIES IN PRODUCTION, WHICH MEANS YOU WILL NEVER KNOW IF YOU'RE !%n" + "! LETTING YOUR USERS DOWN. YOU SHOULD ADD A HEALTHCHECK FOR EACH OF YOUR !%n" + "! APPLICATION'S DEPENDENCIES WHICH FULLY (BUT LIGHTLY) TESTS IT. !%n" + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!%n" + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" )); } LOGGER.debug("health checks = {}", healthChecks.getNames()); } }
environment.healthChecks().getNames().forEach( name -> environment.metrics().register( "helios." + name + ".ok", new HealthCheckGauge(environment.healthChecks(), name)));
/** * Returns a set of the names of all registered health checks. * * @return the names of all registered health checks */ public static SortedSet<String> getHealthNames() { return healthMetrics.getNames(); }
public Set<String> getHealthCheckNames() { return healthCheckRegistry.getNames(); }
@Override public Stream<Metric> registered() { return healthCheckRegistry.getNames().stream().map( name -> new MetricsHealthCheck() { @Override public Result check() throws Exception { return CodahaleHealthCheck.wrap( healthCheckRegistry.runHealthCheck( name ) ); } }); } };
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { rejectedExecutions.incrementAndGet(); // copied from DiscardOldestPolicy to ensure health check gets cancelled if (!executor.isShutdown()) { LOGGER.log(Level.WARNING, "Execution of health check was rejected:" + " {0}, queue size={1}, health checks={2} ({3})", new Object[]{ executor, executor.getQueue().size(), healthCheckRegistry.getNames(), healthCheckRegistry.getNames().size() }); dropOldestInQueue(executor, healthCheckRegistry); executor.execute(r); } } }
public Integer getValue() { return healthCheckRegistry().getNames().size(); } };
/** * Checks if Hikari CP health checks are already registered. * * @param poolName The Hikari CP name. Must not be * {@code null}. * @param healthCheckRegistry The health check registry. Must not be * {@code null}. * * @return {@code true} if the Hikari CP health checks are already * registered. */ static boolean healthChecksAlreadyRegistered(final HikariPoolName poolName, final HealthCheckRegistry healthCheckRegistry) { for (String checkName: healthCheckRegistry.getNames()) { // simple test if (checkName.contains(poolName.toString()) && checkName.contains("pool.ConnectivityCheck")) { return true; } } return false; }
@GET @Path("/{metric-name}") public MonitorResponse get(@PathParam("metric-name") String metricName) { final Metric metric = metrics.getMetrics().get(metricName); if (metric != null) { return toResponse(metricName, metric); } if (health.getNames().contains(metricName)) { return toResponse(metricName, health.runHealthCheck(metricName)); } return null; }
public HealthChecksThreadPool(HealthCheckRegistry healthCheckRegistry) { super(MAX_THREAD_POOL_SIZE, MAX_THREAD_POOL_SIZE, 5L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), // new ExceptionCatchingThreadFactory(new DaemonThreadFactory(new ThreadFactory() { private final AtomicInteger number = new AtomicInteger(); public Thread newThread(Runnable r) { return new Thread(r, "Metrics-HealthChecks-" + number.incrementAndGet()); } })), new MetricsRejectedExecutionHandler(healthCheckRegistry)); this.allowCoreThreadTimeOut(true); // allow stopping all threads if idle this.healthCheckRegistry = healthCheckRegistry; LOGGER.log(Level.FINE, "Created thread pool with a max of {0} threads (plus {1} in queue) for {2} health checks", new Object[] { getMaximumPoolSize(), Math.max(0, healthCheckRegistry.getNames().size() + 1 - getMaximumPoolSize()), healthCheckRegistry.getNames().size() }); }
@Test public void itAddsProvidedHealthCheck() { assertThat(environment.healthChecks().getNames()) .containsOnlyOnce(ProvidedHealthCheck.class.getSimpleName()); }
/** * {@inheritDoc} */ @Override public void stop() throws Exception { if (filter != null) { PluginServletFilter.removeFilter(filter); } metricRegistry.removeMatching(MetricFilter.ALL); for (String name : healthCheckRegistry.getNames()) { healthCheckRegistry.unregister(name); } if (jmxReporter!=null) { jmxReporter.stop(); jmxReporter = null; } }
@Test public void itAddsBoundHealthCheck() { assertThat(environment.healthChecks().getNames()) .containsOnlyOnce(InjectedHealthCheck.class.getSimpleName()); }
/** * Registers, updates or unregisters a health check. * * @param name The health check name. If {@code null} the method will * return immediately. * @param check The health check, {@code null} to unregister. If a * metric with the same name exists it will be replaced. */ public static void register(final String name, final HealthCheck check) { if (name == null) { return; } if (check != null) { if (getHealthCheckRegistry().getNames().contains(name)) { // remove previously registered check with same name getHealthCheckRegistry().unregister(name); } getHealthCheckRegistry().register(name, check); } else { getHealthCheckRegistry().unregister(name); } }
@Test public void addInjectableHealthChecks() { //when autoConfig.run(environment, injector); // then SortedSet<String> healthChecks = environment.healthChecks().getNames(); assertThat(healthChecks).contains(new InjectedHealthCheck().getName()); }