-
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
base: master
Are you sure you want to change the base?
Changes from all commits
e096dc1
fa99ce5
a433a81
c1203b1
1935adf
b508826
953a76e
e6481ab
89abbde
5f55711
afac7bc
a817e73
d0b95de
828abe3
01f0663
18b884d
d4639ff
718bc52
b26e8c4
3588978
9e7f54f
bc78644
29da042
7250778
43f9633
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| } | ||
|
Comment on lines
+58
to
+64
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm seems that if the kind is mismatched with the actual registered prometheus metric, then it will fail late here. Is there any way to make this fail earlier / louder / with a better error message if that's the case?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what you mean by "it will fail". If we mismatch metric kinds (e.g. say it's a counter but it's actually a gauge), then |
||
| 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") | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.