forked from aws-observability/aws-otel-test-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit, Add base for testcase
- Loading branch information
1 parent
5a0284a
commit 965ec7b
Showing
7 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
extensions: | ||
pprof: | ||
endpoint: 0.0.0.0:1777 | ||
receivers: | ||
otlp: | ||
protocols: | ||
grpc: | ||
endpoint: 0.0.0.0:${grpc_port} | ||
|
||
processors: | ||
batch: | ||
|
||
exporters: | ||
logging: | ||
verbosity: detailed | ||
awscloudwatchlogs: | ||
log_group_name: "otlp-receiver" | ||
log_stream_name: "otlp-logs" | ||
region: ${region} | ||
|
||
service: | ||
pipelines: | ||
metrics: | ||
receivers: [otlp] | ||
processors: [batch] | ||
exporters: [logging, awscloudwatchlogs] | ||
extensions: [pprof] | ||
telemetry: | ||
logs: | ||
level: ${log_level} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
validation_config = "spark-otel-log-validation.yml" | ||
|
||
sample_app = "spark" | ||
|
||
sample_app_image = "public.ecr.aws/aws-otel-test/aws-otel-java-spark:latest" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
validator/src/main/java/com/amazon/aoc/validators/CWLogValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package com.amazon.aoc.validators; | ||
|
||
import com.amazon.aoc.callers.ICaller; | ||
import com.amazon.aoc.fileconfigs.FileConfig; | ||
import com.amazon.aoc.models.Context; | ||
import com.amazon.aoc.models.ValidationConfig; | ||
import com.amazonaws.services.logs.CloudWatchLogsClient; | ||
import com.amazonaws.services.logs.model.GetLogEventsRequest; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.awaitility.core.RetryerBuilder; | ||
import org.awaitility.core.StopStrategies; | ||
import org.awaitility.core.WaitStrategies; | ||
import org.opentest4j.AssertionFailedError; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.util.HashSet; | ||
import java.util.Objects; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.stream.Collectors; | ||
|
||
public class CWLogValidator implements IValidator { | ||
|
||
|
||
|
||
// String getJsonSchemaMappingKey(JsonNode jsonNode) { | ||
// // Your implementation for getting the JSON schema mapping key | ||
// return null; | ||
// } | ||
|
||
@Override | ||
public void init(Context context, ValidationConfig validationConfig, ICaller caller, FileConfig expectedDataTemplate) throws Exception { | ||
|
||
} | ||
|
||
@Override | ||
public void validate() throws Exception { | ||
var lines = new HashSet<String>(); | ||
InputStream inputStream = getClass().getResourceAsStream("/logs/testingJSON.log"); | ||
|
||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { | ||
String line; | ||
while ((line = reader.readLine()) != null) { | ||
lines.add(line); | ||
} | ||
} catch (IOException e) { | ||
throw new RuntimeException("Error reading from the file: " + inputStream, e); | ||
} | ||
|
||
var cwClient = CloudWatchLogsClient.builder().build(); | ||
var objectMapper = new ObjectMapper(); | ||
|
||
RetryerBuilder.<Void>newBuilder() | ||
.retryIfException() | ||
.retryIfRuntimeException() | ||
.retryIfExceptionOfType(AssertionFailedError.class) | ||
.withWaitStrategy(WaitStrategies.fixedWait(10, TimeUnit.SECONDS)) | ||
.withStopStrategy(StopStrategies.stopAfterAttempt(5)) | ||
.build() | ||
.call(() -> { | ||
var now = Instant.now(); | ||
var start = now.minus(Duration.ofMinutes(2)); | ||
var end = now.plus(Duration.ofMinutes(2)); | ||
var response = cwClient.getLogEvents(GetLogEventsRequest.builder() | ||
.logGroupName("adot-testbed/logs-component-testing/logs") | ||
.logStreamName(testLogStreamName) | ||
.startTime(start.toEpochMilli()) | ||
.endTime(end.toEpochMilli()) | ||
.build()); | ||
|
||
var events = response.events(); | ||
var receivedMessages = events.stream().map(x -> x.message()).collect(Collectors.toSet()); | ||
|
||
// Extract the "body" field from each received message that is received from CloudWatch in JSON Format | ||
var messageToValidate = receivedMessages.stream() | ||
.map(message -> { | ||
try { | ||
JsonNode jsonNode = objectMapper.readTree(message); | ||
return jsonNode.get("body").asText(); | ||
} catch (Exception e) { | ||
return null; | ||
} | ||
}) | ||
.filter(Objects::nonNull) | ||
.collect(Collectors.toSet()); | ||
|
||
// Validate the body field in JSON-messageToValidate with actual log lines from the log file. | ||
assertThat(messageToValidate.containsAll(lines)).isTrue(); | ||
assertThat(messageToValidate).containsExactlyInAnyOrderElementsOf(lines); | ||
return null; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
validator/src/main/resources/validations/spark-otel-log-validation.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
- | ||
validationType: "cw-logs" | ||
httpPath: "/outgoing-http-call" | ||
httpMethod: "get" | ||
callingType: "http" | ||
expectedMetricTemplate: "DEFAULT_EXPECTED_LOG" |