Skip to content

Commit 23fc058

Browse files
authored
Add autobake loadtest config and report generation logic (#18)
1 parent 4beeef7 commit 23fc058

8 files changed

Lines changed: 295 additions & 116 deletions

File tree

config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ type LoadConfig struct {
1717
Scenarios []Scenario `json:"scenarios,omitempty"`
1818
MockDeploy bool `json:"mockDeploy,omitempty"`
1919
Settings *Settings `json:"settings,omitempty"`
20+
// Path to write a JSON report of the load test.
21+
ReportPath string `json:"reportPath,omitempty"`
2022
}
2123

2224
// Duration wraps time.Duration to provide JSON unmarshaling support

config/settings.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type Settings struct {
2121
TrackUserLatency bool `json:"trackUserLatency"`
2222
Prewarm bool `json:"prewarm"`
2323
RampUp bool `json:"rampUp"`
24+
ReportPath string `json:"reportPath"`
2425
}
2526

2627
// DefaultSettings returns the default configuration values
@@ -37,6 +38,7 @@ func DefaultSettings() Settings {
3738
TrackUserLatency: false,
3839
Prewarm: false,
3940
RampUp: false,
41+
ReportPath: "",
4042
}
4143
}
4244

@@ -55,6 +57,7 @@ func InitializeViper(cmd *cobra.Command) error {
5557
"trackUserLatency": "track-user-latency",
5658
"workers": "workers",
5759
"rampUp": "ramp-up",
60+
"reportPath": "report-path",
5861
}
5962

6063
for viperKey, flagName := range flagBindings {
@@ -76,6 +79,7 @@ func InitializeViper(cmd *cobra.Command) error {
7679
viper.SetDefault("trackUserLatency", defaults.TrackUserLatency)
7780
viper.SetDefault("workers", defaults.Workers)
7881
viper.SetDefault("rampUp", defaults.RampUp)
82+
viper.SetDefault("reportPath", defaults.ReportPath)
7983
return nil
8084
}
8185

@@ -107,5 +111,6 @@ func ResolveSettings() Settings {
107111
TrackUserLatency: viper.GetBool("trackUserLatency"),
108112
Prewarm: viper.GetBool("prewarm"),
109113
RampUp: viper.GetBool("rampUp"),
114+
ReportPath: viper.GetString("reportPath"),
110115
}
111116
}

config/settings_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func TestArgumentPrecedence(t *testing.T) {
9191
cmd.Flags().Bool("track-user-latency", false, "Track user latency")
9292
cmd.Flags().Int("buffer-size", 0, "Buffer size")
9393
cmd.Flags().Bool("ramp-up", false, "Ramp up loadtest")
94+
cmd.Flags().String("report-path", "", "Report path")
9495

9596
// Parse CLI args
9697
if len(tt.cliArgs) > 0 {
@@ -130,6 +131,7 @@ func TestDefaultSettings(t *testing.T) {
130131
TrackUserLatency: false,
131132
Prewarm: false,
132133
RampUp: false,
134+
ReportPath: "",
133135
}
134136

135137
if defaults != expected {

main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func init() {
6464
rootCmd.Flags().IntP("nodes", "n", 0, "Number of nodes/endpoints to use (0 = use all)")
6565
rootCmd.Flags().String("metricsListenAddr", "0.0.0.0:9090", "The ip:port on which to export prometheus metrics.")
6666
rootCmd.Flags().Bool("ramp-up", false, "Ramp up loadtest")
67+
rootCmd.Flags().String("report-path", "", "Path to save the report")
6768

6869
// Initialize Viper with proper error handling
6970
if err := config.InitializeViper(rootCmd); err != nil {
@@ -148,7 +149,7 @@ func runLoadTest(ctx context.Context, cmd *cobra.Command, args []string) error {
148149

149150
// Create statistics collector and logger
150151
collector := stats.NewCollector()
151-
logger := stats.NewLogger(collector, settings.StatsInterval.ToDuration(), settings.Debug)
152+
logger := stats.NewLogger(collector, settings.StatsInterval.ToDuration(), settings.ReportPath, settings.Debug)
152153
var ramper *sender.Ramper
153154

154155
err = service.Run(ctx, func(ctx context.Context, s service.Scope) error {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"chainId": 713714,
3+
"seiChainId": "sei-autobake",
4+
"endpoints": [
5+
"https://evm-rpc.sei-autobake.seinetwork.io"
6+
],
7+
"accounts": {
8+
"count": 5000,
9+
"newAccountRate": 0.0
10+
},
11+
"scenarios": [
12+
{
13+
"name": "EVMTransfer",
14+
"weight": 1
15+
}
16+
],
17+
"settings": {
18+
"workers": 500,
19+
"tps": 0,
20+
"statsInterval": "5s",
21+
"bufferSize": 1000,
22+
"dryRun": false,
23+
"debug": false,
24+
"trackReceipts": false,
25+
"trackBlocks": false,
26+
"trackUserLatency": false,
27+
"prewarm": false,
28+
"reportPath": "/home/ubuntu/evm_transfer_report.txt"
29+
}
30+
}

stats/block_collector.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"log"
77
"sort"
8-
"strings"
98
"time"
109

1110
"github.com/ethereum/go-ethereum/core/types"
@@ -57,9 +56,7 @@ func NewBlockCollector(seiChainID string) *BlockCollector {
5756

5857
// Start begins block subscription and data collection
5958
func (bc *BlockCollector) Run(ctx context.Context, firstEndpoint string) error {
60-
// Convert HTTP endpoint to WebSocket endpoint (8545 -> 8546)
61-
wsEndpoint := strings.Replace(firstEndpoint, ":8545", ":8546", 1)
62-
wsEndpoint = strings.Replace(wsEndpoint, "http://", "ws://", 1)
59+
wsEndpoint := utils.GetWSEndpoint(firstEndpoint)
6360
return service.Run(ctx, func(ctx context.Context, s service.Scope) error {
6461
// Connect to WebSocket endpoint
6562
client, err := ethclient.Dial(wsEndpoint)

0 commit comments

Comments
 (0)