@Test public void allRemotesAreUp() { when(PROM_REMOTE_1.isHealthy()).thenReturn("OK"); when(PROM_REMOTE_2.isHealthy()).thenReturn("OK"); 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.UP) .build())); }
@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 PrometheusNamedAccountCredentials) .map(credentials -> ((PrometheusNamedAccountCredentials) 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); }
PrometheusHealthJob { @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 PrometheusNamedAccountCredentials) .map(credentials -> ((PrometheusNamedAccountCredentials) 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); } }
PrometheusHealthJob { @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 PrometheusNamedAccountCredentials) .map(credentials -> ((PrometheusNamedAccountCredentials) 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); } PrometheusHealthJob(
      PrometheusConfigurationProperties prometheusConfigurationProperties,
      AccountCredentialsRepository accountCredentialsRepository,
      PrometheusHealthCache healthCache); }
PrometheusHealthJob { @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 PrometheusNamedAccountCredentials) .map(credentials -> ((PrometheusNamedAccountCredentials) 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); } PrometheusHealthJob(
      PrometheusConfigurationProperties prometheusConfigurationProperties,
      AccountCredentialsRepository accountCredentialsRepository,
      PrometheusHealthCache healthCache); @Scheduled( initialDelayString = "${kayenta.prometheus.health.initial-delay:PT2S}", fixedDelayString = "${kayenta.prometheus.health.fixed-delay:PT5M}") void run(); }
PrometheusHealthJob { @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 PrometheusNamedAccountCredentials) .map(credentials -> ((PrometheusNamedAccountCredentials) 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); } PrometheusHealthJob(
      PrometheusConfigurationProperties prometheusConfigurationProperties,
      AccountCredentialsRepository accountCredentialsRepository,
      PrometheusHealthCache healthCache); @Scheduled( initialDelayString = "${kayenta.prometheus.health.initial-delay:PT2S}", fixedDelayString = "${kayenta.prometheus.health.fixed-delay:PT5M}") void run();  }