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

Make sure we have Agroal datasources before configuring health checks #43991

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
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 @@ -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
Loading