Search in sources :

Example 1 with Gauge

use of io.prometheus.client.Gauge in project verify-hub by alphagov.

the class PrometheusClient method createMatchingServiceHealthCheckMetrics.

public void createMatchingServiceHealthCheckMetrics() {
    final PrometheusClientServiceConfiguration configuration = samlSoapProxyConfiguration.getMatchingServiceHealthCheckServiceConfiguration();
    if (configuration.getEnable()) {
        Gauge healthStatusGauge = Gauge.build(VERIFY_SAML_SOAP_PROXY_MSA_HEALTH_STATUS, VERIFY_SAML_SOAP_PROXY_MSA_HEALTH_STATUS_HELP).labelNames("matchingService").register();
        Gauge healthStatusLastUpdatedGauge = Gauge.build(VERIFY_SAML_SOAP_PROXY_MSA_HEALTH_STATUS_LAST_UPDATED, VERIFY_SAML_SOAP_PROXY_MSA_HEALTH_STATUS_LAST_UPDATED_HELP).labelNames("matchingService").register();
        MatchingServiceInfoMetric infoMetric = new MatchingServiceInfoMetric().register();
        ExecutorService matchingServiceHealthCheckTaskManager = environment.lifecycle().executorService(MSA_HEALTH_CHECK_TASK_MANAGER).threadFactory(new ThreadFactoryBuilder().setNameFormat(MSA_HEALTH_CHECK_TASK_MANAGER).setDaemon(USE_DAEMON_THREADS).build()).minThreads(configuration.getMinNumOfThreads()).maxThreads(configuration.getMaxNumOfThreads()).keepAliveTime(configuration.getKeepAliveTime()).workQueue(new SynchronousQueue<>()).build();
        MatchingServiceHealthCheckService matchingServiceHealthCheckService = new MatchingServiceHealthCheckService(matchingServiceHealthCheckTaskManager, samlSoapProxyConfiguration.getHealthCheckSoapHttpClient().getTimeout(), matchingServiceConfigProxy, matchingServiceHealthChecker, healthStatusGauge, healthStatusLastUpdatedGauge, infoMetric);
        createScheduledExecutorService(configuration, VERIFY_SAML_SOAP_PROXY_MSA_HEALTH_STATUS, matchingServiceHealthCheckService);
    }
}
Also used : MatchingServiceInfoMetric(uk.gov.ida.hub.samlsoapproxy.service.MatchingServiceInfoMetric) SynchronousQueue(java.util.concurrent.SynchronousQueue) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) PrometheusClientServiceConfiguration(uk.gov.ida.hub.samlsoapproxy.config.PrometheusClientServiceConfiguration) MatchingServiceHealthCheckService(uk.gov.ida.hub.samlsoapproxy.service.MatchingServiceHealthCheckService) Gauge(io.prometheus.client.Gauge)

Example 2 with Gauge

use of io.prometheus.client.Gauge in project verify-hub by alphagov.

the class PrometheusClientService method createCertificateExpiryDateCheckMetrics.

public void createCertificateExpiryDateCheckMetrics() {
    final PrometheusClientServiceConfiguration configuration = configConfiguration.getCertificateExpiryDateCheckServiceConfiguration();
    if (configuration.getEnable()) {
        Gauge expiryDateGauge = Gauge.build(VERIFY_CONFIG_CERTIFICATE_EXPIRY_DATE, VERIFY_CONFIG_CERTIFICATE_EXPIRY_DATE_HELP).labelNames("entity_id", "use", "subject", "fingerprint", "serial").register();
        Gauge lastUpdatedGauge = Gauge.build(VERIFY_CONFIG_CERTIFICATE_EXPIRY_DATE_LAST_UPDATED, VERIFY_CONFIG_CERTIFICATE_EXPIRY_DATE_LAST_UPDATED_HELP).register();
        CertificateExpiryDateCheckService certificateExpiryDateCheckService = new CertificateExpiryDateCheckService(certificateService, expiryDateGauge, lastUpdatedGauge);
        createScheduledExecutorService(configuration, VERIFY_CONFIG_CERTIFICATE_EXPIRY_DATE, certificateExpiryDateCheckService);
    }
}
Also used : PrometheusClientServiceConfiguration(uk.gov.ida.hub.config.configuration.PrometheusClientServiceConfiguration) Gauge(io.prometheus.client.Gauge)

Example 3 with Gauge

use of io.prometheus.client.Gauge in project verify-hub by alphagov.

the class PrometheusClientService method createCertificateOcspRevocationStatusCheckMetrics.

