Skip to content

Commit

Permalink
Rebase the branch
Browse files Browse the repository at this point in the history
  • Loading branch information
vasireddy99 committed Oct 6, 2023
1 parent aad1a4f commit f3c2243
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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();
}
Expand All @@ -164,41 +164,41 @@ void testCollectorRestartAfterCrash() throws Exception {

collector.start();
try {
Thread.sleep(1000);
Thread.sleep(10000);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
}
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
// 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);
Expand Down Expand Up @@ -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;
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
receivers:
filelog:
include: [/logs/*.log]
include: [/logs/filerotationlogs/*.log]
start_at: beginning

exporters:
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f3c2243

Please sign in to comment.