standardised on counter names ending in _total

This commit is contained in:
Matt Johnstone 2024-10-30 09:29:32 +02:00
parent 9542fc1588
commit ef6941e87b
No known key found for this signature in database
GPG Key ID: BE985FBB9BE7D3BB
2 changed files with 21 additions and 21 deletions

View File

@ -39,7 +39,7 @@ type SlotWatcher struct {
EpochLastSlotMetric prometheus.Gauge EpochLastSlotMetric prometheus.Gauge
LeaderSlotsMetric *prometheus.CounterVec LeaderSlotsMetric *prometheus.CounterVec
LeaderSlotsByEpochMetric *prometheus.CounterVec LeaderSlotsByEpochMetric *prometheus.CounterVec
InflationRewardsMetric *prometheus.GaugeVec InflationRewardsMetric *prometheus.CounterVec
FeeRewardsMetric *prometheus.CounterVec FeeRewardsMetric *prometheus.CounterVec
BlockSizeMetric *prometheus.GaugeVec BlockSizeMetric *prometheus.GaugeVec
BlockHeightMetric prometheus.Gauge BlockHeightMetric prometheus.Gauge
@ -74,7 +74,7 @@ func NewSlotWatcher(client *rpc.Client, config *ExporterConfig) *SlotWatcher {
}), }),
LeaderSlotsMetric: prometheus.NewCounterVec( LeaderSlotsMetric: prometheus.NewCounterVec(
prometheus.CounterOpts{ prometheus.CounterOpts{
Name: "solana_validator_leader_slots", Name: "solana_validator_leader_slots_total",
Help: fmt.Sprintf( Help: fmt.Sprintf(
"Number of slots processed, grouped by %s, and %s ('%s' or '%s')", "Number of slots processed, grouped by %s, and %s ('%s' or '%s')",
NodekeyLabel, SkipStatusLabel, StatusValid, StatusSkipped, NodekeyLabel, SkipStatusLabel, StatusValid, StatusSkipped,
@ -84,7 +84,7 @@ func NewSlotWatcher(client *rpc.Client, config *ExporterConfig) *SlotWatcher {
), ),
LeaderSlotsByEpochMetric: prometheus.NewCounterVec( LeaderSlotsByEpochMetric: prometheus.NewCounterVec(
prometheus.CounterOpts{ prometheus.CounterOpts{
Name: "solana_validator_leader_slots_by_epoch", Name: "solana_validator_leader_slots_by_epoch_total",
Help: fmt.Sprintf( Help: fmt.Sprintf(
"Number of slots processed, grouped by %s, %s ('%s' or '%s'), and %s", "Number of slots processed, grouped by %s, %s ('%s' or '%s'), and %s",
NodekeyLabel, SkipStatusLabel, StatusValid, StatusSkipped, EpochLabel, NodekeyLabel, SkipStatusLabel, StatusValid, StatusSkipped, EpochLabel,
@ -92,16 +92,16 @@ func NewSlotWatcher(client *rpc.Client, config *ExporterConfig) *SlotWatcher {
}, },
[]string{NodekeyLabel, EpochLabel, SkipStatusLabel}, []string{NodekeyLabel, EpochLabel, SkipStatusLabel},
), ),
InflationRewardsMetric: prometheus.NewGaugeVec( InflationRewardsMetric: prometheus.NewCounterVec(
prometheus.GaugeOpts{ prometheus.CounterOpts{
Name: "solana_validator_inflation_rewards", Name: "solana_validator_inflation_rewards_total",
Help: fmt.Sprintf("Inflation reward earned, grouped by %s and %s", VotekeyLabel, EpochLabel), Help: fmt.Sprintf("Inflation reward earned, grouped by %s and %s", VotekeyLabel, EpochLabel),
}, },
[]string{VotekeyLabel, EpochLabel}, []string{VotekeyLabel, EpochLabel},
), ),
FeeRewardsMetric: prometheus.NewCounterVec( FeeRewardsMetric: prometheus.NewCounterVec(
prometheus.CounterOpts{ prometheus.CounterOpts{
Name: "solana_validator_fee_rewards", Name: "solana_validator_fee_rewards_total",
Help: fmt.Sprintf("Transaction fee rewards earned, grouped by %s and %s", NodekeyLabel, EpochLabel), Help: fmt.Sprintf("Transaction fee rewards earned, grouped by %s and %s", NodekeyLabel, EpochLabel),
}, },
[]string{NodekeyLabel, EpochLabel}, []string{NodekeyLabel, EpochLabel},
@ -423,7 +423,7 @@ func (c *SlotWatcher) fetchAndEmitInflationRewards(ctx context.Context, epoch in
for i, rewardInfo := range rewardInfos { for i, rewardInfo := range rewardInfos {
address := c.config.VoteKeys[i] address := c.config.VoteKeys[i]
reward := float64(rewardInfo.Amount) / float64(rpc.LamportsInSol) reward := float64(rewardInfo.Amount) / float64(rpc.LamportsInSol)
c.InflationRewardsMetric.WithLabelValues(address, toString(epoch)).Set(reward) c.InflationRewardsMetric.WithLabelValues(address, toString(epoch)).Add(reward)
} }
c.logger.Infof("Fetched inflation reward for epoch %v.", epoch) c.logger.Infof("Fetched inflation reward for epoch %v.", epoch)
return nil return nil

View File

@ -109,38 +109,38 @@ func TestSlotWatcher_WatchSlots_Static(t *testing.T) {
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
type testCase struct { type testCase struct {
name string
expectedValue float64 expectedValue float64
metric prometheus.Gauge metric prometheus.Collector
} }
// epoch info tests: // epoch info tests:
firstSlot, lastSlot := GetEpochBounds(epochInfo) firstSlot, lastSlot := GetEpochBounds(epochInfo)
tests := []testCase{ tests := []testCase{
{expectedValue: float64(epochInfo.AbsoluteSlot), metric: watcher.SlotHeightMetric}, {"slot_height", float64(epochInfo.AbsoluteSlot), watcher.SlotHeightMetric},
{expectedValue: float64(epochInfo.TransactionCount), metric: watcher.TotalTransactionsMetric}, {"total_transactions", float64(epochInfo.TransactionCount), watcher.TotalTransactionsMetric},
{expectedValue: float64(epochInfo.Epoch), metric: watcher.EpochNumberMetric}, {"epoch_number", float64(epochInfo.Epoch), watcher.EpochNumberMetric},
{expectedValue: float64(firstSlot), metric: watcher.EpochFirstSlotMetric}, {"epoch_first_slot", float64(firstSlot), watcher.EpochFirstSlotMetric},
{expectedValue: float64(lastSlot), metric: watcher.EpochLastSlotMetric}, {"epoch_last_slot", float64(lastSlot), watcher.EpochLastSlotMetric},
} }
// add inflation reward tests: // add inflation reward tests:
inflationRewards, err := client.GetInflationReward(ctx, rpc.CommitmentFinalized, simulator.Votekeys, 2) inflationRewards, err := client.GetInflationReward(ctx, rpc.CommitmentFinalized, simulator.Votekeys, 2)
assert.NoError(t, err) assert.NoError(t, err)
for i, rewardInfo := range inflationRewards { for i, rewardInfo := range inflationRewards {
epoch := fmt.Sprintf("%v", epochInfo.Epoch)
tests = append( tests = append(
tests, tests,
testCase{ testCase{
expectedValue: float64(rewardInfo.Amount) / float64(rpc.LamportsInSol), fmt.Sprintf("inflation_rewards_%s", simulator.Votekeys[i]),
metric: watcher.InflationRewardsMetric.WithLabelValues(simulator.Votekeys[i], epoch), float64(rewardInfo.Amount) / float64(rpc.LamportsInSol),
watcher.InflationRewardsMetric.WithLabelValues(simulator.Votekeys[i], toString(epochInfo.Epoch)),
}, },
) )
} }
for _, testCase := range tests { for _, test := range tests {
name := extractName(testCase.metric.Desc()) t.Run(test.name, func(t *testing.T) {
t.Run(name, func(t *testing.T) { assert.Equal(t, test.expectedValue, testutil.ToFloat64(test.metric))
assert.Equal(t, testCase.expectedValue, testutil.ToFloat64(testCase.metric))
}) })
} }
} }