public void createCertificateOcspRevocationStatusCheckMetrics() {
    final PrometheusClientServiceConfiguration configuration = configConfiguration.getCertificateOcspRevocationStatusCheckServiceConfiguration();
    if (configuration.getEnable()) {
        Gauge ocspStatusGauge = Gauge.build(VERIFY_CONFIG_CERTIFICATE_OCSP_REVOCATION_STATUS, VERIFY_CONFIG_CERTIFICATE_OCSP_REVOCATION_STATUS_HELP).labelNames("entity_id", "use", "subject", "fingerprint", "serial").register();
        Gauge lastUpdatedGauge = Gauge.build(VERIFY_CONFIG_CERTIFICATE_OCSP_LAST_SUCCESS_TIMESTAMP, VERIFY_CONFIG_CERTIFICATE_OCSP_LAST_SUCCESS_TIMESTAMP_HELP).labelNames("entity_id", "use", "subject", "fingerprint", "serial").register();
        OcspCertificateChainValidationService ocspCertificateChainValidationService = new OcspCertificateChainValidationService(ocspCertificateChainValidityChecker, certificateService, ocspStatusGauge, lastUpdatedGauge);
        createScheduledExecutorService(configuration, VERIFY_CONFIG_CERTIFICATE_OCSP_REVOCATION_STATUS, ocspCertificateChainValidationService);
    }
}
Also used : PrometheusClientServiceConfiguration(uk.gov.ida.hub.config.configuration.PrometheusClientServiceConfiguration) Gauge(io.prometheus.client.Gauge)

Example 4 with Gauge

use of io.prometheus.client.Gauge in project verify-hub by alphagov.

the class OcspCertificateChainValidationServiceTest method gaugesAreUpdatedForCertsWithValidChains.

@Test
public void gaugesAreUpdatedForCertsWithValidChains() throws Exception {
    Gauge ocspStatusGauge = Gauge.build("ocspStatusGauge", "whatever").labelNames("entity_id", "use", "subject", "fingerprint", "serial").create();
    Gauge lastUpdatedGauge = Gauge.build("lastUpdatedGauge", "whatever").labelNames("entity_id", "use", "subject", "fingerprint", "serial").create();
    OcspCertificateChainValidationService ocspCertificateChainValidationService = new OcspCertificateChainValidationService(ocspCertificateChainValidityChecker, certificateService, ocspStatusGauge, lastUpdatedGauge);
    // Check gauges are initially set to zero.
    assertThat(getGaugeValue(ocspStatusGauge, cert1)).isEqualTo(0);
    assertThat(getGaugeValue(ocspStatusGauge, cert2)).isEqualTo(0);
    assertThat(getGaugeValue(ocspStatusGauge, cert3)).isEqualTo(0);
    assertThat(getGaugeValue(lastUpdatedGauge, cert1)).isEqualTo(0);
    assertThat(getGaugeValue(lastUpdatedGauge, cert2)).isEqualTo(0);
    assertThat(getGaugeValue(lastUpdatedGauge, cert3)).isEqualTo(0);
    // Run the service and check gauges.
    when(certificateService.getAllCertificates()).thenReturn(Set.of(cert1, cert2, cert3));
    when(ocspCertificateChainValidityChecker.isValid(cert1)).thenReturn(true);
    when(ocspCertificateChainValidityChecker.isValid(cert2)).thenReturn(true);
    when(ocspCertificateChainValidityChecker.isValid(cert3)).thenReturn(false);
    ocspCertificateChainValidationService.run();
    assertThat(getGaugeValue(ocspStatusGauge, cert1)).isEqualTo(1);
    assertThat(getGaugeValue(ocspStatusGauge, cert2)).isEqualTo(1);
    assertThat(getGaugeValue(ocspStatusGauge, cert3)).isEqualTo(0);
    assertThat(getGaugeValue(lastUpdatedGauge, cert1)).isGreaterThan(0);
    assertThat(getGaugeValue(lastUpdatedGauge, cert2)).isGreaterThan(0);
    assertThat(getGaugeValue(lastUpdatedGauge, cert3)).isEqualTo(0);
    // Make cert2 invalid and run the service again.
    when(ocspCertificateChainValidityChecker.isValid(cert2)).thenReturn(false);
    ocspCertificateChainValidationService.run();
    assertThat(getGaugeValue(ocspStatusGauge, cert1)).isEqualTo(1);
    assertThat(getGaugeValue(ocspStatusGauge, cert2)).isEqualTo(0);
    assertThat(getGaugeValue(ocspStatusGauge, cert3)).isEqualTo(0);
    assertThat(getGaugeValue(lastUpdatedGauge, cert1)).isGreaterThan(0);
    assertThat(getGaugeValue(lastUpdatedGauge, cert2)).isGreaterThan(0);
    assertThat(getGaugeValue(lastUpdatedGauge, cert3)).isEqualTo(0);
}
Also used : Gauge(io.prometheus.client.Gauge) Test(org.junit.jupiter.api.Test)

Aggregations

Gauge (io.prometheus.client.Gauge)4 PrometheusClientServiceConfiguration (uk.gov.ida.hub.config.configuration.PrometheusClientServiceConfiguration)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 ExecutorService (java.util.concurrent.ExecutorService)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 SynchronousQueue (java.util.concurrent.SynchronousQueue)1 Test (org.junit.jupiter.api.Test)1 PrometheusClientServiceConfiguration (uk.gov.ida.hub.samlsoapproxy.config.PrometheusClientServiceConfiguration)1 MatchingServiceHealthCheckService (uk.gov.ida.hub.samlsoapproxy.service.MatchingServiceHealthCheckService)1 MatchingServiceInfoMetric (uk.gov.ida.hub.samlsoapproxy.service.MatchingServiceInfoMetric)1