-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
25235f8
commit 65ea3f3
Showing
3 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Proxy load testing | ||
|
||
defaults: | ||
run: | ||
working-directory: grid-proxy | ||
on: | ||
schedule: | ||
- cron: 0 21 * * * | ||
workflow_dispatch: | ||
|
||
jobs: | ||
load_test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: 1.21 | ||
|
||
- name: Run Load Testing | ||
run: | | ||
go mod tidy | ||
cd tests/load_testing | ||
go test -v | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package load_test | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"os" | ||
"time" | ||
|
||
prometheus_integration "github.com/threefoldtech/tfgrid-sdk-go/grid-proxy/tests/load_testing/prometheus" | ||
vegeta "github.com/tsenart/vegeta/v12/lib" | ||
"gopkg.in/yaml.v2" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
func PerformLoadTesting() error { | ||
|
||
data, err := os.ReadFile("test.yml") | ||
if err != nil { | ||
return fmt.Errorf("Failed to read YAML file: %v", err) | ||
} | ||
var loadTest LoadTest | ||
err = yaml.Unmarshal(data, &loadTest) | ||
if err != nil { | ||
return fmt.Errorf("Failed to unmarshal YAML: %v", err) | ||
} | ||
|
||
var targets []vegeta.Target | ||
for _, endpoint := range loadTest.Endpoints { | ||
targets = append(targets, vegeta.Target{ | ||
Method: "GET", | ||
URL: loadTest.BaseUrl + endpoint, | ||
}) | ||
} | ||
|
||
attacker := vegeta.NewAttacker() | ||
|
||
rate := vegeta.Rate{Freq: loadTest.Freq, Per: time.Second} | ||
duration := loadTest.Duration * time.Second | ||
|
||
reg := prometheus.NewRegistry() | ||
pm := prometheus_integration.NewMetrics() | ||
|
||
if err := pm.Register(reg); err != nil { | ||
log.Fatal("error registering metrics", err) | ||
} | ||
|
||
go func() { | ||
fmt.Println("Prometheus metrics server running on :9090/metrics") | ||
log.Fatal(http.ListenAndServe(":9090", prometheus_integration.NewHandler(reg, time.Now().UTC()))) | ||
}() | ||
|
||
var results vegeta.Metrics | ||
for res := range attacker.Attack(vegeta.NewStaticTargeter(targets...), rate, duration, "load testing") { | ||
results.Add(res) | ||
pm.Observe(res) | ||
} | ||
|
||
results.Close() | ||
|
||
successRate := results.Success * 100 | ||
errorRate := (1.0 - results.Success) * 100 | ||
pm.SuccessRate.Set(successRate) | ||
pm.ErrorRate.Set(errorRate) | ||
pm.AvgLatency.Set(results.Latencies.Mean.Seconds()) | ||
pm.MaxLatency.Set(results.Latencies.Max.Seconds()) | ||
|
||
fmt.Printf("Success Rate: %.2f%%\n", successRate) | ||
fmt.Printf("Error Rate: %.2f%%\n", errorRate) | ||
fmt.Printf("Average Latency: %v\n", results.Latencies.Mean.Seconds()) | ||
fmt.Printf("Maximum Latency: %v\n", results.Latencies.Max.Seconds()) | ||
|
||
return nil | ||
} | ||
|
||
type LoadTest struct { | ||
BaseUrl string `yaml:"base_url"` | ||
Endpoints []string `yaml:"endpoints"` | ||
Freq int `yaml:"rate_second"` | ||
Duration time.Duration `yaml:"duration"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package load_test | ||
|
||
import "testing" | ||
|
||
func TestLoad(t *testing.T) { | ||
err := PerformLoadTesting() | ||
if err != nil { | ||
t.Fatalf("Load test failed: %v", err) | ||
} | ||
} |