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

Add configuration property to container-based datasource devservices for capturing logs with JBossLoggingConsumer #44375

Merged
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
2 changes: 1 addition & 1 deletion docs/src/main/asciidoc/appcds.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ When building container images using the `quarkus-container-image-jib` extension
This way, by simply setting `quarkus.package.jar.appcds.enabled` to `true`, containers using the generated image can benefit from a slight reduction in startup time and memory usage.

You may see that Quarkus starts a container to generate the AppCDS archive.
It does this to ensure that the Java version of the build align with that of the generated container image.
It does this to ensure that the Java version of the build aligns with that of the generated container image.
It is possible to opt out of this by setting `quarkus.package.jar.appcds.use-container` to `false`.
In that case, it is your responsibility to ensure that the Java version that will run the Quarkus application matches that of the machine building it.
10 changes: 10 additions & 0 deletions docs/src/main/asciidoc/databases-dev-services.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ ibmcom/db2:11.5.0.0a
mcr.microsoft.com/mssql/server:2022-latest
----

=== Capturing Logs

By default, logs of the underlying database are not exposed.
By capturing the logs, they become visible amongst other log statements:

[source,properties]
----
quarkus.datasource.devservices.show-logs=true
----

[[reuse]]
== Reusing Dev Services

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class DevServicesDatasourceContainerConfig {
private final Optional<String> initScriptPath;
private final Map<String, String> volumes;
private final boolean reuse;
private final boolean showLogs;

public DevServicesDatasourceContainerConfig(Optional<String> imageName,
Map<String, String> containerEnv,
Expand All @@ -30,7 +31,8 @@ public DevServicesDatasourceContainerConfig(Optional<String> imageName,
Optional<String> password,
Optional<String> initScriptPath,
Map<String, String> volumes,
boolean reuse) {
boolean reuse,
boolean showLogs) {
this.imageName = imageName;
this.containerEnv = containerEnv;
this.containerProperties = containerProperties;
Expand All @@ -43,6 +45,7 @@ public DevServicesDatasourceContainerConfig(Optional<String> imageName,
this.initScriptPath = initScriptPath;
this.volumes = volumes;
this.reuse = reuse;
this.showLogs = showLogs;
}

public Optional<String> getImageName() {
Expand Down Expand Up @@ -85,6 +88,10 @@ public Optional<String> getInitScriptPath() {
return initScriptPath;
}

public boolean isShowLogs() {
return showLogs;
}

public Map<String, String> getVolumes() {
return volumes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ private RunningDevService startDevDb(
dataSourceBuildTimeConfig.devservices().password(),
dataSourceBuildTimeConfig.devservices().initScriptPath(),
dataSourceBuildTimeConfig.devservices().volumes(),
dataSourceBuildTimeConfig.devservices().reuse());
dataSourceBuildTimeConfig.devservices().reuse(),
dataSourceBuildTimeConfig.devservices().showLogs());

DevServicesDatasourceProvider.RunningDevServicesDatasource datasource = devDbProvider
.startDatabase(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,12 @@ public interface DevServicesBuildTimeConfig {
@WithDefault("true")
boolean reuse();

/**
* Whether the logs should be consumed by the JBoss logger.
* <p>
* This has no effect if the provider is not a container-based database, such as H2 or Derby.
*/
@WithDefault("false")
boolean showLogs();

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.quarkus.deployment.dev.devservices.GlobalDevServicesConfig;
import io.quarkus.devservices.common.ConfigureUtil;
import io.quarkus.devservices.common.ContainerShutdownCloseable;
import io.quarkus.devservices.common.JBossLoggingConsumer;
import io.quarkus.devservices.common.Labels;
import io.quarkus.devservices.common.Volumes;
import io.quarkus.runtime.LaunchMode;
Expand Down Expand Up @@ -65,6 +66,9 @@ public RunningDevServicesDatasource startDatabase(Optional<String> username, Opt
containerConfig.getAdditionalJdbcUrlProperties().forEach(container::withUrlParam);
containerConfig.getCommand().ifPresent(container::setCommand);
containerConfig.getInitScriptPath().ifPresent(container::withInitScript);
if (containerConfig.isShowLogs()) {
container.withLogConsumer(new JBossLoggingConsumer(LOG));
}
container.start();

LOG.info("Dev Services for IBM Db2 started.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.quarkus.deployment.dev.devservices.GlobalDevServicesConfig;
import io.quarkus.devservices.common.ConfigureUtil;
import io.quarkus.devservices.common.ContainerShutdownCloseable;
import io.quarkus.devservices.common.JBossLoggingConsumer;
import io.quarkus.devservices.common.Labels;
import io.quarkus.devservices.common.Volumes;
import io.quarkus.runtime.LaunchMode;
Expand Down Expand Up @@ -74,6 +75,9 @@ public RunningDevServicesDatasource startDatabase(Optional<String> username, Opt
containerConfig.getAdditionalJdbcUrlProperties().forEach(container::withUrlParam);
containerConfig.getCommand().ifPresent(container::setCommand);
containerConfig.getInitScriptPath().ifPresent(container::withInitScript);
if (containerConfig.isShowLogs()) {
container.withLogConsumer(new JBossLoggingConsumer(LOG));
}
container.start();

LOG.info("Dev Services for MariaDB started.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.quarkus.deployment.dev.devservices.GlobalDevServicesConfig;
import io.quarkus.devservices.common.ConfigureUtil;
import io.quarkus.devservices.common.ContainerShutdownCloseable;
import io.quarkus.devservices.common.JBossLoggingConsumer;
import io.quarkus.devservices.common.Labels;
import io.quarkus.devservices.common.Volumes;
import io.quarkus.runtime.LaunchMode;
Expand Down Expand Up @@ -65,6 +66,9 @@ public RunningDevServicesDatasource startDatabase(Optional<String> username, Opt
containerConfig.getAdditionalJdbcUrlProperties().forEach(container::withUrlParam);
containerConfig.getCommand().ifPresent(container::setCommand);
containerConfig.getInitScriptPath().ifPresent(container::withInitScript);
if (containerConfig.isShowLogs()) {
container.withLogConsumer(new JBossLoggingConsumer(LOG));
}

container.start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.quarkus.deployment.dev.devservices.GlobalDevServicesConfig;
import io.quarkus.devservices.common.ConfigureUtil;
import io.quarkus.devservices.common.ContainerShutdownCloseable;
import io.quarkus.devservices.common.JBossLoggingConsumer;
import io.quarkus.devservices.common.Labels;
import io.quarkus.devservices.common.Volumes;
import io.quarkus.runtime.LaunchMode;
Expand Down Expand Up @@ -73,6 +74,9 @@ public RunningDevServicesDatasource startDatabase(Optional<String> username, Opt
containerConfig.getAdditionalJdbcUrlProperties().forEach(container::withUrlParam);
containerConfig.getCommand().ifPresent(container::setCommand);
containerConfig.getInitScriptPath().ifPresent(container::withInitScript);
if (containerConfig.isShowLogs()) {
container.withLogConsumer(new JBossLoggingConsumer(LOG));
}

container.start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.quarkus.deployment.dev.devservices.GlobalDevServicesConfig;
import io.quarkus.devservices.common.ConfigureUtil;
import io.quarkus.devservices.common.ContainerShutdownCloseable;
import io.quarkus.devservices.common.JBossLoggingConsumer;
import io.quarkus.devservices.common.Labels;
import io.quarkus.devservices.common.Volumes;
import io.quarkus.runtime.LaunchMode;
Expand Down Expand Up @@ -79,6 +80,9 @@ public RunningDevServicesDatasource startDatabase(Optional<String> username, Opt
containerConfig.getAdditionalJdbcUrlProperties().forEach(container::withUrlParam);
containerConfig.getCommand().ifPresent(container::setCommand);
containerConfig.getInitScriptPath().ifPresent(container::withInitScript);
if (containerConfig.isShowLogs()) {
container.withLogConsumer(new JBossLoggingConsumer(LOG));
}

container.start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.quarkus.deployment.dev.devservices.GlobalDevServicesConfig;
import io.quarkus.devservices.common.ConfigureUtil;
import io.quarkus.devservices.common.ContainerShutdownCloseable;
import io.quarkus.devservices.common.JBossLoggingConsumer;
import io.quarkus.devservices.common.Labels;
import io.quarkus.devservices.common.Volumes;
import io.quarkus.runtime.LaunchMode;
Expand Down Expand Up @@ -76,6 +77,9 @@ public RunningDevServicesDatasource startDatabase(Optional<String> username, Opt
containerConfig.getAdditionalJdbcUrlProperties().forEach(container::withUrlParam);
containerConfig.getCommand().ifPresent(container::setCommand);
containerConfig.getInitScriptPath().ifPresent(container::withInitScript);
if (containerConfig.isShowLogs()) {
container.withLogConsumer(new JBossLoggingConsumer(LOG));
}

container.start();

Expand Down
Loading