package io.bootique.jdbc.instrumented.healthcheck;

import io.bootique.jdbc.DataSourceFactory;
import io.bootique.metrics.health.HealthCheck;
import io.bootique.metrics.health.HealthCheckGroup;

import java.util.HashMap;
import java.util.Map;

/**
 * Generates individual healthchecks for a {@link io.bootique.jdbc.DataSourceFactory} DataSources. It is important to
 * report DataSource health individually.
 *
 * @since 0.12
 */
public class DataSourceHealthCheckGroup implements HealthCheckGroup {

    private DataSourceFactory dataSourceFactory;

    public DataSourceHealthCheckGroup(DataSourceFactory dataSourceFactory) {
        this.dataSourceFactory = dataSourceFactory;
    }

    @Override
    public Map<String, HealthCheck> getHealthChecks() {

        Map<String, HealthCheck> checks = new HashMap<>();

        // TODO: namespacing module healthchecks..
        dataSourceFactory.allNames().forEach(n -> {
            String hcName = healthCheckName(n);
            checks.put(hcName, new DataSourceHealthCheck(dataSourceFactory, hcName));
        });

        return checks;
    }

    // generate stable qualified name for the DataSource healthcheck
    private String healthCheckName(String dataSourceName) {
        return "bq.jdbc." + dataSourceName + ".canConnect";
    }
}

@@ -915,59 +915,13 @@
 n -%3E
- %7B
 %0A    
-        String hcName = healthCheckName(n);%0A
     
@@ -940,21 +940,33 @@
 ks.put(h
-c
+ealthCheck
 Name
+(n)
 , new Da
@@ -1008,27 +1008,11 @@
 ry, 
-hcName));%0A        %7D
+n))
 );%0A%0A

Rename healthcheck labels #66