Refine search
@Override public void run(Configuration configuration, Environment environment) { final SimpleServerFactory serverConfig = new SimpleServerFactory(); configuration.setServerFactory(serverConfig); final HttpConnectorFactory connectorConfig = (HttpConnectorFactory) serverConfig.getConnector(); connectorConfig.setPort(0); environment.healthChecks().register("dummy", new DummyHealthCheck()); for (Object resource : resources) { if (resource instanceof Class<?>) { environment.jersey().register((Class<?>) resource); } else { environment.jersey().register(resource); } } } }
@Override public Integer getValue() { final SortedMap<String, HealthCheck.Result> results = registry.runHealthChecks(); return results.values().stream().allMatch(HealthCheck.Result::isHealthy) ? 1 : 0; } }
public static void registerTaskHealthCheck(int taskId, String name, HealthCheck healthCheck) { HealthCheckRegistry healthCheckRegister = taskHealthCheckMap.get(taskId); if (healthCheckRegister == null) { healthCheckRegister = new HealthCheckRegistry(); taskHealthCheckMap.put(taskId, healthCheckRegister); } healthCheckRegister.register(name, healthCheck); }
@Override public void register(String name, HealthCheck healthCheck) { super.unregister(name); super.register(name, healthCheck); }
@Override public void handle(final Request req, final Response rsp) throws Throwable { HealthCheckRegistry registry = req.require(HealthCheckRegistry.class); SortedMap<String, Result> checks = req.param("name").toOptional().map(name -> { SortedMap<String, Result> set = ImmutableSortedMap.of(name, registry.runHealthCheck(name)); return set; }).orElseGet(() -> registry.runHealthChecks()); final Status status; if (checks.isEmpty()) { status = Status.NOT_IMPLEMENTED; } else { status = checks.values().stream() .filter(it -> !it.isHealthy()) .findFirst() .map(it -> Status.SERVER_ERROR) .orElse(Status.OK); } rsp.status(status) .header("Cache-Control", "must-revalidate,no-cache,no-store") .send(checks); }
final MetricRegistry metricsRegistry = environment.metrics(); metricsRegistry.registerAll(new GarbageCollectorMetricSet()); metricsRegistry.registerAll(new MemoryUsageGaugeSet()); environment.lifecycle().manage(new ManagedStatsdReporter(config.getStatsdHostPort(), metricsRegistry)); attributesSupplier); environment.lifecycle().manage(reporter); environment.healthChecks().register("docker", dockerHealthChecker); environment.healthChecks().register("zookeeper", zkHealthChecker); environment.healthChecks().register("dockerd", dockerDaemonHealthChecker); environment.healthChecks().getNames().forEach( name -> environment.metrics().register( "helios." + name + ".ok", new HealthCheckGauge(environment.healthChecks(), name)));
private void runRegularGraphHopper(CmdArgs configuration, Environment environment) { final GraphHopperManaged graphHopperManaged = new GraphHopperManaged(configuration, environment.getObjectMapper()); environment.lifecycle().manage(graphHopperManaged); environment.jersey().register(new AbstractBinder() { @Override protected void configure() { bind(configuration).to(CmdArgs.class); bind(graphHopperManaged).to(GraphHopperManaged.class); bind(graphHopperManaged.getGraphHopper()).to(GraphHopper.class); bind(graphHopperManaged.getGraphHopper()).to(GraphHopperAPI.class); bindFactory(HasElevation.class).to(Boolean.class).named("hasElevation"); bindFactory(LocationIndexFactory.class).to(LocationIndex.class); bindFactory(TranslationMapFactory.class).to(TranslationMap.class); bindFactory(EncodingManagerFactory.class).to(EncodingManager.class); bindFactory(GraphHopperStorageFactory.class).to(GraphHopperStorage.class); bindFactory(RasterHullBuilderFactory.class).to(DelaunayTriangulationIsolineBuilder.class); } }); if (configuration.getBool("web.change_graph.enabled", false)) { environment.jersey().register(ChangeGraphResource.class); } environment.jersey().register(NearestResource.class); environment.jersey().register(RouteResource.class); environment.jersey().register(IsochroneResource.class); environment.jersey().register(I18NResource.class); environment.jersey().register(InfoResource.class); environment.healthChecks().register("graphhopper", new GraphHopperHealthCheck(graphHopperManaged.getGraphHopper())); }
throws Exception SharedMetricRegistries.add(Constants.METRICS_NAME, environment.metrics()); environment.getObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); environment.getObjectMapper().setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE); environment.getObjectMapper().setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); environment.healthChecks().register("directory", new RedisHealthCheck(directoryClient)); environment.healthChecks().register("cache", new RedisHealthCheck(cacheClient)); environment.jersey().register(new IOExceptionMapper());
environment.lifecycle().manage(dataSource); environment.healthChecks().register(name, new JdbiHealthCheck( environment.getHealthCheckExecutorService(), configuration.getValidationQueryTimeout().orElseGet(() -> Duration.seconds(5)), jdbi,
@Override public void run(MacroBaseConf configuration, Environment environment) throws Exception { configuration.loadSystemProperties(); environment.healthChecks().register("basic", new HealthCheck() { @Override protected Result check() throws Exception { return null; } }); } }
public static void registerWorkerHealthCheck(String name, HealthCheck healthCheck) { workerHealthCheck.register(name, healthCheck); }
@Override public void run(HelloWorldConfiguration configuration, Environment environment) { final PersonDAO dao = new PersonDAO(hibernateBundle.getSessionFactory()); final Template template = configuration.buildTemplate(); environment.healthChecks().register("template", new TemplateHealthCheck(template)); environment.admin().addTask(new EchoTask()); environment.jersey().register(DateRequiredFeature.class); environment.jersey().register(new AuthDynamicFeature(new BasicCredentialAuthFilter.Builder<User>() .setAuthenticator(new ExampleAuthenticator()) .setAuthorizer(new ExampleAuthorizer()) .setRealm("SUPER SECRET STUFF") .buildAuthFilter())); environment.jersey().register(new AuthValueFactoryProvider.Binder<>(User.class)); environment.jersey().register(RolesAllowedDynamicFeature.class); environment.jersey().register(new HelloWorldResource(template)); environment.jersey().register(new ViewResource()); environment.jersey().register(new ProtectedResource()); environment.jersey().register(new PeopleResource(dao)); environment.jersey().register(new PersonResource(dao)); environment.jersey().register(new FilteredResource()); } }
public static ManagedAwsS3ClientStorage buildStorage(RequestLogUploadConfiguration uploadConfiguration, Environment environment, Map<String,String> propertyOverrides) { ManagedAwsS3ClientStorage storage = new ManagedAwsS3ClientStorage(uploadConfiguration.getAWSCredentialsProvider().getCredentials()); environment.lifecycle().manage(storage); environment.healthChecks().register("Amazon S3",storage.healthCheck()); return storage; }
@Override public final void run(T configuration, Environment environment) throws Exception { final PooledDataSourceFactory dbConfig = getDataSourceFactory(configuration); this.sessionFactory = requireNonNull(sessionFactoryFactory.build(this, environment, dbConfig, entities, name())); registerUnitOfWorkListenerIfAbsent(environment).registerSessionFactory(name(), sessionFactory); environment.healthChecks().register(name(), new SessionFactoryHealthCheck( environment.getHealthCheckExecutorService(), dbConfig.getValidationQueryTimeout().orElse(Duration.seconds(5)), sessionFactory, dbConfig.getValidationQuery())); }
@Override public Map<String, HealthCheck.Result> runHealthChecks() { return _environment.healthChecks().runHealthChecks(); } }
@Test public void itAddsProvidedHealthCheck() { assertThat(environment.healthChecks().getNames()) .containsOnlyOnce(ProvidedHealthCheck.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); } }
/** * Creates an environment with default health check registry */ public Environment(String name, ObjectMapper objectMapper, Validator validator, MetricRegistry metricRegistry, @Nullable ClassLoader classLoader) { this(name, objectMapper, validator, metricRegistry, classLoader, new HealthCheckRegistry()); }
@Override public Object watch(Map<String, Object> params) { Object key = checkNotNull(params).get(Constants.KEY); if (key == null) { SortedMap<String, HealthCheck.Result> healthChecks = healthCheckRegistry.runHealthChecks(); boolean isAllOk = true; for (HealthCheck.Result singleResult : healthChecks.values()) { if (!singleResult.isHealthy()) { isAllOk = false; break; } } Map<String, Object> result = Maps.newHashMap(); result.put("healthy", isAllOk); result.put("healthChecks", healthChecks); return result; } else { if (!healthCheckRegistry.getNames().contains(key.toString())) { return Collections.emptyMap(); } return healthCheckRegistry.runHealthCheck(key.toString()); } }
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()); } }