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 4 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 @@ -12,6 +12,7 @@ type PrometheusMetrics struct {
LatestHeightGauge *prometheus.GaugeVec
WalletBalance *prometheus.GaugeVec
FeesSpent *prometheus.GaugeVec
BlockQueryFailure *prometheus.CounterVec
}

func (m *PrometheusMetrics) AddPacketsObserved(path, chain, channel, port, eventType string, count int) {
Expand All @@ -34,10 +35,15 @@ func (m *PrometheusMetrics) SetFeesSpent(chain, key, address, denom string, amou
m.FeesSpent.WithLabelValues(chain, key, address, denom).Set(amount)
}

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"}
walletLabels := []string{"chain", "key", "address", "denom"}
blockQueryFailureLabels := []string{"chain", "type"}
registry := prometheus.NewRegistry()
registerer := promauto.With(registry)
return &PrometheusMetrics{
Expand All @@ -62,5 +68,9 @@ 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),
}
}
Loading