Skip to content

Commit

Permalink
PR Cleanup (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
okankoAMZ committed Aug 16, 2023
1 parent c25c1a2 commit a38cbff
Show file tree
Hide file tree
Showing 19 changed files with 43 additions and 314 deletions.
52 changes: 0 additions & 52 deletions mock_server/certificates/private.key

This file was deleted.

36 changes: 0 additions & 36 deletions mock_server/certificates/ssl/ca-bundle.crt

This file was deleted.

36 changes: 0 additions & 36 deletions mock_server/certificates/ssl/certificate.crt

This file was deleted.

File renamed without changes.
5 changes: 0 additions & 5 deletions mock_server/README → mockserver/README
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
# Mocked Servers

Most of the tests use mocked servers as stand-ins for the exporters to send to.
The docker images are built and pushed to ECR as part of `terraform/imagebuild` and then used in the tests as part of `defaults/docker_compose.tpl`.

Most will use the `https` mocked_server, but some test cases like `otlp_grpc_exporter_metric_mock` and `otlp_grpc_exporter_trace_mock` will need to use the `grpc_metrics` and `grpc_trace` mocked_servers.

The servers themselves are very basic. They listen for a message and tend to set a flag to success upon receiving it. Typically, they are set up with two servers: one to mock the backend and one to report on the status of that mock (if endpoint is called, how many times, etc.). There's a built-in 15ms of latency between each message that's received. The status reporter will always be on port 8080 and support the `:8080/` (returns "healthcheck") and the `:8080/check-data` (returns "success" if mock has received messages) endpoints.
Empty file.
Empty file.
Empty file.
10 changes: 5 additions & 5 deletions mock_server/http_server.go → mockserver/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ func healthCheck(w http.ResponseWriter, _ *http.Request) {

func (ts *transactionStore) checkData(w http.ResponseWriter, _ *http.Request) {
var message string
var t =atomic.LoadUint32(&ts.transactions)
if t > 0 {
var t = atomic.LoadUint32(&ts.transactions)
if t > 0 {
message = SuccessMessage
}
fmt.Printf("\033[31m Time: %d | checkData msg: %s | %d\033[0m \n", time.Now().Unix(), message,t)
fmt.Printf("\033[31m Time: %d | checkData msg: %s | %d\033[0m \n", time.Now().Unix(), message, t)
if _, err := io.WriteString(w, message); err != nil {
io.WriteString(w, err.Error())
log.Printf("Unable to write response: %v", err)
Expand Down Expand Up @@ -88,7 +88,7 @@ func (ts *transactionStore) tpm(w http.ResponseWriter, _ *http.Request) {

// Starts an HTTPS server that receives requests for the data handler service at the sample server port
// Starts an HTTP server that receives request from validator only to verify the data ingestion
func startHttpServer() chan interface{} {
func StartHttpServer() chan interface{} {
serverControlChan := make(chan interface{})
log.Println("\033[31m Starting Server \033[0m")
store := transactionStore{startTime: time.Now()}
Expand All @@ -102,7 +102,7 @@ func startHttpServer() chan interface{} {
dataApp.PathPrefix("/put-data").HandlerFunc(ts.dataReceived)
dataApp.HandleFunc("/trace/v1", ts.dataReceived)
dataApp.HandleFunc("/metric/v1", ts.dataReceived)
if err := daemonServer.ListenAndServeTLS(CertFilePath, KeyFilePath ); err != nil {
if err := daemonServer.ListenAndServeTLS(CertFilePath, KeyFilePath); err != nil {
log.Fatalf("HTTPS server error: %v", err)
err = daemonServer.Shutdown(context.TODO())
log.Fatalf("Shutdown server error: %v", err)
Expand Down
19 changes: 3 additions & 16 deletions mock_server/http_server_test.go → mockserver/http_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,29 +83,16 @@ func HttpServerCheckTPM(t *testing.T) {
assert.Truef(t, tpm.(float64) > 1, "tpm is less than 1 %f", tpm)
}

// func HttpServerSendData(t *testing.T,) {
// var wg sync.WaitGroup
// wg.Add(2)
// go func(){
// defer wg.Done()
// for i := 1; i < 5; i++ {
// HttpServerCheckTPM(t)
// time.Sleep(TPM_CHECK_INTERVAL)
// }
// }()
// wg.Wait()
// }
func TestMockServer(t *testing.T) {
serverControlChan := startHttpServer()
serverControlChan := StartHttpServer()
time.Sleep(3 * time.Second)
HttpServerSanityCheck(t, APP_SERVER)
HttpsServerSanityCheck(t, DATA_SERVER)
// HttpServerSendData(t)
// time.Sleep(1 * time.Minute)
time.Sleep(5 * time.Minute)
serverControlChan <- 0

}

func TestStartMockServer(t *testing.T) {
startHttpServer()
StartHttpServer()
}
File renamed without changes.
9 changes: 7 additions & 2 deletions terraform/performance/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ resource "null_resource" "install_binaries" {
"aws s3 cp s3://${var.s3_bucket}/integration-test/packaging/${var.cwa_github_sha}/amazon-cloudwatch-agent.msi .",
"aws s3 cp s3://${var.s3_bucket}/integration-test/binary/${var.cwa_github_sha}/${var.family}/${var.arc}/${local.install_package} .",
"aws s3 cp s3://${var.s3_bucket}/integration-test/validator/${var.cwa_github_sha}/${var.family}/${var.arc}/${local.install_validator} .",
"git clone https://github.com/okankoAMZ/amazon-cloudwatch-agent-test.git",
"cp -r amazon-cloudwatch-agent-test/test/xray/resources /home/ec2-user/",
local.ami_family["install_command"],
]
}
Expand All @@ -113,7 +111,14 @@ resource "null_resource" "validator_linux" {
inline = [
"export AWS_REGION=${var.region}",
"sudo chmod +x ./${local.install_validator}",
#mock server dependencies getting transfered.
"git clone https://github.com/okankoAMZ/amazon-cloudwatch-agent-test.git",
"cd amazon-cloudwatch-agent-test && git checkout xray-performance-test && cd ..",
"cp -r amazon-cloudwatch-agent-test/test/xray/resources /home/ec2-user/",
"cp -a amazon-cloudwatch-agent-test/mockserver/. /home/ec2-user/",
"make update-certs",
"./${local.install_validator} --validator-config=${module.validator.instance_validator_config} --preparation-mode=true",
"sudo setcap 'cap_net_bind_service=+ep' validator",
local.start_command,
"./${local.install_validator} --validator-config=${module.validator.instance_validator_config} --preparation-mode=false",
]
Expand Down
95 changes: 0 additions & 95 deletions test/performance/trace/xray/agent_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,100 +8,5 @@
"xray": {
}
}
},
"metrics": {
"namespace": "CloudWatchAgentPerformance",
"append_dimensions": {
"InstanceId": "${aws:InstanceId}"
},
"metrics_collected": {
"cpu": {
"measurement": [
"time_active", "time_guest", "time_guest_nice", "time_idle", "time_iowait", "time_irq",
"time_nice", "time_softirq", "time_steal", "time_system", "time_user",
"usage_active", "usage_guest", "usage_guest_nice", "usage_idle", "usage_iowait", "usage_irq",
"usage_nice", "usage_softirq", "usage_steal", "usage_system", "usage_user"
],
"metrics_collection_interval": 1
},
"swap": {
"measurement": [
"free","used","used_percent"
],
"metrics_collection_interval": 1
},
"processes": {
"measurement": [
"blocked","running","sleeping","stopped","total","dead","idle","paging","total_threads","zombies"
],
"metrics_collection_interval": 1
},
"netstat": {
"measurement": [
"tcp_close","tcp_close_wait","tcp_closing", "tcp_established","tcp_fin_wait1","tcp_fin_wait2","tcp_last_ack",
"tcp_listen","tcp_none","tcp_syn_sent","tcp_syn_recv","tcp_time_wait","udp_socket"
],
"metrics_collection_interval": 1
},
"mem": {
"measurement": [
"active", "available", "available_percent", "buffered", "cached", "free", "inactive", "total",
"used", "used_percent"
],
"metrics_collection_interval": 1
},
"diskio": {
"resources": [
"*"
],
"measurement": [
"iops_in_progress", "io_time", "reads", "read_bytes", "read_time", "writes", "write_bytes", "write_time"
],
"metrics_collection_interval": 1
},
"disk": {
"resources": [
"*"
],
"measurement": [
"free","inodes_free","inodes_total","inodes_used","total","used","used_percent"
],
"drop_device": true,
"metrics_collection_interval": 1
},
"ethtool": {
"interface_include": [
"eth0",
"ens5"
],
"metrics_include": [
"queue_0_tx_cnt","queue_0_rx_cnt"
]
},
"net": {
"resources": [
"eth0"
],
"measurement": [
"bytes_sent", "bytes_recv", "drop_in", "drop_out", "err_in", "err_out", "packets_sent", "packets_recv"
],
"metrics_collection_interval": 1
},
"procstat": [
{
"exe": "cloudwatch-agent",
"measurement": [
"cpu_usage",
"memory_rss",
"memory_swap",
"memory_vms",
"memory_data",
"num_fds",
"write_bytes"
],
"metrics_collection_interval": 1
}
]
}
}
}
20 changes: 11 additions & 9 deletions util/common/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package common
import (
"context"
"encoding/json"
"log"
"reflect"
"testing"
"time"
Expand Down Expand Up @@ -112,13 +113,14 @@ func SegmentValidationTest(t *testing.T, traceTest TraceTestConfig, segments []t
return nil

}
func GenerateTraces(traceTest TraceTestConfig) error{
CopyFile(traceTest.AgentConfigPath, ConfigOutputPath)
go func() {
traceTest.Generator.StartSendingTraces(context.Background())
}()
time.Sleep(traceTest.AgentRuntime)
traceTest.Generator.StopSendingTraces()
time.Sleep(AGENT_SHUTDOWN_DELAY)
return nil
func GenerateTraces(traceTest TraceTestConfig) error {
CopyFile(traceTest.AgentConfigPath, ConfigOutputPath)
go func() {
err := traceTest.Generator.StartSendingTraces(context.Background())
log.Printf("Error sending traces: %v", err)
}()
time.Sleep(traceTest.AgentRuntime)
traceTest.Generator.StopSendingTraces()
time.Sleep(AGENT_SHUTDOWN_DELAY)
return nil
}
17 changes: 0 additions & 17 deletions validator/resources/sampling-rule.json

This file was deleted.

11 changes: 0 additions & 11 deletions validator/resources/xray-config.json

This file was deleted.

Loading

0 comments on commit a38cbff

Please sign in to comment.