Skip to content

Commit

Permalink
Expected template changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielzolty committed Oct 26, 2023
1 parent 56a2fc2 commit 4b9dccf
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions validator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ dependencies {
implementation 'com.amazonaws:aws-java-sdk-xray'
implementation 'com.amazonaws:aws-java-sdk-logs'
implementation 'com.amazonaws:aws-java-sdk-sts'
implementation group: 'javax.json', name: 'javax.json-api', version: '1.0-b01'

// aws ecs sdk
implementation 'com.amazonaws:aws-java-sdk-ecs'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static boolean retry(
} catch (Exception ex) {
exceptionInTheEnd = ex;
if (retryCount != 0) { // don't sleep before leave this loop
log.info("Error that occured:" + ex.getMessage());
log.info(
"retrying after {} seconds", TimeUnit.MILLISECONDS.toSeconds(sleepInMilliSeconds));
TimeUnit.MILLISECONDS.sleep(sleepInMilliSeconds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,22 @@ public void init(
// cloudWatchService = new CloudWatchService(context.getRegion());
MustacheHelper mustacheHelper = new MustacheHelper();
String templateInput = mustacheHelper.render(expectedDataTemplate, context);
log.info("Template input: " + templateInput);
JsonNode jsonNode = JsonLoader.fromString(templateInput);
log.info("Trying to get jsonNode string: " + jsonNode.textValue());
JsonSchemaFactory jsonSchemaFactory =
JsonSchemaFactory.newBuilder()
.setReportProvider(new ListReportProvider(LogLevel.INFO, LogLevel.FATAL))
.freeze();
JsonSchema schema = jsonSchemaFactory.getJsonSchema(jsonNode);
this.schema = schema;
JsonSchema jsonSchema = jsonSchemaFactory.getJsonSchema(jsonNode);
this.schema = jsonSchema;
log.info(("CWLog init ending"));
Map<String, Object> mapping = new ObjectMapper().readValue(templateInput, HashMap.class);
// ObjectMapper mapper = new ObjectMapper();
// ObjectNode jsonObject = mapper.readValue(templateInput, ObjectNode.class);
// Map<String, Object> result =
// mapper.convertValue(jsonObject, new TypeReference<Map<String, Object>>() {});
log.info("Mapper is:" + mapping.toString());
caller.callSampleApp();
}

Expand Down Expand Up @@ -116,9 +124,12 @@ protected void fetchAndValidateLogs(Instant startTime) throws Exception {
"[StructuredLogValidator] no logs found under log stream %s" + " in log group %s",
logStreamName, logGroupName));
}
log.info("Number of log events: " + logEvents.size());
for (OutputLogEvent logEvent : logEvents) {
log.info("Log message: " + logEvent.getMessage());
validateJsonSchema(logEvent.getMessage());
if (logEvent.getMessage().contains("Executing outgoing-http-call")) {
validateJsonSchema(logEvent.getMessage());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
[
{
{
"body": "Executing outgoing-http-call",
"severity_number": 9,
"severity_number": "{{severity_number}}",
"severity_text": "INFO",
"flags": 1,
"trace_id": "{{trace_id}}",
"span_id": "{{span_id}}",
"resource": {
"service.name": "{{resource.service.name}}"
}

}
]
}

0 comments on commit 4b9dccf

Please sign in to comment.