From 975168c026fb41625b1b3cff942b189271ad0294 Mon Sep 17 00:00:00 2001 From: musa-asad Date: Thu, 19 Dec 2024 08:30:59 -0500 Subject: [PATCH] clean --- ...trix.json => eks_e2e_jmx_test_matrix.json} | 0 generator/test_case_generator.go | 2 +- terraform/eks/e2e/main.tf | 2 +- test/e2e/jmx/jmx_test.go | 39 +++++++++++++++---- .../jmx/resources/cwagent_configs/kafka.json | 37 +++++++----------- test/e2e/jmx/resources/sample_apps/kafka.yaml | 12 ++---- 6 files changed, 49 insertions(+), 43 deletions(-) rename generator/resources/{eks_e2e_test_matrix.json => eks_e2e_jmx_test_matrix.json} (100%) diff --git a/generator/resources/eks_e2e_test_matrix.json b/generator/resources/eks_e2e_jmx_test_matrix.json similarity index 100% rename from generator/resources/eks_e2e_test_matrix.json rename to generator/resources/eks_e2e_jmx_test_matrix.json diff --git a/generator/test_case_generator.go b/generator/test_case_generator.go index f5887186e..4daaae1d2 100644 --- a/generator/test_case_generator.go +++ b/generator/test_case_generator.go @@ -248,7 +248,7 @@ var testTypeToTestConfig = map[string][]testConfig{ } var testTypeToTestConfigE2E = map[string][]testConfig{ - "eks_e2e": { + "eks_e2e_jmx": { {testDir: "../../../test/e2e/jmx"}, }, } diff --git a/terraform/eks/e2e/main.tf b/terraform/eks/e2e/main.tf index 470dc0b65..f9b91713c 100644 --- a/terraform/eks/e2e/main.tf +++ b/terraform/eks/e2e/main.tf @@ -144,7 +144,7 @@ resource "null_resource" "validator" { provisioner "local-exec" { when = destroy command = <<-EOT - echo "Running cleanup before destruction" + echo "Running cleanup for K8s resources" go test -timeout 15m -v ${self.triggers.test_dir} \ -destroy=true \ -region=${self.triggers.region} \ diff --git a/test/e2e/jmx/jmx_test.go b/test/e2e/jmx/jmx_test.go index 3c070c36b..b78ea2f9b 100644 --- a/test/e2e/jmx/jmx_test.go +++ b/test/e2e/jmx/jmx_test.go @@ -80,7 +80,19 @@ func TestMain(m *testing.M) { os.Exit(m.Run()) } -func TestResources(t *testing.T) { +func TestAll(t *testing.T) { + t.Run("Resources", func(t *testing.T) { + testResources(t) + }) + + if !t.Failed() { + t.Run("Metrics", func(t *testing.T) { + testMetrics(t) + }) + } +} + +func testResources(t *testing.T) { config, err := clientcmd.BuildConfigFromFlags("", filepath.Join(os.Getenv("HOME"), ".kube", "config")) require.NoError(t, err, "Error building kubeconfig") @@ -108,7 +120,7 @@ func TestResources(t *testing.T) { require.NotNil(t, serviceAccount, "CloudWatch Agent Service Account not found") } -func TestMetrics(t *testing.T) { +func testMetrics(t *testing.T) { env := environment.GetEnvironmentMetaData() configFile := filepath.Base(env.AgentConfig) @@ -126,7 +138,6 @@ func TestMetrics(t *testing.T) { func testTomcatMetrics(t *testing.T) { t.Run("verify_jvm_tomcat_metrics", func(t *testing.T) { metricsToCheck := []string{ - "tomcat.traffic", "jvm.classes.loaded", "jvm.gc.collections.count", "jvm.gc.collections.elapsed", @@ -143,6 +154,7 @@ func testTomcatMetrics(t *testing.T) { "jvm.memory.pool.used", "jvm.memory.pool.committed", "jvm.threads.count", + "tomcat.traffic", "tomcat.sessions", "tomcat.errors", "tomcat.request_count", @@ -153,7 +165,7 @@ func testTomcatMetrics(t *testing.T) { for _, metric := range metricsToCheck { t.Run(metric, func(t *testing.T) { - awsservice.ValidateMetricWithTest(t, metric, metric, nil, 5, 1*time.Minute) + awsservice.ValidateMetricWithTest(t, metric, "JVM_TOMCAT_E2E", nil, 5, 30*time.Second) }) } }) @@ -161,7 +173,7 @@ func testTomcatMetrics(t *testing.T) { func testTomcatSessions(t *testing.T) { t.Run("verify_tomcat_sessions", func(t *testing.T) { - cmd := exec.Command("kubectl", "get", "svc", "tomcat-service", "-o", "jsonpath='{.status.loadBalancer.ingress[0].hostname}'") + cmd := exec.Command("kubectl", "get", "svc", "tomcat-service", "-n", "test", "-o", "jsonpath='{.status.loadBalancer.ingress[0].hostname}'") output, err := cmd.CombinedOutput() require.NoError(t, err, "Error getting LoadBalancer URL") @@ -198,6 +210,17 @@ func testTomcatSessions(t *testing.T) { func testKafkaMetrics(t *testing.T) { t.Run("verify_kafka_metrics", func(t *testing.T) { metricsToCheck := []string{ + "kafka.message.count", + "kafka.request.count", + "kafka.request.failed", + "kafka.request.time.total", + "kafka.request.time.50p", + "kafka.request.time.99p", + "kafka.request.time.avg", + "kafka.producer.io-wait-time-ns-avg", + "kafka.producer.outgoing-byte-rate", + "kafka.producer.request-rate", + "kafka.producer.response-rate", "kafka.consumer.fetch-rate", "kafka.consumer.total.bytes-consumed-rate", "kafka.consumer.total.records-consumed-rate", @@ -205,7 +228,7 @@ func testKafkaMetrics(t *testing.T) { for _, metric := range metricsToCheck { t.Run(metric, func(t *testing.T) { - awsservice.ValidateMetricWithTest(t, metric, "KAFKA_E2E", nil, 5, 1*time.Minute) + awsservice.ValidateMetricWithTest(t, metric, "KAFKA_E2E", nil, 5, 30*time.Second) }) } }) @@ -236,7 +259,7 @@ func testContainerInsightsMetrics(t *testing.T) { for _, metric := range metricsToCheck { t.Run(metric, func(t *testing.T) { - awsservice.ValidateMetricWithTest(t, metric, "ContainerInsights/Prometheus", nil, 5, 1*time.Minute) + awsservice.ValidateMetricWithTest(t, metric, "ContainerInsights/Prometheus", nil, 5, 30*time.Second) }) } }) @@ -244,7 +267,7 @@ func testContainerInsightsMetrics(t *testing.T) { func testTomcatRejectedSessions(t *testing.T) { t.Run("verify_catalina_manager_rejectedsessions", func(t *testing.T) { - cmd := exec.Command("kubectl", "get", "svc", "tomcat-service", "-o", "jsonpath='{.status.loadBalancer.ingress[0].hostname}'") + cmd := exec.Command("kubectl", "get", "svc", "tomcat-service", "-n", "test", "-o", "jsonpath='{.status.loadBalancer.ingress[0].hostname}'") output, err := cmd.CombinedOutput() require.NoError(t, err, "Error getting LoadBalancer URL") diff --git a/test/e2e/jmx/resources/cwagent_configs/kafka.json b/test/e2e/jmx/resources/cwagent_configs/kafka.json index dce338b31..4fc5c2a82 100644 --- a/test/e2e/jmx/resources/cwagent_configs/kafka.json +++ b/test/e2e/jmx/resources/cwagent_configs/kafka.json @@ -3,41 +3,30 @@ "namespace": "KAFKA_E2E", "metrics_collected": { "jmx": { - "kafka-consumer": { + "kafka": { "measurement": [ - "kafka.consumer.total.records-consumed-rate", - "kafka.consumer.total.bytes-consumed-rate", - "kafka.consumer.fetch-rate", - "kafka.consumer.records-lag-max", - "kafka.consumer.total.fetch-size-avg", - "kafka.consumer.bytes-consumed-rate", - "kafka.consumer.fetch-size-avg", - "kafka.consumer.records-consumed-rate" + "kafka.message.count", + "kafka.request.count", + "kafka.request.failed", + "kafka.request.time.total", + "kafka.request.time.50p", + "kafka.request.time.99p", + "kafka.request.time.avg" ] }, "kafka-producer": { "measurement": [ "kafka.producer.io-wait-time-ns-avg", "kafka.producer.outgoing-byte-rate", - "kafka.producer.request-latency-avg", "kafka.producer.request-rate", - "kafka.producer.response-rate", - "kafka.producer.byte-rate", - "kafka.producer.compression-rate", - "kafka.producer.record-error-rate", - "kafka.producer.record-retry-rate", - "kafka.producer.record-send-rate" + "kafka.producer.response-rate" ] }, - "kafka": { + "kafka-consumer": { "measurement": [ - "kafka.message.count", - "kafka.request.count", - "kafka.request.failed", - "kafka.request.time.total", - "kafka.request.time.50p", - "kafka.request.time.99p", - "kafka.request.time.avg" + "kafka.consumer.total.records-consumed-rate", + "kafka.consumer.total.bytes-consumed-rate", + "kafka.consumer.fetch-rate" ] } } diff --git a/test/e2e/jmx/resources/sample_apps/kafka.yaml b/test/e2e/jmx/resources/sample_apps/kafka.yaml index 8c3588613..8e1680f1d 100644 --- a/test/e2e/jmx/resources/sample_apps/kafka.yaml +++ b/test/e2e/jmx/resources/sample_apps/kafka.yaml @@ -80,7 +80,7 @@ spec: - name: KAFKA_LISTENERS value: "PLAINTEXT://:9092" - name: KAFKA_ADVERTISED_LISTENERS - value: "PLAINTEXT://:9092" + value: "PLAINTEXT://kafka-service:9092" - name: KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR value: "1" --- @@ -106,10 +106,7 @@ spec: - name: kafka-producer image: public.ecr.aws/l9b8e0i6/kafka:latest command: ["/bin/sh"] - args: ["-c", "while true; do echo 'Producing message'; kafka-console-producer.sh --broker-list kafka-service:9092 --topic test-topic | 'Test message'; sleep 5; done"] - env: - - name: KAFKA_BROKER_LIST - value: "kafka-service:9092" + args: ["-c", "while true; do echo 'Test message' | kafka-console-producer.sh --broker-list kafka-service:9092 --topic test-topic; sleep 5; done"] --- apiVersion: apps/v1 kind: Deployment @@ -133,7 +130,4 @@ spec: - name: kafka-consumer image: public.ecr.aws/l9b8e0i6/kafka:latest command: ["/bin/sh"] - args: ["-c", "kafka-console-consumer.sh --bootstrap-server kafka-service:9092 --topic test-topic --from-beginning"] - env: - - name: KAFKA_BROKER_LIST - value: "kafka-service:9092" \ No newline at end of file + args: ["-c", "kafka-console-consumer.sh --bootstrap-server kafka-service:9092 --topic test-topic --from-beginning"] \ No newline at end of file