Skip to content

Commit

Permalink
Pass correct config to health providers (#5572)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjquinno authored Dec 6, 2022
1 parent 6502894 commit 9fa11b7
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

import io.helidon.common.HelidonServiceLoader;
import io.helidon.config.Config;
import io.helidon.config.ConfigSources;
import io.helidon.config.spi.ConfigSource;
import io.helidon.health.HealthCheck;
import io.helidon.health.HealthCheckType;
import io.helidon.health.spi.HealthCheckProvider;
Expand Down Expand Up @@ -139,6 +141,8 @@ public static class Builder extends HelidonFeatureSupport.Builder<Builder, Healt
private final List<HealthCheck> liveChecks = new ArrayList<>();
private final List<HealthCheck> startChecks = new ArrayList<>();

private final List<Config> configs = new ArrayList<>();

private boolean enabled = true;
private boolean details = false;

Expand All @@ -148,11 +152,17 @@ public static class Builder extends HelidonFeatureSupport.Builder<Builder, Healt

@Override
public HealthFeature build() {
// Optimize for the most common cases.
Config config =
switch (configs.size()) {
case 0 -> Config.empty();
case 1 -> configs.get(0);
default -> effectiveConfig();
};
providers.build()
.asList()
.stream()
// TODO use configuration
.map(provider -> provider.healthChecks(Config.empty()))
.map(provider -> provider.healthChecks(config))
.flatMap(Collection::stream)
.forEach(it -> addCheck(it, it.type()));
return new HealthFeature(this);
Expand Down Expand Up @@ -194,6 +204,7 @@ public Builder details(boolean details) {
*/
public Builder config(Config config) {
super.config(config);
configs.add(config);

config.get("enabled").asBoolean().ifPresent(this::enabled);
config.get("details").asBoolean().ifPresent(this::details);
Expand Down Expand Up @@ -242,5 +253,12 @@ public Builder useSystemServices(boolean useServices) {
providers.useSystemServiceLoader(useServices);
return this;
}

private Config effectiveConfig() {

return Config.create(configs.stream()
.map(ConfigSources::create)
.toArray(ConfigSource[]::new));
}
}
}

0 comments on commit 9fa11b7

Please sign in to comment.