Skip to content

Commit

Permalink
datasource devservices: showLogs
Browse files Browse the repository at this point in the history
Brings support for JBossLoggingConsumer to container-based datasource
dev services, and adds a little section to the documentation about the
new "showLogs" option.

Also contains a minor correction to the AppCDS documentation.
  • Loading branch information
DeMol-EE committed Nov 8, 2024
1 parent 5810fca commit 611f5e0
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 1 deletion.
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 @@ -16,6 +16,7 @@ public class DevServicesDatasourceContainerConfig {
private final Optional<String> username;
private final Optional<String> password;
private final Optional<String> initScriptPath;
private final Optional<Boolean> showLogs;
private final Map<String, String> volumes;
private final boolean reuse;

Expand All @@ -29,6 +30,7 @@ public DevServicesDatasourceContainerConfig(Optional<String> imageName,
Optional<String> username,
Optional<String> password,
Optional<String> initScriptPath,
Optional<Boolean> showLogs,
Map<String, String> volumes,
boolean reuse) {
this.imageName = imageName;
Expand All @@ -41,6 +43,7 @@ public DevServicesDatasourceContainerConfig(Optional<String> imageName,
this.username = username;
this.password = password;
this.initScriptPath = initScriptPath;
this.showLogs = showLogs;
this.volumes = volumes;
this.reuse = reuse;
}
Expand Down Expand Up @@ -85,6 +88,10 @@ public Optional<String> getInitScriptPath() {
return initScriptPath;
}

public Optional<Boolean> getShowLogs() {
return showLogs;
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ public interface DevServicesBuildTimeConfig {
*/
Optional<String> initScriptPath();

/**
* 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.
*/
Optional<Boolean> showLogs();

/**
* The volumes to be mapped to the container.
* <p>
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 @@ -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.getShowLogs().orElse(Boolean.FALSE)) {
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.getShowLogs().orElse(Boolean.FALSE)) {
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.getShowLogs().orElse(Boolean.FALSE)) {
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.getShowLogs().orElse(Boolean.FALSE)) {
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.getShowLogs().orElse(Boolean.FALSE)) {
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.getShowLogs().orElse(Boolean.FALSE)) {
container.withLogConsumer(new JBossLoggingConsumer(LOG));
}

container.start();

Expand Down

0 comments on commit 611f5e0

Please sign in to comment.