CASSSIDECAR-336: Fix logging regression in Sidecar after CASSSIDECAR-176 (#253)
Patch by Francisco Guerrero; reviewed by Bernardo Botella, Yifan Cai for CASSSIDECAR-336
diff --git a/CHANGES.txt b/CHANGES.txt
index 3227e36..798114f 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,5 +1,6 @@
0.2.0
-----
+ * Fix logging regression in Sidecar after CASSSIDECAR-176 (CASSSIDECAR-336)
* Do not log whole exception when schema is not found (CASSSIDECAR-250)
* Add comprehensive OpenAPI documentation (CASSSIDECAR-176)
* Fix type used for reading member_of column in SystemAuthDatabaseAccessor (CASSSIDECAR-333)
diff --git a/server/build.gradle b/server/build.gradle
index f7cad2c..410fa7f 100644
--- a/server/build.gradle
+++ b/server/build.gradle
@@ -143,10 +143,6 @@
// OpenAPI support
implementation("org.eclipse.microprofile.openapi:microprofile-openapi-api:${project.microprofileOpenApiVersion}")
implementation("jakarta.ws.rs:jakarta.ws.rs-api:${project.jakartaWsRsVersion}")
- implementation("io.swagger.core.v3:swagger-core:${project.swaggerVersion}")
- implementation("io.swagger.core.v3:swagger-annotations:${project.swaggerVersion}")
- implementation("io.swagger.core.v3:swagger-models:${project.swaggerVersion}")
- implementation("io.swagger.core.v3:swagger-jaxrs2:${project.swaggerVersion}")
testImplementation "org.junit.jupiter:junit-jupiter-api:${project.junitVersion}"
testImplementation "org.junit.jupiter:junit-jupiter-params:${project.junitVersion}"
diff --git a/server/src/test/java/org/apache/cassandra/sidecar/CassandraSidecarDaemonTest.java b/server/src/test/java/org/apache/cassandra/sidecar/CassandraSidecarDaemonTest.java
index bda9c9a..714bc5f 100644
--- a/server/src/test/java/org/apache/cassandra/sidecar/CassandraSidecarDaemonTest.java
+++ b/server/src/test/java/org/apache/cassandra/sidecar/CassandraSidecarDaemonTest.java
@@ -18,6 +18,7 @@
package org.apache.cassandra.sidecar;
+import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -25,12 +26,13 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
+import java.util.stream.Stream;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.junit.jupiter.api.io.TempDir;
import io.vertx.core.Vertx;
import io.vertx.ext.web.client.HttpResponse;
@@ -49,14 +51,42 @@
*/
class CassandraSidecarDaemonTest
{
- private static final Logger LOGGER = LoggerFactory.getLogger(CassandraSidecarDaemonTest.class);
-
static final String[] NO_ARGS = {};
+ @TempDir
+ static Path testDir;
+
+ @BeforeAll
+ static void configureLogging() throws IOException
+ {
+ Path confDirectory = testDir.resolve("conf");
+ Path logbackConfigFile = testDir.resolve("conf/logback.xml");
+ Path logDirectory = testDir.resolve("logs");
+ Files.createDirectories(confDirectory);
+ Files.createDirectories(logDirectory);
+
+ Path sourceLogbackConfigFile = Paths.get("../conf/logback.xml");
+ assertThat(sourceLogbackConfigFile).exists();
+ Files.copy(sourceLogbackConfigFile, logbackConfigFile);
+
+ System.setProperty("sidecar.logdir", logDirectory.toString());
+ System.setProperty("logback.configurationFile", logbackConfigFile.toString());
+ System.setProperty("vertx.logger-delegate-factory-class-name", "io.vertx.core.logging.SLF4JLogDelegateFactory");
+ }
+
+ @AfterAll
+ static void clearLoggingProperties()
+ {
+ System.clearProperty("sidecar.logdir");
+ System.clearProperty("logback.configurationFile");
+ System.clearProperty("vertx.logger-delegate-factory-class-name");
+ }
+
@BeforeEach
void setup()
{
System.clearProperty("sidecar.config");
+ clearLogDirectory();
}
@Test
@@ -141,7 +171,6 @@
}
finally
{
- LOGGER.debug("Tearing down");
maybeStopCassandraSidecar();
Files.deleteIfExists(targetFile);
@@ -156,6 +185,39 @@
}
}
+ @Test
+ void testLogbackConfiguration()
+ {
+ Path path = Paths.get("../conf/sidecar.yaml");
+ assertThat(path).exists();
+
+ System.setProperty("sidecar.config", path.toUri().toString());
+ Vertx vertx = Vertx.vertx();
+ WebClient client = WebClient.create(vertx);
+ try
+ {
+ CassandraSidecarDaemon.main(NO_ARGS);
+
+ loopAssert(10, () -> {
+ HttpResponse<String> response = getBlocking(client.get(9043, "localhost", "/api/v1/__health")
+ .as(BodyCodec.string())
+ .send(),
+ 2, TimeUnit.SECONDS,
+ "Query for sidecar health");
+ assertThat(response.statusCode()).isEqualTo(OK.code());
+ assertThat(response.body()).isEqualTo("{\"status\":\"OK\"}");
+ });
+
+ assertThat(testDir.resolve("logs/debug.log")).exists().isNotEmptyFile();
+ assertThat(testDir.resolve("logs/system.log")).exists().isNotEmptyFile();
+ }
+ finally
+ {
+ maybeStopCassandraSidecar();
+ TestResourceReaper.create().with(vertx).with(client).close();
+ }
+ }
+
static void maybeStopCassandraSidecar()
{
Server runningApplication = CassandraSidecarDaemon.runningApplication;
@@ -183,4 +245,20 @@
Files.createDirectories(parentDirectory);
return createdParents;
}
+
+ void clearLogDirectory()
+ {
+ Path logsDirectory = testDir.resolve("logs");
+ if (Files.exists(logsDirectory))
+ {
+ try (Stream<Path> logFiles = Files.walk(logsDirectory))
+ {
+ logFiles.map(Path::toFile).forEach(File::delete);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unable to clear all files in the log directory", e);
+ }
+ }
+ }
}