Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass correct config to health providers #5572

Merged
merged 6 commits into from
Dec 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}
}
}