From f3c22430d406e25e772307452d78de83fca8542f Mon Sep 17 00:00:00 2001 From: Vasi Vasireddy Date: Fri, 6 Oct 2023 16:18:27 -0700 Subject: [PATCH] Rebase the branch --- .../amazon/adot/testbed/LogsTests.java | 64 ++++++++++--------- .../configurations/config-fileRotation.yaml | 2 +- .../resources/logs/filerotationlogs/log4j.log | 7 +- .../test/resources/logs/storageExtension.log | 1 - 4 files changed, 36 insertions(+), 38 deletions(-) diff --git a/adot-testbed/app/src/test/java/software/amazon/adot/testbed/LogsTests.java b/adot-testbed/app/src/test/java/software/amazon/adot/testbed/LogsTests.java index 98cc268ae..85da72eea 100644 --- a/adot-testbed/app/src/test/java/software/amazon/adot/testbed/LogsTests.java +++ b/adot-testbed/app/src/test/java/software/amazon/adot/testbed/LogsTests.java @@ -53,7 +53,7 @@ class LogsTests { : "public.ecr.aws/aws-observability/aws-otel-collector:latest"; private final Logger collectorLogger = LoggerFactory.getLogger("collector"); private static final String uniqueID = UUID.randomUUID().toString(); - private final File tempFile = File.createTempFile("testlog", ".log"); +// private final File tempFile = File.createTempFile("testlog", ".log"); private GenericContainer collector; @@ -85,7 +85,7 @@ private GenericContainer createAndStartCollector(String configFilePath, Strin //Mount the log file for the file log receiver to parse collector.withCopyFileToContainer(MountableFile.forClasspathResource(logFilePath), logFilePath); - collector.withFileSystemBind(tempFile.getAbsolutePath(), "/logs/logs.log", BindMode.READ_WRITE); +// collector.withFileSystemBind(tempFile.getAbsolutePath(), "/logs/logs.log", BindMode.READ_WRITE); // collector.withCopyFileToContainer(MountableFile.forClasspathResource("/logs/"), "/logs/" ); // collector.withCommand("sh", "-c", "chmod -R a+rw " + "/logs"); @@ -147,7 +147,7 @@ void testCollectorRestartAfterCrash() throws Exception { validateLogs(logStreamName, resourceFilePath); collector.stop(); try { - Thread.sleep(1000); + Thread.sleep(10000); } catch (InterruptedException ie) { Thread.currentThread().interrupt(); } @@ -164,7 +164,7 @@ void testCollectorRestartAfterCrash() throws Exception { collector.start(); try { - Thread.sleep(1000); + Thread.sleep(10000); } catch (InterruptedException ie) { Thread.currentThread().interrupt(); } @@ -172,33 +172,33 @@ void testCollectorRestartAfterCrash() throws Exception { collector.stop(); } - -// @Test -// void testFileRotation() throws Exception { -// String logStreamName = "fileRotation-logstream-" + uniqueID; -// collector = createAndStartCollector("/configurations/config-fileRotation.yaml", "/logs/filerotationlogs/log4j.log", logStreamName); -// String resourceFilePath = "/logs/filerotationlogs/log4j.log"; // Path to the resource file -// File tempFile = File.createTempFile("testlog", ".log"); -// // crash by forcefully stopping the collector -// // collector.stop(); -// try (InputStream inputStream = getClass().getResourceAsStream(resourceFilePath); -// OutputStream outputStream = new FileOutputStream(new File(getClass().getResource(resourceFilePath).toURI()), true); -// BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream))) { -// -// // Append the lines to the file -// writer.write("[otel.javaagent 2023-09-28 16:56:22:242 +0000] [OkHttp ConnectionPool] DEBUG okhttp3.internal.concurrent.TaskRunner - Q10002 run again after 300 s : OkHttp ConnectionPool- First Entry"); -// writer.newLine(); -// writer.write("[otel.javaagent 2023-09-29 16:56:22:242 +0000] [OkHttp ConnectionPool] DEBUG okhttp3.internal.concurrent.TaskRunner - Q10002 run again after 300 s : OkHttp ConnectionPool- Second Entry"); -// writer.newLine(); -// writer.write("[otel.javaagent 2023-09-29 16:56:22:242 +0000] [OkHttp ConnectionPool] DEBUG okhttp3.internal.concurrent.TaskRunner - Q10002 run again after 300 s : OkHttp ConnectionPool- Third Entry"); -// writer.newLine(); -// } catch (IOException | URISyntaxException e) { -// throw new RuntimeException("Error writing to the file: " + resourceFilePath, e); -// } -// -// validateLogs(logStreamName, resourceFilePath); -// collector.stop(); -// } +// @Test +// void testFileRotation() throws Exception { +// String logStreamName = "fileRotation-logstream-" + uniqueID; +// collector = createAndStartCollector("/configurations/config-fileRotation.yaml", "/logs/filerotationlogs/log4j.log", logStreamName); +// String resourceFilePath = "/logs/filerotationlogs/log4j.log"; // Path to the resource file +// try { +// Thread.sleep(10000); +// } catch (InterruptedException ie) { +// Thread.currentThread().interrupt(); +// } +// File tempFile = File.createTempFile("testlog", ".log"); +// FileWriter fileWriter = new FileWriter(tempFile); +// try { +// fileWriter.write("Mesaage in the rotated/new file." + "\n"); +// } catch (IOException e) { +// throw new RuntimeException("Error writing to the file.", e); +// } +// fileWriter.flush(); +// collector.withFileSystemBind(tempFile.getAbsolutePath(), "/logs/filerotationlogs/logs.log", BindMode.READ_WRITE); +// try { +// Thread.sleep(10000); +// } catch (InterruptedException ie) { +// Thread.currentThread().interrupt(); +// } +//// validateLogs(logStreamName, resourceFilePath); +// collector.stop(); +// } void validateLogs(String testLogStreamName, String logFilePath) throws Exception { var file = new File(logFilePath); @@ -237,6 +237,8 @@ void validateLogs(String testLogStreamName, String logFilePath) throws Exception var events = response.events(); var receivedMessages = events.stream().map(x -> x.message()).collect(Collectors.toSet()); assertThat(receivedMessages.containsAll(lines)).isTrue(); + assertThat(receivedMessages).containsExactlyInAnyOrderElementsOf(lines); + return null; }); } diff --git a/adot-testbed/app/src/test/resources/configurations/config-fileRotation.yaml b/adot-testbed/app/src/test/resources/configurations/config-fileRotation.yaml index 4efbe2634..951b78f72 100644 --- a/adot-testbed/app/src/test/resources/configurations/config-fileRotation.yaml +++ b/adot-testbed/app/src/test/resources/configurations/config-fileRotation.yaml @@ -1,6 +1,6 @@ receivers: filelog: - include: [/logs/*.log] + include: [/logs/filerotationlogs/*.log] start_at: beginning exporters: diff --git a/adot-testbed/app/src/test/resources/logs/filerotationlogs/log4j.log b/adot-testbed/app/src/test/resources/logs/filerotationlogs/log4j.log index 5a455c111..b676b2c5b 100644 --- a/adot-testbed/app/src/test/resources/logs/filerotationlogs/log4j.log +++ b/adot-testbed/app/src/test/resources/logs/filerotationlogs/log4j.log @@ -1,5 +1,2 @@ -[otel.javaagent 2023-09-25 16:56:22:242 +0000] [OkHttp ConnectionPool] DEBUG okhttp3.internal.concurrent.TaskRunner - Q10002 run again after 300 s : OkHttp ConnectionPool- First Entry -[otel.javaagent 2023-09-26 16:56:22:242 +0000] [OkHttp ConnectionPool] DEBUG okhttp3.internal.concurrent.TaskRunner - Q10002 run again after 300 s : OkHttp ConnectionPool- Second Entry -[otel.javaagent 2023-09-27 16:56:22:242 +0000] [OkHttp ConnectionPool] DEBUG okhttp3.internal.concurrent.TaskRunner - Q10002 run again after 300 s : OkHttp ConnectionPool- Third Entry -[otel.javaagent 2023-09-28 16:56:22:242 +0000] [OkHttp ConnectionPool] DEBUG okhttp3.internal.concurrent.TaskRunner - Q10002 run again after 300 s : OkHttp ConnectionPool- Fourth Entry -[otel.javaagent 2023-09-29 16:56:22:242 +0000] [OkHttp ConnectionPool] DEBUG okhttp3.internal.concurrent.TaskRunner - Q10002 run again after 300 s : OkHttp ConnectionPool- Fifth Entry +[otel.javaagent 2023-09-25 16:56:22:242 +0000] [OkHttp ConnectionPool] DEBUG okhttp3.internal.concurrent.TaskRunner - Q10002 run again after 300 s : File rotation First Line +[otel.javaagent 2023-09-26 16:56:22:242 +0000] [OkHttp ConnectionPool] DEBUG okhttp3.internal.concurrent.TaskRunner - Q10002 run again after 300 s : File rotation Second Line diff --git a/adot-testbed/app/src/test/resources/logs/storageExtension.log b/adot-testbed/app/src/test/resources/logs/storageExtension.log index 38b5db56e..e69de29bb 100644 --- a/adot-testbed/app/src/test/resources/logs/storageExtension.log +++ b/adot-testbed/app/src/test/resources/logs/storageExtension.log @@ -1 +0,0 @@ -[otel.javaagent 2023-09-29 16:56:22:242 +0000] [OkHttp ConnectionPool] DEBUG okhttp3.internal.concurrent.TaskRunner - Q10002 run again after 300 s : Log Entry