From 71f79092e8febab8b4ed7e34a29d3f0f9b268053 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Thu, 22 Feb 2024 13:01:44 +0100 Subject: [PATCH 1/2] Agroal - Only generate healths for active datasources Fixes #38934 --- .../quarkus/agroal/runtime/health/DataSourceHealthCheck.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/health/DataSourceHealthCheck.java b/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/health/DataSourceHealthCheck.java index 7a6d03fee425a..bd80e4efb38f6 100644 --- a/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/health/DataSourceHealthCheck.java +++ b/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/health/DataSourceHealthCheck.java @@ -18,6 +18,7 @@ import org.eclipse.microprofile.health.Readiness; import io.agroal.api.AgroalDataSource; +import io.quarkus.agroal.runtime.AgroalDataSourceSupport; import io.quarkus.agroal.runtime.DataSources; import io.quarkus.arc.Arc; import io.quarkus.datasource.common.runtime.DataSourceUtil; @@ -40,10 +41,12 @@ protected void init() { } DataSourceSupport support = Arc.container().instance(DataSourceSupport.class) .get(); + AgroalDataSourceSupport agroalSupport = Arc.container().instance(AgroalDataSourceSupport.class) + .get(); Set names = support.getConfiguredNames(); Set excludedNames = support.getInactiveOrHealthCheckExcludedNames(); for (String name : names) { - if (excludedNames.contains(name)) { + if (excludedNames.contains(name) || !agroalSupport.entries.containsKey(name)) { continue; } DataSource ds = dataSources.get().getDataSource(name); From 5ee3dc6dae8970e48370606fe888a8ca0ecb20b3 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Thu, 22 Feb 2024 15:04:32 +0100 Subject: [PATCH 2/2] Drop DataSourceSupport#configuredNames() It is misleading and can only lead to issues. Per discussion with Yoann. --- .../agroal/runtime/health/DataSourceHealthCheck.java | 5 ++--- .../datasource/runtime/DataSourceRecorder.java | 10 +--------- .../quarkus/datasource/runtime/DataSourceSupport.java | 11 +---------- 3 files changed, 4 insertions(+), 22 deletions(-) diff --git a/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/health/DataSourceHealthCheck.java b/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/health/DataSourceHealthCheck.java index bd80e4efb38f6..4a6e3db63be68 100644 --- a/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/health/DataSourceHealthCheck.java +++ b/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/health/DataSourceHealthCheck.java @@ -43,10 +43,9 @@ protected void init() { .get(); AgroalDataSourceSupport agroalSupport = Arc.container().instance(AgroalDataSourceSupport.class) .get(); - Set names = support.getConfiguredNames(); Set excludedNames = support.getInactiveOrHealthCheckExcludedNames(); - for (String name : names) { - if (excludedNames.contains(name) || !agroalSupport.entries.containsKey(name)) { + for (String name : agroalSupport.entries.keySet()) { + if (excludedNames.contains(name)) { continue; } DataSource ds = dataSources.get().getDataSource(name); diff --git a/extensions/datasource/runtime/src/main/java/io/quarkus/datasource/runtime/DataSourceRecorder.java b/extensions/datasource/runtime/src/main/java/io/quarkus/datasource/runtime/DataSourceRecorder.java index 87a39c554f6c3..3f4b459505df8 100644 --- a/extensions/datasource/runtime/src/main/java/io/quarkus/datasource/runtime/DataSourceRecorder.java +++ b/extensions/datasource/runtime/src/main/java/io/quarkus/datasource/runtime/DataSourceRecorder.java @@ -15,20 +15,12 @@ public class DataSourceRecorder { public RuntimeValue createDataSourceSupport( DataSourcesBuildTimeConfig buildTimeConfig, DataSourcesRuntimeConfig runtimeConfig) { - Stream.Builder configured = Stream.builder(); Stream.Builder excludedForHealthChecks = Stream.builder(); for (Map.Entry dataSource : buildTimeConfig.dataSources().entrySet()) { - // TODO this is wrong, as the default datasource could be configured without db-kind being set: - // it's inferred automatically for the default datasource when possible. - // See https://github.com/quarkusio/quarkus/issues/37779 - if (dataSource.getValue().dbKind().isPresent()) { - configured.add(dataSource.getKey()); - } if (dataSource.getValue().healthExclude()) { excludedForHealthChecks.add(dataSource.getKey()); } } - Set names = configured.build().collect(toUnmodifiableSet()); Set excludedNames = excludedForHealthChecks.build().collect(toUnmodifiableSet()); Stream.Builder inactive = Stream.builder(); @@ -39,6 +31,6 @@ public RuntimeValue createDataSourceSupport( } Set inactiveNames = inactive.build().collect(toUnmodifiableSet()); - return new RuntimeValue<>(new DataSourceSupport(names, excludedNames, inactiveNames)); + return new RuntimeValue<>(new DataSourceSupport(excludedNames, inactiveNames)); } } diff --git a/extensions/datasource/runtime/src/main/java/io/quarkus/datasource/runtime/DataSourceSupport.java b/extensions/datasource/runtime/src/main/java/io/quarkus/datasource/runtime/DataSourceSupport.java index 96b4b0f1fa9a9..21ea9141a98ce 100644 --- a/extensions/datasource/runtime/src/main/java/io/quarkus/datasource/runtime/DataSourceSupport.java +++ b/extensions/datasource/runtime/src/main/java/io/quarkus/datasource/runtime/DataSourceSupport.java @@ -12,26 +12,17 @@ */ public class DataSourceSupport { - private final Set configuredNames; private final Set inactiveNames; private final Set inactiveOrHealthCheckExcludedNames; - public DataSourceSupport(Set configuredNames, Set healthCheckExcludedNames, + public DataSourceSupport(Set healthCheckExcludedNames, Set inactiveNames) { - this.configuredNames = configuredNames; this.inactiveOrHealthCheckExcludedNames = new HashSet<>(); inactiveOrHealthCheckExcludedNames.addAll(inactiveNames); inactiveOrHealthCheckExcludedNames.addAll(healthCheckExcludedNames); this.inactiveNames = inactiveNames; } - // TODO careful when using this, as it might (incorrectly) not include the default datasource. - // See TODO in code that calls the constructor of this class. - // See https://github.com/quarkusio/quarkus/issues/37779 - public Set getConfiguredNames() { - return configuredNames; - } - public Set getInactiveNames() { return inactiveNames; }