-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20273 from tsegismont/issue_20059
Datasource "health-exclude" property should apply to reactive pools too
- Loading branch information
Showing
23 changed files
with
274 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...n/java/io/quarkus/datasource/deployment/DataSourcesExcludedFromHealthChecksProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.quarkus.datasource.deployment; | ||
|
||
import static io.quarkus.deployment.annotations.ExecutionTime.STATIC_INIT; | ||
|
||
import javax.inject.Singleton; | ||
|
||
import io.quarkus.arc.deployment.SyntheticBeanBuildItem; | ||
import io.quarkus.datasource.runtime.DataSourcesBuildTimeConfig; | ||
import io.quarkus.datasource.runtime.DataSourcesExcludedFromHealthChecks; | ||
import io.quarkus.datasource.runtime.DataSourcesExcludedFromHealthChecksRecorder; | ||
import io.quarkus.deployment.Capabilities; | ||
import io.quarkus.deployment.Capability; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.annotations.Record; | ||
|
||
public class DataSourcesExcludedFromHealthChecksProcessor { | ||
|
||
@BuildStep | ||
@Record(STATIC_INIT) | ||
void produceBean( | ||
Capabilities capabilities, | ||
DataSourcesExcludedFromHealthChecksRecorder recorder, | ||
DataSourcesBuildTimeConfig config, | ||
BuildProducer<SyntheticBeanBuildItem> syntheticBeans) { | ||
if (capabilities.isPresent(Capability.SMALLRYE_HEALTH)) { | ||
syntheticBeans.produce(SyntheticBeanBuildItem.configure(DataSourcesExcludedFromHealthChecks.class) | ||
.scope(Singleton.class) | ||
.unremovable() | ||
.runtimeValue(recorder.configureDataSourcesExcludedFromHealthChecks(config)) | ||
.done()); | ||
} | ||
} | ||
} |
10 changes: 5 additions & 5 deletions
10
...time/src/main/java/io/quarkus/datasource/runtime/DataSourcesExcludedFromHealthChecks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
package io.quarkus.datasource.runtime; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
public class DataSourcesExcludedFromHealthChecks { | ||
|
||
private List<String> excludedNames; | ||
private final Set<String> excludedNames; | ||
|
||
public DataSourcesExcludedFromHealthChecks(List<String> names) { | ||
this.excludedNames = names; | ||
public DataSourcesExcludedFromHealthChecks(Set<String> excludedNames) { | ||
this.excludedNames = excludedNames; | ||
} | ||
|
||
public List<String> getExcludedNames() { | ||
public Set<String> getExcludedNames() { | ||
return excludedNames; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
.../main/java/io/quarkus/datasource/runtime/DataSourcesExcludedFromHealthChecksRecorder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.quarkus.datasource.runtime; | ||
|
||
import static java.util.stream.Collectors.toUnmodifiableSet; | ||
|
||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.stream.Stream; | ||
|
||
import io.quarkus.datasource.common.runtime.DataSourceUtil; | ||
import io.quarkus.runtime.RuntimeValue; | ||
import io.quarkus.runtime.annotations.Recorder; | ||
|
||
@Recorder | ||
public class DataSourcesExcludedFromHealthChecksRecorder { | ||
|
||
public RuntimeValue<DataSourcesExcludedFromHealthChecks> configureDataSourcesExcludedFromHealthChecks( | ||
DataSourcesBuildTimeConfig config) { | ||
Stream.Builder<String> builder = Stream.builder(); | ||
if (config.defaultDataSource.healthExclude) { | ||
builder.add(DataSourceUtil.DEFAULT_DATASOURCE_NAME); | ||
} | ||
for (Map.Entry<String, DataSourceBuildTimeConfig> dataSource : config.namedDataSources.entrySet()) { | ||
if (dataSource.getValue().healthExclude) { | ||
builder.add(dataSource.getKey()); | ||
} | ||
} | ||
Set<String> excludedNames = builder.build().collect(toUnmodifiableSet()); | ||
return new RuntimeValue<>(new DataSourcesExcludedFromHealthChecks(excludedNames)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...nt/src/test/java/io/quarkus/reactive/mssql/client/DataSourceHealthCheckExclusionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.quarkus.reactive.mssql.client; | ||
|
||
import org.hamcrest.CoreMatchers; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class DataSourceHealthCheckExclusionTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)) | ||
.withConfigurationResource("application-datasources-with-health.properties"); | ||
|
||
@Test | ||
public void testDataSourceHealthCheckExclusion() { | ||
RestAssured.when().get("/q/health/ready") | ||
.then() | ||
.body("status", CoreMatchers.equalTo("UP")); | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
...mssql-client/deployment/src/test/resources/application-datasources-with-health.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
quarkus.datasource.db-kind=mssql | ||
quarkus.datasource.username=sa | ||
quarkus.datasource.password=A_Str0ng_Required_Password | ||
quarkus.datasource.reactive.url=${reactive-mssql.url} | ||
# this data source is broken, but will be excluded from the health check, so the overall check should pass | ||
quarkus.datasource."broken".db-kind=mssql | ||
quarkus.datasource."broken".username=BROKEN | ||
quarkus.datasource."broken".password=A_Str0ng_Required_Password | ||
quarkus.datasource."broken".reactive.url=${reactive-mssql.url} | ||
quarkus.datasource."broken".health-exclude=true | ||
quarkus.datasource.health.enabled=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.