Skip to content

Commit

Permalink
feat(monitor): add reward service error metric (#2905)
Browse files Browse the repository at this point in the history
  • Loading branch information
rickstaa authored Dec 20, 2023
1 parent 8a8b0e3 commit d877233
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

- #2911 Set default price with livepeer_cli option 20 (@eliteprox)
- #2928 Added `startupAvailabilityCheck` param to skip the availability check on startup (@stronk-dev)
- #2905 Add `reward_call_errors` Prometheus metric (@rickstaa)

#### Transcoder

Expand Down
6 changes: 5 additions & 1 deletion eth/rewardservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/ethereum/go-ethereum/core/types"
"github.com/golang/glog"
"github.com/livepeer/go-livepeer/monitor"
)

var (
Expand Down Expand Up @@ -56,7 +57,10 @@ func (s *RewardService) Start(ctx context.Context) error {
go func() {
err := s.tryReward()
if err != nil {
glog.Errorf("Error trying to call reward err=%q", err)
glog.Errorf("Error trying to call reward for round %v err=%q", s.tw.LastInitializedRound(), err)
if monitor.Enabled {
monitor.RewardCallError(err.Error())
}
}
}()
case <-cancelCtx.Done():
Expand Down
25 changes: 25 additions & 0 deletions monitor/census.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ type (
mMaxGasPrice *stats.Float64Measure
mTranscodingPrice *stats.Float64Measure

// Metrics for calling rewards
mRewardCallError *stats.Int64Measure

// Metrics for pixel accounting
mMilPixelsProcessed *stats.Float64Measure

Expand Down Expand Up @@ -318,6 +321,9 @@ func InitCensus(nodeType NodeType, version string) {
census.mMaxGasPrice = stats.Float64("max_gas_price", "MaxGasPrice", "gwei")
census.mTranscodingPrice = stats.Float64("transcoding_price", "TranscodingPrice", "wei")

// Metrics for calling rewards
census.mRewardCallError = stats.Int64("reward_call_errors", "RewardCallError", "tot")

// Metrics for pixel accounting
census.mMilPixelsProcessed = stats.Float64("mil_pixels_processed", "MilPixelsProcessed", "mil pixels")

Expand Down Expand Up @@ -780,6 +786,15 @@ func InitCensus(nodeType NodeType, version string) {
Aggregation: view.LastValue(),
},

// Metrics for calling rewards
{
Name: "reward_call_errors",
Measure: census.mRewardCallError,
Description: "Errors when calling rewards",
TagKeys: baseTags,
Aggregation: view.Sum(),
},

// Metrics for fast verification
{
Name: "fast_verification_done",
Expand Down Expand Up @@ -1683,6 +1698,16 @@ func TranscodingPrice(sender string, price *big.Rat) {
}
}

// RewardCallError records an error from reward calling
func RewardCallError(sender string) {
if err := stats.RecordWithTags(census.ctx,
[]tag.Mutator{tag.Insert(census.kSender, sender)},
census.mRewardCallError.M(1)); err != nil {

glog.Errorf("Error recording metrics err=%q", err)
}
}

// Convert wei to gwei
func wei2gwei(wei *big.Int) float64 {
gwei, _ := new(big.Float).Quo(new(big.Float).SetInt(wei), big.NewFloat(float64(gweiConversionFactor))).Float64()
Expand Down

0 comments on commit d877233

Please sign in to comment.