Skip to content

Commit

Permalink
Merge pull request #43991 from gsmet/agroal-health-checks
Browse files Browse the repository at this point in the history
Make sure we have Agroal datasources before configuring health checks
  • Loading branch information
yrodiere authored Oct 21, 2024
2 parents 76be953 + c9d008b commit 097092a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import javax.sql.XADataSource;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Singleton;

import org.jboss.jandex.ClassType;
import org.jboss.jandex.DotName;
Expand Down Expand Up @@ -233,13 +234,15 @@ void generateDataSourceSupportBean(AgroalRecorder recorder,
// make AgroalPoolInterceptor beans unremovable, users still have to make them beans
unremovableBeans.produce(UnremovableBeanBuildItem.beanTypes(AgroalPoolInterceptor.class));

// create the DataSourceSupport bean that DataSourceProducer uses as a dependency
// create the AgroalDataSourceSupport bean that DataSources/DataSourceHealthCheck use as a dependency
AgroalDataSourceSupport agroalDataSourceSupport = getDataSourceSupport(aggregatedBuildTimeConfigBuildItems,
sslNativeConfig,
capabilities);
syntheticBeanBuildItemBuildProducer.produce(SyntheticBeanBuildItem.configure(AgroalDataSourceSupport.class)
.supplier(recorder.dataSourceSupportSupplier(agroalDataSourceSupport))
.scope(Singleton.class)
.unremovable()
.setRuntimeInit()
.done());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
* For applications, use CDI to retrieve datasources instead.
* For extensions, use {@link AgroalDataSourceUtil} instead.
*/
@Deprecated
@Deprecated(since = "3.16", forRemoval = true)
@Singleton
public class DataSources {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import io.agroal.api.AgroalDataSource;
import io.quarkus.agroal.runtime.AgroalDataSourceSupport;
import io.quarkus.agroal.runtime.AgroalDataSourceUtil;
import io.quarkus.arc.Arc;
import io.quarkus.datasource.common.runtime.DataSourceUtil;
import io.quarkus.datasource.runtime.DataSourceSupport;

Expand All @@ -32,19 +31,20 @@ public class DataSourceHealthCheck implements HealthCheck {
@Inject
Instance<DataSourceSupport> dataSourceSupport;

@Inject
Instance<AgroalDataSourceSupport> agroalDataSourceSupport;

private final Map<String, DataSource> checkedDataSources = new HashMap<>();

@PostConstruct
protected void init() {
if (!dataSourceSupport.isResolvable()) {
// No configured Agroal datasource at build time.
if (!dataSourceSupport.isResolvable() || !agroalDataSourceSupport.isResolvable()) {
// No configured Agroal datasources at build time.
return;
}
DataSourceSupport support = dataSourceSupport.get();
AgroalDataSourceSupport agroalSupport = Arc.container().instance(AgroalDataSourceSupport.class)
.get();
Set<String> healthCheckExcludedNames = support.getHealthCheckExcludedNames();
for (String name : agroalSupport.entries.keySet()) {
for (String name : agroalDataSourceSupport.get().entries.keySet()) {
if (healthCheckExcludedNames.contains(name)) {
continue;
}
Expand Down

0 comments on commit 097092a

Please sign in to comment.