Skip to content

Commit 22bce42

Browse files
authoredJul 25, 2023
Export client expiration metric to prometheus (#1235)
* export client expiration metric * finalize * add path name * snake case * change label to `chain` * trusting period as string
1 parent 7ae1596 commit 22bce42

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed
 

‎relayer/processor/message_processor.go

+7
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,14 @@ func (mp *messageProcessor) shouldUpdateClientNow(ctx context.Context, src, dst
141141

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

144+
if mp.metrics != nil {
145+
timeToExpiration := dst.clientState.TrustingPeriod - time.Since(consensusHeightTime)
146+
mp.metrics.SetClientExpiration(src.info.PathName, dst.info.ChainID, dst.clientState.ClientID, fmt.Sprint(dst.clientState.TrustingPeriod.String()), timeToExpiration)
147+
}
148+
144149
if shouldUpdateClientNow {
145150
mp.log.Info("Client update threshold condition met",
151+
zap.String("path_name", src.info.PathName),
146152
zap.String("chain_id", dst.info.ChainID),
147153
zap.String("client_id", dst.info.ClientID),
148154
zap.Int64("trusting_period", dst.clientState.TrustingPeriod.Milliseconds()),
@@ -249,6 +255,7 @@ func (mp *messageProcessor) assembleMsgUpdateClient(ctx context.Context, src, ds
249255
clientConsensusHeight.RevisionHeight+1, src.info.ChainID, err)
250256
}
251257
mp.log.Debug("Had to query for client trusted IBC header",
258+
zap.String("path_name", src.info.PathName),
252259
zap.String("chain_id", src.info.ChainID),
253260
zap.String("counterparty_chain_id", dst.info.ChainID),
254261
zap.String("counterparty_client_id", clientID),

‎relayer/processor/metrics.go

+12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package processor
22

33
import (
4+
"time"
5+
46
"github.com/prometheus/client_golang/prometheus"
57
"github.com/prometheus/client_golang/prometheus/promauto"
68
)
@@ -12,6 +14,7 @@ type PrometheusMetrics struct {
1214
LatestHeightGauge *prometheus.GaugeVec
1315
WalletBalance *prometheus.GaugeVec
1416
FeesSpent *prometheus.GaugeVec
17+
ClientExpiration *prometheus.GaugeVec
1518
}
1619

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

40+
func (m *PrometheusMetrics) SetClientExpiration(pathName, chain, clientID, trustingPeriod string, timeToExpiration time.Duration) {
41+
m.ClientExpiration.WithLabelValues(pathName, chain, clientID, trustingPeriod).Set(timeToExpiration.Seconds())
42+
}
43+
3744
func NewPrometheusMetrics() *PrometheusMetrics {
3845
packetLabels := []string{"path", "chain", "channel", "port", "type"}
3946
heightLabels := []string{"chain"}
4047
walletLabels := []string{"chain", "key", "address", "denom"}
48+
clientExpirationLables := []string{"path_name", "chain", "client_id", "trusting_period"}
4149
registry := prometheus.NewRegistry()
4250
registerer := promauto.With(registry)
4351
return &PrometheusMetrics{
@@ -62,5 +70,9 @@ func NewPrometheusMetrics() *PrometheusMetrics {
6270
Name: "cosmos_relayer_fees_spent",
6371
Help: "The amount of fees spent from the relayer's wallet",
6472
}, walletLabels),
73+
ClientExpiration: registerer.NewGaugeVec(prometheus.GaugeOpts{
74+
Name: "cosmos_relayer_client_expiration_seconds",
75+
Help: "Seconds until the client expires",
76+
}, clientExpirationLables),
6577
}
6678
}

0 commit comments

Comments
 (0)