-
Notifications
You must be signed in to change notification settings - Fork 840
chore(reexecute/c): add back scraping of multiple metrics #4673
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
Open
RodrigoVillar
wants to merge
25
commits into
master
Choose a base branch
from
rodrigo/add-back-multiple-metrics
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
e096dc1
refactor: block export
RodrigoVillar fa99ce5
chore: nits
RodrigoVillar a433a81
chore(reexecute/c): remove go bench from benchmark
RodrigoVillar c1203b1
chore: remove go bench in workflow
RodrigoVillar 1935adf
chore: reduce diff
RodrigoVillar b508826
chore: use test context logger
RodrigoVillar 953a76e
chore: clean up benchmarkTool
RodrigoVillar e6481ab
docs: benchmarking types
RodrigoVillar 89abbde
refactor: use tc wherever convenient
RodrigoVillar 5f55711
refactor: clean up result logging
RodrigoVillar afac7bc
fix: append unit to base name
RodrigoVillar a817e73
chore: remove unnecessary log
RodrigoVillar d0b95de
Merge branch 'master' into rodrigo/custom-benchmarks
RodrigoVillar 828abe3
chore: nit
RodrigoVillar 01f0663
chore: add back require
RodrigoVillar 18b884d
chore: txt => json
RodrigoVillar d4639ff
docs: remove stale ref
RodrigoVillar 718bc52
docs: nit
RodrigoVillar b26e8c4
chore: improve logResults()
RodrigoVillar 3588978
chore: address PR review
RodrigoVillar 9e7f54f
Merge branch 'master' into rodrigo/custom-benchmarks
RodrigoVillar bc78644
chore(reexecute/c): add back scraping of multiple metrics
RodrigoVillar 29da042
Merge branch 'master' into rodrigo/add-back-multiple-metrics
RodrigoVillar 7250778
chore: nit
RodrigoVillar 43f9633
chore: nsPerMs => nanosecondsPerMillisecond
RodrigoVillar 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "time" | ||
|
|
||
| "github.com/prometheus/client_golang/prometheus" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/ava-labs/avalanchego/tests" | ||
| ) | ||
|
|
||
| type metricKind uint | ||
|
|
||
| const ( | ||
| counter metricKind = iota + 1 | ||
| gauge | ||
| ) | ||
|
|
||
| var ( | ||
| gasMetric = topLevelMetric{ | ||
| name: "gas", | ||
| query: "avalanche_evm_eth_chain_block_gas_used_processed", | ||
| kind: counter, | ||
| } | ||
| meterVMMetrics = []topLevelMetric{ | ||
| { | ||
| name: "block_parse", | ||
| query: "avalanche_meterchainvm_parse_block_sum", | ||
| kind: gauge, | ||
| }, | ||
| { | ||
| name: "block_verify", | ||
| query: "avalanche_meterchainvm_verify_sum", | ||
| kind: gauge, | ||
| }, | ||
| { | ||
| name: "block_accept", | ||
| query: "avalanche_meterchainvm_accept_sum", | ||
| kind: gauge, | ||
| }, | ||
| } | ||
| ) | ||
|
|
||
| func getMetricValue(registry prometheus.Gatherer, metric topLevelMetric) (float64, error) { | ||
| metricFamilies, err := registry.Gather() | ||
| if err != nil { | ||
| return 0, fmt.Errorf("failed to gather metrics: %w", err) | ||
| } | ||
|
|
||
| query := metric.query | ||
| for _, mf := range metricFamilies { | ||
| switch metric.kind { | ||
| case counter: | ||
| if mf.GetName() == query { | ||
| return mf.GetMetric()[0].Counter.GetValue(), nil | ||
| } | ||
| case gauge: | ||
| if mf.GetName() == query { | ||
| return mf.GetMetric()[0].Gauge.GetValue(), nil | ||
| } | ||
aaronbuchwald marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| default: | ||
| return 0, fmt.Errorf("metric type unknown: %d", metric.kind) | ||
| } | ||
| } | ||
|
|
||
| return 0, fmt.Errorf("metric %s not found", query) | ||
| } | ||
|
|
||
| type topLevelMetric struct { | ||
| name string | ||
| query string | ||
| kind metricKind | ||
| } | ||
|
|
||
| func getTopLevelMetrics(tc tests.TestContext, tool *benchmarkTool, registry prometheus.Gatherer, elapsed time.Duration) { | ||
| r := require.New(tc) | ||
|
|
||
| totalGas, err := getMetricValue(registry, gasMetric) | ||
| r.NoError(err) | ||
| r.NotZero(totalGas, "denominator metric %q has value 0", gasMetric.name) | ||
|
|
||
| var ( | ||
| mgas float64 = 1_000_000 | ||
| ggas float64 = 1_000_000_000 | ||
| nanosecondsPerMillisecond float64 = 1_000_000 | ||
| ) | ||
|
|
||
| mgasPerSecond := (totalGas / mgas) / elapsed.Seconds() | ||
| tool.addResult(mgasPerSecond, "mgas/s") | ||
|
|
||
| totalGGas := totalGas / ggas | ||
| msPerGGas := (float64(elapsed) / nanosecondsPerMillisecond) / totalGGas | ||
| tool.addResult(msPerGGas, "ms/ggas") | ||
|
|
||
| for _, metric := range meterVMMetrics { | ||
| metricVal, err := getMetricValue(registry, metric) | ||
| r.NoError(err) | ||
|
|
||
| metricValMS := (metricVal / nanosecondsPerMillisecond) / totalGGas | ||
| tool.addResult(metricValMS, metric.name+"_ms/ggas") | ||
| } | ||
| } | ||
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
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.