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

Export client expiration metric to prometheus #1235

Merged
merged 7 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
7 changes: 7 additions & 0 deletions relayer/processor/message_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,14 @@ func (mp *messageProcessor) shouldUpdateClientNow(ctx context.Context, src, dst

shouldUpdateClientNow := enoughBlocksPassed && (pastTwoThirdsTrustingPeriod || pastConfiguredClientUpdateThreshold)

if mp.metrics != nil {
timeToExpiration := dst.clientState.TrustingPeriod - time.Since(consensusHeightTime)
mp.metrics.SetClientExpiration(src.info.PathName, dst.info.ChainID, dst.clientState.ClientID, fmt.Sprint(dst.clientState.TrustingPeriod.String()), timeToExpiration)
}

if shouldUpdateClientNow {
mp.log.Info("Client update threshold condition met",
zap.String("path_name", src.info.PathName),
zap.String("chain_id", dst.info.ChainID),
zap.String("client_id", dst.info.ClientID),
zap.Int64("trusting_period", dst.clientState.TrustingPeriod.Milliseconds()),
Expand Down Expand Up @@ -249,6 +255,7 @@ func (mp *messageProcessor) assembleMsgUpdateClient(ctx context.Context, src, ds
clientConsensusHeight.RevisionHeight+1, src.info.ChainID, err)
}
mp.log.Debug("Had to query for client trusted IBC header",
zap.String("path_name", src.info.PathName),
zap.String("chain_id", src.info.ChainID),
zap.String("counterparty_chain_id", dst.info.ChainID),
zap.String("counterparty_client_id", clientID),
Expand Down
12 changes: 12 additions & 0 deletions relayer/processor/metrics.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package processor

import (
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
Expand All @@ -12,6 +14,7 @@ type PrometheusMetrics struct {
LatestHeightGauge *prometheus.GaugeVec
WalletBalance *prometheus.GaugeVec
FeesSpent *prometheus.GaugeVec
ClientExpiration *prometheus.GaugeVec
}

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

func (m *PrometheusMetrics) SetClientExpiration(pathName, chain, clientID, trustingPeriod string, timeToExpiration time.Duration) {
boojamya marked this conversation as resolved.
Show resolved Hide resolved
m.ClientExpiration.WithLabelValues(pathName, chain, clientID, trustingPeriod).Set(timeToExpiration.Seconds())
}

func NewPrometheusMetrics() *PrometheusMetrics {
packetLabels := []string{"path", "chain", "channel", "port", "type"}
heightLabels := []string{"chain"}
walletLabels := []string{"chain", "key", "address", "denom"}
clientExpirationLables := []string{"path_name", "chain", "client_id", "trusting_period"}
registry := prometheus.NewRegistry()
registerer := promauto.With(registry)
return &PrometheusMetrics{
Expand All @@ -62,5 +70,9 @@ func NewPrometheusMetrics() *PrometheusMetrics {
Name: "cosmos_relayer_fees_spent",
Help: "The amount of fees spent from the relayer's wallet",
}, walletLabels),
ClientExpiration: registerer.NewGaugeVec(prometheus.GaugeOpts{
Name: "cosmos_relayer_client_expiration_seconds",
Help: "Seconds until the client expires",
}, clientExpirationLables),
}
}
Loading