Skip to content

Commit

Permalink
feat: add aggregate price provider metric
Browse files Browse the repository at this point in the history
  • Loading branch information
k-yang committed Jun 6, 2024
1 parent 6530fd2 commit dc52295
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions feeder/priceprovider/aggregateprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (

"github.com/NibiruChain/nibiru/x/common/asset"
"github.com/NibiruChain/pricefeeder/types"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/rs/zerolog"
)

Expand Down Expand Up @@ -37,6 +39,11 @@ func NewAggregatePriceProvider(
}
}

var aggregatePriceProvider = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "aggregate_price_provider_prices_total",
Help: "The total number prices provided by the aggregate price provider, by pair, source, and success status",
}, []string{"pair", "source", "success"})

// GetPrice fetches the first available and correct price from the wrapped PriceProviders.
// Iteration is exhaustive and random.
// If no correct PriceResponse is found, then an invalid PriceResponse is returned.
Expand All @@ -46,12 +53,14 @@ func (a AggregatePriceProvider) GetPrice(pair asset.Pair) types.Price {
for _, p := range a.providers {
price := p.GetPrice(pair)
if price.Valid {
aggregatePriceProvider.WithLabelValues(pair.String(), price.SourceName, "true").Inc()
return price
}
}

// if we reach here no valid symbols were found
a.logger.Warn().Str("pair", pair.String()).Msg("no valid price found")
aggregatePriceProvider.WithLabelValues(pair.String(), "missing", "false").Inc()
return types.Price{
SourceName: "missing",
Pair: pair,
Expand Down

0 comments on commit dc52295

Please sign in to comment.