Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: add metric kind
  • Loading branch information
RodrigoVillar committed Sep 30, 2025
commit 63899f12a5633d71c614d88326a52dcdd9743848
47 changes: 27 additions & 20 deletions tests/reexecute/c/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,57 @@ import (
"github.com/stretchr/testify/require"
)

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_C_parse_block_sum",
kind: gauge,
},
{
name: "block_verify",
query: "avalanche_meterchainvm_C_verify_sum",
kind: gauge,
},
{
name: "block_accept",
query: "avalanche_meterchainvm_C_accept_sum",
kind: gauge,
},
}
)

func getCounterMetricValue(registry prometheus.Gatherer, query string) (float64, error) {
metricFamilies, err := registry.Gather()
if err != nil {
return 0, fmt.Errorf("failed to gather metrics: %w", err)
}

for _, mf := range metricFamilies {
if mf.GetName() == query {
return mf.GetMetric()[0].Counter.GetValue(), nil
}
}

return 0, fmt.Errorf("metric %s not found", query)
}

func getGaugeMetricValue(registry prometheus.Gatherer, query string) (float64, error) {
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 {
if mf.GetName() == query {
return mf.GetMetric()[0].Gauge.GetValue(), nil
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
}
default:
return 0, fmt.Errorf("metric type unknown: %d", metric.kind)
}
}

Expand All @@ -66,12 +72,13 @@ func getGaugeMetricValue(registry prometheus.Gatherer, query string) (float64, e
type topLevelMetric struct {
name string
query string
kind metricKind
}

func getTopLevelMetrics(b *testing.B, registry prometheus.Gatherer, elapsed time.Duration) {
r := require.New(b)

totalGas, err := getCounterMetricValue(registry, gasMetric.query)
totalGas, err := getMetricValue(registry, gasMetric)
r.NoError(err)
r.NotZero(totalGas, "denominator metric %q has value 0", gasMetric.name)

Expand All @@ -90,7 +97,7 @@ func getTopLevelMetrics(b *testing.B, registry prometheus.Gatherer, elapsed time

totalMSTrackedPerGGas := float64(0)
for _, metric := range meterVMMetrics {
metricVal, err := getGaugeMetricValue(registry, metric.query)
metricVal, err := getMetricValue(registry, metric)
r.NoError(err)

metricValMS := (metricVal / nsPerMs) / totalGGas
Expand Down