Skip to content

Commit

Permalink
feat: add post prices prometheus counter
Browse files Browse the repository at this point in the history
  • Loading branch information
k-yang committed Jun 6, 2024
1 parent dc52295 commit b72535e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
11 changes: 11 additions & 0 deletions feeder/priceposter/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import (

"github.com/NibiruChain/nibiru/app"
oracletypes "github.com/NibiruChain/nibiru/x/oracle/types"
"github.com/NibiruChain/pricefeeder/metrics"
"github.com/NibiruChain/pricefeeder/types"
"github.com/cosmos/cosmos-sdk/client"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"
txservice "github.com/cosmos/cosmos-sdk/types/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/rs/zerolog"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
Expand Down Expand Up @@ -102,6 +105,12 @@ func (c *Client) Whoami() sdk.ValAddress {
return c.validator
}

var pricePosterCounter = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: metrics.PrometheusNamespace,
Name: "prices_posted_total",
Help: "The total number of price update txs sent to the chain, by success status",
}, []string{"success"})

func (c *Client) SendPrices(vp types.VotingPeriod, prices []types.Price) {
logger := c.logger.With().Uint64("voting-period-height", vp.Height).Logger()

Expand All @@ -112,11 +121,13 @@ func (c *Client) SendPrices(vp types.VotingPeriod, prices []types.Price) {
resp, err := vote(ctx, newPrevote, c.previousPrevote, c.validator, c.feeder, c.deps, logger)
if err != nil {
logger.Err(err).Msg("prevote failed")
pricePosterCounter.WithLabelValues("false").Inc()
return
}

c.previousPrevote = newPrevote
logger.Info().Str("tx-hash", resp.TxHash).Msg("successfully forwarded prices")
pricePosterCounter.WithLabelValues("true").Inc()
}

func (c *Client) Close() {
Expand Down
6 changes: 4 additions & 2 deletions feeder/priceprovider/aggregateprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"

"github.com/NibiruChain/nibiru/x/common/asset"
"github.com/NibiruChain/pricefeeder/metrics"
"github.com/NibiruChain/pricefeeder/types"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
Expand Down Expand Up @@ -40,8 +41,9 @@ 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",
Namespace: metrics.PrometheusNamespace,
Name: "aggregate_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.
Expand Down
7 changes: 5 additions & 2 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import (
"github.com/prometheus/client_golang/prometheus/promauto"
)

const PrometheusNamespace = "pricefeeder"

var PriceSourceCounter = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "price_source_counter",
Help: "The total number prices scraped, by source and success status",
Namespace: PrometheusNamespace,
Name: "fetched_prices_total",
Help: "The total number prices fetched, by source and success status",
}, []string{"source", "success"})

0 comments on commit b72535e

Please sign in to comment.