Skip to content

Commit

Permalink
PR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
okankoAMZ committed Sep 18, 2023
1 parent 6491d06 commit de1f4ab
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 31 deletions.
7 changes: 2 additions & 5 deletions generator/test_case_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ type matrixRow struct {
TerraformDir string `json:"terraform_dir"`
UseSSM bool `json:"useSSM"`
ExcludedTests string `json:"excludedTests"`
RunMockServer bool `json:"run_mock_server"`
MetadataEnabled string `json:"metadataEnabled"`
}

Expand Down Expand Up @@ -123,8 +122,7 @@ var testTypeToTestConfig = map[string][]testConfig{
{testDir: "../../test/performance/system"},
{testDir: "../../test/performance/statsd"},
{testDir: "../../test/performance/collectd"},
{testDir: "../../test/performance/trace/xray",
runMockServer: true},
{testDir: "../../test/performance/trace/xray",runMockServer: true},
},
"ec2_windows_performance": {
{testDir: "../../test/performance/windows/logs"},
Expand Down Expand Up @@ -227,8 +225,7 @@ func genMatrix(testType string, testConfigs []testConfig) []matrixRow {
testMatrixComplete := make([]matrixRow, 0, len(testMatrix))
for _, test := range testMatrix {
for _, testConfig := range testConfigs {
row := matrixRow{TestDir: testConfig.testDir, TestType: testType, TerraformDir: testConfig.terraformDir,
RunMockServer: testConfig.runMockServer}
row := matrixRow{TestDir: testConfig.testDir, TestType: testType, TerraformDir: testConfig.terraformDir}
err = mapstructure.Decode(test, &row)
if err != nil {
log.Panicf("can't decode map test %v to metric line struct with error %v", testConfig, err)
Expand Down
39 changes: 13 additions & 26 deletions mockserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"log"
"net/http"
"path"
"sync"
"sync/atomic"
"time"

Expand All @@ -47,7 +48,7 @@ type TransactionPayload struct {
TransactionsPerMinute float64 `json:"tpm"`
}

func healthCheck(w http.ResponseWriter, _ *http.Request) {
func healthCheck(w http.ResponseWriter, _ *http.Request) {
if _, err := io.WriteString(w, HealthCheckMessage); err != nil {
log.Printf("Unable to write response: %v", err)
}
Expand Down Expand Up @@ -91,56 +92,42 @@ 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{} {
serverControlChan := make(chan interface{})
func StartHttpServer() {
var wg sync.WaitGroup
log.Println("\033[31m Starting Server \033[0m")
store := transactionStore{startTime: time.Now()}
dataApp := mux.NewRouter()
daemonServer := &http.Server{Addr: ":443", Handler: dataApp}
verifyApp := http.NewServeMux()
appServer := &http.Server{Addr: ":8080", Handler: verifyApp}
go func(ts *transactionStore) {
defer close(serverControlChan)
dataApp.HandleFunc("/", healthCheck)
wg.Add(1)
dataApp.HandleFunc("/ping", healthCheck)
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 {
log.Fatalf("HTTPS server error: %v", err)
log.Printf("HTTPS server error: %v", err)
err = daemonServer.Shutdown(context.TODO())
log.Fatalf("Shutdown server error: %v", err)
}
}(&store)

go func(ts *transactionStore) {
defer close(serverControlChan)
verifyApp.HandleFunc("/", healthCheck)
wg.Add(1)
verifyApp.HandleFunc("/ping", healthCheck)
verifyApp.HandleFunc("/check-data", ts.checkData)
verifyApp.HandleFunc("/tpm", ts.tpm)
if err := appServer.ListenAndServe(); err != nil {
log.Fatalf("Verification server error: %v", err)
log.Printf("Verification server error: %v", err)
err := appServer.Shutdown(context.TODO())
log.Fatalf("Shuwdown server error: %v", err)
}
}(&store)
go func() {
for {
select {
case <-serverControlChan:
log.Println("\033[32m Stopping Server \033[0m")

}
}
}()

return serverControlChan
wg.Done()
log.Println("\033[32m Stopping Server \033[0m")
}

func main() {
server := StartHttpServer()
select {
case <-server:
fmt.Println("server is dead")

}
StartHttpServer()
}

0 comments on commit de1f4ab

Please sign in to comment.