Skip to content

Commit

Permalink
export client expiration metric
Browse files Browse the repository at this point in the history
  • Loading branch information
boojamya committed Jul 8, 2023
1 parent 91f9105 commit 42e980b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions relayer/processor/message_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ func (mp *messageProcessor) shouldUpdateClientNow(ctx context.Context, src, dst

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

timeToExpiration := dst.clientState.TrustingPeriod - time.Since(consensusHeightTime)
mp.metrics.SetSecsToClientExpiration(dst.info.ChainID, timeToExpiration)

if shouldUpdateClientNow {
mp.log.Info("Client update threshold condition met",
zap.String("chain_id", dst.info.ChainID),
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) SetSecsToClientExpiration(chain string, timeToExpiration time.Duration) {
m.ClientExpiration.WithLabelValues(chain).Set(timeToExpiration.Seconds())
}

func NewPrometheusMetrics() *PrometheusMetrics {
packetLabels := []string{"path", "chain", "channel", "port", "type"}
heightLabels := []string{"chain"}
walletLabels := []string{"chain", "key", "address", "denom"}
clientExpiration := []string{"chain"}
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: "chain_client_expiration",
Help: "Seconds until the client expires",
}, clientExpiration),
}
}

0 comments on commit 42e980b

Please sign in to comment.