-
Notifications
You must be signed in to change notification settings - Fork 251
refactor: move spamoor benchmark into testify suite #3107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
81dc810
refactor: move spamoor benchmark into testify suite in test/e2e/bench…
chatton cc56590
merge main into cian/bench-refactor
chatton 18fc15a
fix: correct BENCH_JSON_OUTPUT path for spamoor benchmark
chatton fccd9db
fix: place package pattern before test binary flags in benchmark CI
chatton ae525ca
fix: adjust evm-binary path for benchmark subpackage working directory
chatton 85c9d2d
fix: exclude benchmark subpackage from make test-e2e
chatton e4e06c5
fix: address PR review feedback for benchmark suite
chatton 1c3b560
Merge branch 'main' into cian/bench-refactor
chatton 03b9239
chore: specify http
chatton fe3ca23
chore: filter out benchmark tests from test-e2e
chatton 8752fee
Merge branch 'main' into cian/bench-refactor
chatton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,41 @@ | ||
| //go:build evm | ||
|
|
||
| package benchmark | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
|
|
||
| dto "github.com/prometheus/client_model/go" | ||
| ) | ||
|
|
||
| // requireHostUp polls a URL until it returns a 2xx status code or the timeout expires. | ||
| func requireHostUp(t testing.TB, url string, timeout time.Duration) { | ||
| t.Helper() | ||
| client := &http.Client{Timeout: 200 * time.Millisecond} | ||
| require.Eventually(t, func() bool { | ||
| resp, err := client.Get(url) | ||
| if err != nil { | ||
| return false | ||
| } | ||
| _ = resp.Body.Close() | ||
| return resp.StatusCode >= 200 && resp.StatusCode < 300 | ||
| }, timeout, 100*time.Millisecond, "daemon not ready at %s", url) | ||
| } | ||
|
|
||
| // sumCounter sums all counter values in a prometheus MetricFamily. | ||
| func sumCounter(f *dto.MetricFamily) float64 { | ||
| if f == nil || f.GetType() != dto.MetricType_COUNTER { | ||
| return 0 | ||
| } | ||
| var sum float64 | ||
| for _, m := range f.GetMetric() { | ||
| if m.GetCounter() != nil && m.GetCounter().Value != nil { | ||
| sum += m.GetCounter().GetValue() | ||
| } | ||
| } | ||
| return sum | ||
| } |
This file contains hidden or 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 @@ | ||
| //go:build evm | ||
|
|
||
| package benchmark | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "os" | ||
| "sort" | ||
| "testing" | ||
|
|
||
| e2e "github.com/evstack/ev-node/test/e2e" | ||
| ) | ||
|
|
||
| // entry matches the customSmallerIsBetter format for github-action-benchmark. | ||
| type entry struct { | ||
| Name string `json:"name"` | ||
| Unit string `json:"unit"` | ||
| Value float64 `json:"value"` | ||
| } | ||
|
|
||
| // resultWriter accumulates benchmark entries and writes them to a JSON file | ||
| // when flush is called. Create one early in a test and defer flush so results | ||
| // are written regardless of where the test exits. | ||
| type resultWriter struct { | ||
| t testing.TB | ||
| label string | ||
| entries []entry | ||
| } | ||
|
|
||
| func newResultWriter(t testing.TB, label string) *resultWriter { | ||
| return &resultWriter{t: t, label: label} | ||
| } | ||
|
|
||
| // addSpans aggregates trace spans into per-operation avg duration entries. | ||
| func (w *resultWriter) addSpans(spans []e2e.TraceSpan) { | ||
| m := e2e.AggregateSpanStats(spans) | ||
| if len(m) == 0 { | ||
| return | ||
| } | ||
|
|
||
| names := make([]string, 0, len(m)) | ||
| for name := range m { | ||
| names = append(names, name) | ||
| } | ||
| sort.Strings(names) | ||
|
|
||
| for _, name := range names { | ||
| s := m[name] | ||
| avg := float64(s.Total.Microseconds()) / float64(s.Count) | ||
| w.entries = append(w.entries, entry{ | ||
| Name: fmt.Sprintf("%s - %s (avg)", w.label, name), | ||
| Unit: "us", | ||
| Value: avg, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // addEntry appends a custom entry to the results. | ||
| func (w *resultWriter) addEntry(e entry) { | ||
| w.entries = append(w.entries, e) | ||
| } | ||
|
|
||
| // flush writes accumulated entries to the path in BENCH_JSON_OUTPUT. | ||
| // It is a no-op when the env var is unset or no entries were added. | ||
| func (w *resultWriter) flush() { | ||
| outputPath := os.Getenv("BENCH_JSON_OUTPUT") | ||
| if outputPath == "" || len(w.entries) == 0 { | ||
| return | ||
| } | ||
|
|
||
| data, err := json.MarshalIndent(w.entries, "", " ") | ||
| if err != nil { | ||
| w.t.Logf("WARNING: failed to marshal benchmark JSON: %v", err) | ||
| return | ||
| } | ||
| if err := os.WriteFile(outputPath, data, 0644); err != nil { | ||
| w.t.Logf("WARNING: failed to write benchmark JSON to %s: %v", outputPath, err) | ||
| return | ||
| } | ||
| w.t.Logf("wrote %d benchmark entries to %s", len(w.entries), outputPath) | ||
| } |
This file contains hidden or 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,120 @@ | ||
| //go:build evm | ||
|
|
||
| package benchmark | ||
|
|
||
| import ( | ||
| "os" | ||
| "time" | ||
|
|
||
| "github.com/celestiaorg/tastora/framework/docker/evstack/spamoor" | ||
| e2e "github.com/evstack/ev-node/test/e2e" | ||
| ) | ||
|
|
||
| // TestSpamoorSmoke spins up reth + sequencer and a Spamoor node, starts a few | ||
| // basic spammers, waits briefly, then validates trace spans and prints a concise | ||
| // metrics summary. | ||
| func (s *SpamoorSuite) TestSpamoorSmoke() { | ||
| t := s.T() | ||
| w := newResultWriter(t, "SpamoorSmoke") | ||
| defer w.flush() | ||
|
|
||
| // TODO: temporary hardcoded tag, will be replaced with a proper release tag | ||
| rethTag := os.Getenv("EV_RETH_TAG") | ||
| if rethTag == "" { | ||
| rethTag = "pr-140" | ||
| } | ||
| e := s.setupEnv(config{ | ||
| rethTag: rethTag, | ||
| serviceName: "ev-node-smoke", | ||
| }) | ||
| api := e.spamoorAPI | ||
|
|
||
| eoatx := map[string]any{ | ||
| "throughput": 100, | ||
| "total_count": 3000, | ||
| "max_pending": 4000, | ||
| "max_wallets": 300, | ||
| "amount": 100, | ||
| "random_amount": true, | ||
| "random_target": true, | ||
| "base_fee": 20, | ||
| "tip_fee": 2, | ||
| "refill_amount": "1000000000000000000", | ||
| "refill_balance": "500000000000000000", | ||
| "refill_interval": 600, | ||
| } | ||
|
|
||
| gasburner := map[string]any{ | ||
| "throughput": 25, | ||
| "total_count": 2000, | ||
| "max_pending": 8000, | ||
| "max_wallets": 500, | ||
| "gas_units_to_burn": 3000000, | ||
| "base_fee": 20, | ||
| "tip_fee": 5, | ||
| "rebroadcast": 5, | ||
| "refill_amount": "5000000000000000000", | ||
| "refill_balance": "2000000000000000000", | ||
| "refill_interval": 300, | ||
| } | ||
|
|
||
| var ids []int | ||
| id, err := api.CreateSpammer("smoke-eoatx", spamoor.ScenarioEOATX, eoatx, true) | ||
| s.Require().NoError(err, "failed to create eoatx spammer") | ||
| ids = append(ids, id) | ||
| id, err = api.CreateSpammer("smoke-gasburner", spamoor.ScenarioGasBurnerTX, gasburner, true) | ||
| s.Require().NoError(err, "failed to create gasburner spammer") | ||
| ids = append(ids, id) | ||
|
|
||
| for _, id := range ids { | ||
| idToDelete := id | ||
| t.Cleanup(func() { _ = api.DeleteSpammer(idToDelete) }) | ||
| } | ||
|
|
||
| // allow spamoor enough time to generate transaction throughput | ||
| // so that the expected tracing spans appear in Jaeger. | ||
| time.Sleep(60 * time.Second) | ||
|
|
||
| // fetch parsed metrics and print a concise summary. | ||
| metrics, err := api.GetMetrics() | ||
| s.Require().NoError(err, "failed to get metrics") | ||
| sent := sumCounter(metrics["spamoor_transactions_sent_total"]) | ||
| fail := sumCounter(metrics["spamoor_transactions_failed_total"]) | ||
|
|
||
| // collect traces | ||
| evNodeSpans := s.collectServiceTraces(e, "ev-node-smoke") | ||
| evRethSpans := s.collectServiceTraces(e, "ev-reth") | ||
| e2e.PrintTraceReport(t, "ev-node-smoke", evNodeSpans) | ||
| e2e.PrintTraceReport(t, "ev-reth", evRethSpans) | ||
|
|
||
| w.addSpans(append(evNodeSpans, evRethSpans...)) | ||
|
|
||
| // assert expected ev-node span names | ||
| assertSpanNames(t, evNodeSpans, []string{ | ||
| "BlockExecutor.ProduceBlock", | ||
| "BlockExecutor.ApplyBlock", | ||
| "BlockExecutor.CreateBlock", | ||
| "BlockExecutor.RetrieveBatch", | ||
| "Executor.ExecuteTxs", | ||
| "Executor.SetFinal", | ||
| "Engine.ForkchoiceUpdated", | ||
| "Engine.NewPayload", | ||
| "Engine.GetPayload", | ||
| "Eth.GetBlockByNumber", | ||
| "Sequencer.GetNextBatch", | ||
| "DASubmitter.SubmitHeaders", | ||
| "DASubmitter.SubmitData", | ||
| "DA.Submit", | ||
| }, "ev-node-smoke") | ||
|
|
||
| // assert expected ev-reth span names | ||
| assertSpanNames(t, evRethSpans, []string{ | ||
| "build_payload", | ||
| "execute_tx", | ||
| "try_build", | ||
| "validate_transaction", | ||
| }, "ev-reth") | ||
|
|
||
| s.Require().Greater(sent, float64(0), "at least one transaction should have been sent") | ||
| s.Require().Zero(fail, "no transactions should have failed") | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only run benchmark tests for PRs when relevant files are changed.