From aef00ab170c0050e03c8de5b667f69cd29a9485d Mon Sep 17 00:00:00 2001 From: Mingjie Shao Date: Mon, 23 Sep 2024 21:38:19 +0100 Subject: [PATCH] [Java/Log] Update log validation + bump mysql version (#246) --- sample-apps/springboot/build.gradle.kts | 2 +- .../com/amazon/aoc/validators/CWLogValidator.java | 10 ++++++++-- .../java/eks/rds-mysql-trace.mustache | 14 ++++++++++---- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/sample-apps/springboot/build.gradle.kts b/sample-apps/springboot/build.gradle.kts index 242e72135..c14ede174 100644 --- a/sample-apps/springboot/build.gradle.kts +++ b/sample-apps/springboot/build.gradle.kts @@ -37,7 +37,7 @@ dependencies { implementation("io.opentelemetry:opentelemetry-api:1.34.1") implementation("software.amazon.awssdk:s3") implementation("software.amazon.awssdk:sts") - implementation("com.mysql:mysql-connector-j:8.0.33") + implementation("com.mysql:mysql-connector-j:8.4.0") } jib { diff --git a/validator/src/main/java/com/amazon/aoc/validators/CWLogValidator.java b/validator/src/main/java/com/amazon/aoc/validators/CWLogValidator.java index 401281cb0..3c4bbceec 100644 --- a/validator/src/main/java/com/amazon/aoc/validators/CWLogValidator.java +++ b/validator/src/main/java/com/amazon/aoc/validators/CWLogValidator.java @@ -66,9 +66,11 @@ public void validate() throws Exception { String operation = (String) expectedAttributes.get("Operation"); String remoteService = (String) expectedAttributes.get("RemoteService"); String remoteOperation = (String) expectedAttributes.get("RemoteOperation"); + String remoteResourceType = (String) expectedAttributes.get("RemoteResourceType"); + String remoteResourceIdentifier = (String) expectedAttributes.get("RemoteResourceIdentifier"); Map actualLog = - this.getActualLog(operation, remoteService, remoteOperation); + this.getActualLog(operation, remoteService, remoteOperation, remoteResourceType, remoteResourceIdentifier); log.info("Value of an actual log: {}", actualLog); if (actualLog == null) throw new BaseException(ExceptionCode.EXPECTED_LOG_NOT_FOUND); @@ -126,7 +128,7 @@ private JsonifyArrayList> getExpectedAttributes() throws Exc } private Map getActualLog( - String operation, String remoteService, String remoteOperation) throws Exception { + String operation, String remoteService, String remoteOperation, String remoteResourceType, String remoteResourceIdentifier) throws Exception { String dependencyFilter = null; // Dependency calls will have the remoteService and remoteOperation attribute, but service calls @@ -139,6 +141,10 @@ private Map getActualLog( dependencyFilter = String.format("&& ($.RemoteService = \"%s\") && ($.RemoteOperation = \"%s\")", remoteService, remoteOperation); } + if (remoteResourceType != null && remoteResourceIdentifier != null) { + dependencyFilter += String.format(" && ($.RemoteResourceType = %%%s%%) && ($.RemoteResourceIdentifier = %%%s%%)", remoteResourceType, remoteResourceIdentifier); + } + String filterPattern = String.format("{ ($.Service = %s) && ($.Operation = \"%s\") %s }", context.getServiceName(), operation, dependencyFilter); log.info("Filter Pattern for Log Search: " + filterPattern); diff --git a/validator/src/main/resources/expected-data-template/java/eks/rds-mysql-trace.mustache b/validator/src/main/resources/expected-data-template/java/eks/rds-mysql-trace.mustache index 7843a9d9e..d30d80aa5 100644 --- a/validator/src/main/resources/expected-data-template/java/eks/rds-mysql-trace.mustache +++ b/validator/src/main/resources/expected-data-template/java/eks/rds-mysql-trace.mustache @@ -26,8 +26,8 @@ "default": { "EC2.AutoScalingGroup": "^eks-.+", "EKS.Cluster": "^{{platformInfo}}$", - "K8s.Namespace": "^{{appNamespace}}", - "otel.resource.K8s.Workload": "^sample-app-deployment-{{testingId}}", + "K8s.Namespace": "^{{appNamespace}}$", + "otel.resource.K8s.Workload": "^sample-app-deployment-{{testingId}}$", "otel.resource.K8s.Node": "^i-[A-Za-z0-9]{17}$", "otel.resource.K8s.Pod": "^sample-app-deployment-{{testingId}}(-[A-Za-z0-9]*)*$", "otel.resource.host.name": "^ip(-[0-9]{1,3}){4}.*$", @@ -50,6 +50,12 @@ "aws.local.operation": "^GET /mysql$" }, "subsegments": [ + { + "name": "^mysql$", + "sql": { + "url": "^Create connection$" + } + }, { "name": "^mysql$", "sql": { @@ -61,7 +67,7 @@ "aws.remote.operation": "^SELECT$", "aws.local.operation": "^GET /mysql$", "aws.remote.resource.type": "^DB::Connection$", - "aws.remote.resource.identifier": "{{remoteResourceIdentifier}}", + "aws.remote.resource.identifier": "^{{remoteResourceIdentifier}}$", "aws.remote.service": "^mysql$", "aws.local.service": "^{{serviceName}}$", "aws.local.environment": "^eks:{{platformInfo}}/{{appNamespace}}$" @@ -83,4 +89,4 @@ } ] } -] \ No newline at end of file +]