Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exports block query errors to prometheus metrics (counter) #1239

Merged
merged 5 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion docs/advanced_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
**Prometheus exporter**

If you started `rly` with the default `--debug-addr` argument,
you can use `http://$IP:7597/relayer/metrics` as a target for your prometheus scraper.
you can use `http://$IP:5183/relayer/metrics` as a target for your prometheus scraper.

**Example metrics**

Expand Down
6 changes: 6 additions & 0 deletions relayer/chains/cosmos/cosmos_chain_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,18 @@ func (ccp *CosmosChainProcessor) queryCycle(ctx context.Context, persistence *qu
queryCtx, cancelQueryCtx := context.WithTimeout(ctx, blockResultsQueryTimeout)
defer cancelQueryCtx()
blockRes, err = ccp.chainProvider.RPCClient.BlockResults(queryCtx, &i)
if err != nil && ccp.metrics != nil {
boojamya marked this conversation as resolved.
Show resolved Hide resolved
ccp.metrics.IncBlockQueryFailure(chainID, "RPC Client")
}
return err
})
eg.Go(func() (err error) {
queryCtx, cancelQueryCtx := context.WithTimeout(ctx, queryTimeout)
defer cancelQueryCtx()
ibcHeader, err = ccp.chainProvider.QueryIBCHeader(queryCtx, i)
if err != nil && ccp.metrics != nil {
ccp.metrics.IncBlockQueryFailure(chainID, "IBC Header")
}
return err
})

Expand Down
10 changes: 10 additions & 0 deletions relayer/processor/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type PrometheusMetrics struct {
LatestHeightGauge *prometheus.GaugeVec
WalletBalance *prometheus.GaugeVec
FeesSpent *prometheus.GaugeVec
BlockQueryFailure *prometheus.CounterVec
ClientExpiration *prometheus.GaugeVec
}

Expand Down Expand Up @@ -41,9 +42,14 @@ func (m *PrometheusMetrics) SetClientExpiration(pathName, chain, clientID, trust
m.ClientExpiration.WithLabelValues(pathName, chain, clientID, trustingPeriod).Set(timeToExpiration.Seconds())
}

func (m *PrometheusMetrics) IncBlockQueryFailure(chain, err string) {
m.BlockQueryFailure.WithLabelValues(chain, err).Inc()
}

func NewPrometheusMetrics() *PrometheusMetrics {
packetLabels := []string{"path", "chain", "channel", "port", "type"}
heightLabels := []string{"chain"}
blockQueryFailureLabels := []string{"chain", "type"}
walletLabels := []string{"chain", "gas_price", "key", "address", "denom"}
clientExpirationLables := []string{"path_name", "chain", "client_id", "trusting_period"}
registry := prometheus.NewRegistry()
Expand All @@ -70,6 +76,10 @@ func NewPrometheusMetrics() *PrometheusMetrics {
Name: "cosmos_relayer_fees_spent",
Help: "The amount of fees spent from the relayer's wallet",
}, walletLabels),
BlockQueryFailure: registerer.NewCounterVec(prometheus.CounterOpts{
Name: "cosmos_relayer_block_query_errors_total",
Help: "The total number of block query failures. The failures are separated into two catagories: 'RPC Client' and 'IBC Header'",
}, blockQueryFailureLabels),
ClientExpiration: registerer.NewGaugeVec(prometheus.GaugeOpts{
Name: "cosmos_relayer_client_expiration_seconds",
Help: "Seconds until the client expires",
Expand Down
Loading