From ba26706aa54234c01f9cdf936a5eb049f8a5813c Mon Sep 17 00:00:00 2001 From: "tim.quinn@oracle.com" Date: Wed, 30 Nov 2022 14:20:17 -0600 Subject: [PATCH 1/6] Pass correct config to health providers during build of HealthFeature --- .../nima/observe/health/HealthFeature.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/nima/observe/health/src/main/java/io/helidon/nima/observe/health/HealthFeature.java b/nima/observe/health/src/main/java/io/helidon/nima/observe/health/HealthFeature.java index 96beee6f345..a47a1124dbf 100644 --- a/nima/observe/health/src/main/java/io/helidon/nima/observe/health/HealthFeature.java +++ b/nima/observe/health/src/main/java/io/helidon/nima/observe/health/HealthFeature.java @@ -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; @@ -139,6 +141,8 @@ public static class Builder extends HelidonFeatureSupport.Builder liveChecks = new ArrayList<>(); private final List startChecks = new ArrayList<>(); + private final List configs = new ArrayList<>(); + private boolean enabled = true; private boolean details = false; @@ -148,11 +152,17 @@ public static class Builder extends HelidonFeatureSupport.Builder 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); @@ -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); @@ -242,5 +253,12 @@ public Builder useSystemServices(boolean useServices) { providers.useSystemServiceLoader(useServices); return this; } + + private Config effectiveConfig() { + return Config.create(configs.stream() + .filter(Config::exists) + .map(ConfigSources::create) + .toArray(ConfigSource[]::new)); + } } } From 92a710ddb29bf490d17b240b048a52dba6ef9590 Mon Sep 17 00:00:00 2001 From: "tim.quinn@oracle.com" Date: Wed, 30 Nov 2022 14:54:36 -0600 Subject: [PATCH 2/6] Rework the effective config calculation a bit --- .../nima/observe/health/HealthFeature.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/nima/observe/health/src/main/java/io/helidon/nima/observe/health/HealthFeature.java b/nima/observe/health/src/main/java/io/helidon/nima/observe/health/HealthFeature.java index a47a1124dbf..af2314323ce 100644 --- a/nima/observe/health/src/main/java/io/helidon/nima/observe/health/HealthFeature.java +++ b/nima/observe/health/src/main/java/io/helidon/nima/observe/health/HealthFeature.java @@ -18,13 +18,18 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.ServiceLoader; +import java.util.function.Function; +import java.util.stream.Collectors; import io.helidon.common.HelidonServiceLoader; import io.helidon.config.Config; import io.helidon.config.ConfigSources; +import io.helidon.config.ConfigValue; import io.helidon.config.spi.ConfigSource; import io.helidon.health.HealthCheck; import io.helidon.health.HealthCheckType; @@ -255,10 +260,14 @@ public Builder useSystemServices(boolean useServices) { } private Config effectiveConfig() { - return Config.create(configs.stream() - .filter(Config::exists) - .map(ConfigSources::create) - .toArray(ConfigSource[]::new)); + + return Config.create(ConfigSources.create(configs.stream() + .map(Config::asMap) + .filter(ConfigValue::isPresent) + .map(ConfigValue::get) + .flatMap(map -> map.entrySet().stream()) + .collect(Collectors.toMap(Map.Entry::getKey, + Map.Entry::getValue)))); } } } From 220717ef56fcfd3bfab9680544a1724c5595d69b Mon Sep 17 00:00:00 2001 From: "tim.quinn@oracle.com" Date: Wed, 30 Nov 2022 14:56:23 -0600 Subject: [PATCH 3/6] Remove unused imports --- .../java/io/helidon/nima/observe/health/HealthFeature.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/nima/observe/health/src/main/java/io/helidon/nima/observe/health/HealthFeature.java b/nima/observe/health/src/main/java/io/helidon/nima/observe/health/HealthFeature.java index af2314323ce..0b5c5725ef1 100644 --- a/nima/observe/health/src/main/java/io/helidon/nima/observe/health/HealthFeature.java +++ b/nima/observe/health/src/main/java/io/helidon/nima/observe/health/HealthFeature.java @@ -18,19 +18,16 @@ import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.ServiceLoader; -import java.util.function.Function; import java.util.stream.Collectors; import io.helidon.common.HelidonServiceLoader; import io.helidon.config.Config; import io.helidon.config.ConfigSources; import io.helidon.config.ConfigValue; -import io.helidon.config.spi.ConfigSource; import io.helidon.health.HealthCheck; import io.helidon.health.HealthCheckType; import io.helidon.health.spi.HealthCheckProvider; From 2d35d8a7ed3f156eb45f3cf7d3a48a8da534cc07 Mon Sep 17 00:00:00 2001 From: "tim.quinn@oracle.com" Date: Wed, 30 Nov 2022 15:01:39 -0600 Subject: [PATCH 4/6] Further refine calc of effective config --- .../main/java/io/helidon/nima/observe/health/HealthFeature.java | 1 - 1 file changed, 1 deletion(-) diff --git a/nima/observe/health/src/main/java/io/helidon/nima/observe/health/HealthFeature.java b/nima/observe/health/src/main/java/io/helidon/nima/observe/health/HealthFeature.java index 0b5c5725ef1..d3feb0ab5dc 100644 --- a/nima/observe/health/src/main/java/io/helidon/nima/observe/health/HealthFeature.java +++ b/nima/observe/health/src/main/java/io/helidon/nima/observe/health/HealthFeature.java @@ -260,7 +260,6 @@ private Config effectiveConfig() { return Config.create(ConfigSources.create(configs.stream() .map(Config::asMap) - .filter(ConfigValue::isPresent) .map(ConfigValue::get) .flatMap(map -> map.entrySet().stream()) .collect(Collectors.toMap(Map.Entry::getKey, From 035a32fc5dff524f03fb980b03a4e06a199c0bb3 Mon Sep 17 00:00:00 2001 From: "tim.quinn@oracle.com" Date: Thu, 1 Dec 2022 07:21:59 -0600 Subject: [PATCH 5/6] Build the uber-config (if needed) from multiple config sources rather than a map --- .../io/helidon/nima/observe/health/HealthFeature.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/nima/observe/health/src/main/java/io/helidon/nima/observe/health/HealthFeature.java b/nima/observe/health/src/main/java/io/helidon/nima/observe/health/HealthFeature.java index d3feb0ab5dc..9bb18ee69f2 100644 --- a/nima/observe/health/src/main/java/io/helidon/nima/observe/health/HealthFeature.java +++ b/nima/observe/health/src/main/java/io/helidon/nima/observe/health/HealthFeature.java @@ -28,6 +28,7 @@ import io.helidon.config.Config; import io.helidon.config.ConfigSources; import io.helidon.config.ConfigValue; +import io.helidon.config.spi.ConfigSource; import io.helidon.health.HealthCheck; import io.helidon.health.HealthCheckType; import io.helidon.health.spi.HealthCheckProvider; @@ -258,12 +259,9 @@ public Builder useSystemServices(boolean useServices) { private Config effectiveConfig() { - return Config.create(ConfigSources.create(configs.stream() - .map(Config::asMap) - .map(ConfigValue::get) - .flatMap(map -> map.entrySet().stream()) - .collect(Collectors.toMap(Map.Entry::getKey, - Map.Entry::getValue)))); + return Config.create(configs.stream() + .map(ConfigSources::create) + .toArray(ConfigSource[]::new)); } } } From 35b2c15b3c6000f8e01fd083851aa30ccbe5bc2a Mon Sep 17 00:00:00 2001 From: "tim.quinn@oracle.com" Date: Thu, 1 Dec 2022 09:03:40 -0600 Subject: [PATCH 6/6] Remove unused imports --- .../java/io/helidon/nima/observe/health/HealthFeature.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/nima/observe/health/src/main/java/io/helidon/nima/observe/health/HealthFeature.java b/nima/observe/health/src/main/java/io/helidon/nima/observe/health/HealthFeature.java index 9bb18ee69f2..48a699be101 100644 --- a/nima/observe/health/src/main/java/io/helidon/nima/observe/health/HealthFeature.java +++ b/nima/observe/health/src/main/java/io/helidon/nima/observe/health/HealthFeature.java @@ -19,15 +19,12 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.Map; import java.util.Optional; import java.util.ServiceLoader; -import java.util.stream.Collectors; import io.helidon.common.HelidonServiceLoader; import io.helidon.config.Config; import io.helidon.config.ConfigSources; -import io.helidon.config.ConfigValue; import io.helidon.config.spi.ConfigSource; import io.helidon.health.HealthCheck; import io.helidon.health.HealthCheckType;