Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
musa-asad committed Dec 19, 2024
1 parent 917a606 commit 975168c
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 43 deletions.
2 changes: 1 addition & 1 deletion generator/test_case_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ var testTypeToTestConfig = map[string][]testConfig{
}

var testTypeToTestConfigE2E = map[string][]testConfig{
"eks_e2e": {
"eks_e2e_jmx": {
{testDir: "../../../test/e2e/jmx"},
},
}
Expand Down
2 changes: 1 addition & 1 deletion terraform/eks/e2e/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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} \
Expand Down
39 changes: 31 additions & 8 deletions test/e2e/jmx/jmx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

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

Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -153,15 +165,15 @@ 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)
})
}
})
}

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")

Expand Down Expand Up @@ -198,14 +210,25 @@ 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",
}

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)
})
}
})
Expand Down Expand Up @@ -236,15 +259,15 @@ 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)
})
}
})
}

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")

Expand Down
37 changes: 13 additions & 24 deletions test/e2e/jmx/resources/cwagent_configs/kafka.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
}
Expand Down
12 changes: 3 additions & 9 deletions test/e2e/jmx/resources/sample_apps/kafka.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
---
Expand All @@ -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
Expand All @@ -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"
args: ["-c", "kafka-console-consumer.sh --bootstrap-server kafka-service:9092 --topic test-topic --from-beginning"]

0 comments on commit 975168c

Please sign in to comment.