@Scheduled(
      initialDelayString = "${kayenta.prometheus.health.initial-delay:PT2S}",
      fixedDelayString = "${kayenta.prometheus.health.fixed-delay:PT5M}")
  public void run() {
    List<PrometheusHealthStatus> healthStatuses =
        prometheusConfigurationProperties.getAccounts().stream()
            .map(
                account -> {
                  String name = account.getName();
                  return accountCredentialsRepository.getOne(name);
                })
            .filter(Optional::isPresent)
            .map(Optional::get)
            .filter(credentials -> credentials instanceof PrometheusManagedAccount)
            .map(credentials -> ((PrometheusManagedAccount) credentials))
            .map(
                credentials -> {
                  try {
                    PrometheusRemoteService remote = credentials.getPrometheusRemoteService();
                    remote.isHealthy();
                    return PrometheusHealthStatus.builder()
                        .accountName(credentials.getName())
                        .status(Status.UP)
                        .build();
                  } catch (Throwable ex) {
                    log.warn(
                        "Prometheus health FAILED for account: {} with exception: ",
                        credentials.getName(),
                        ex);
                    return PrometheusHealthStatus.builder()
                        .accountName(credentials.getName())
                        .status(Status.DOWN)
                        .errorDetails(ex.getClass().getName() + ": " + ex.getMessage())
                        .build();
                  }
                })
            .collect(Collectors.toList());
    healthCache.setHealthStatuses(healthStatuses);
  }
@Test
  public void oneRemoteIsDown() {
    when(PROM_REMOTE_1.isHealthy()).thenReturn("OK");
    when(PROM_REMOTE_2.isHealthy()).thenThrow(new RuntimeException("test 2"));

    healthJob.run();

    verify(healthCache)
        .setHealthStatuses(
            Arrays.asList(
                PrometheusHealthJob.PrometheusHealthStatus.builder()
                    .accountName(PROM_ACCOUNT_1)
                    .status(Status.UP)
                    .build(),
                PrometheusHealthJob.PrometheusHealthStatus.builder()
                    .accountName(PROM_ACCOUNT_2)
                    .status(Status.DOWN)
                    .errorDetails("java.lang.RuntimeException: test 2")
                    .build()));
  }