Skip to content

Commit 0589b9d

Browse files
committed
Add gnosis specific metrics
1 parent 15d7806 commit 0589b9d

File tree

8 files changed

+105
-1
lines changed

8 files changed

+105
-1
lines changed

rolling-shutter/keyperimpl/gnosis/database/gnosiskeyper.sqlc.gen.go

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rolling-shutter/keyperimpl/gnosis/database/sql/queries/gnosiskeyper.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,7 @@ SELECT * FROM validator_registrations_synced_until LIMIT 1;
112112
SELECT nonce FROM validator_registrations
113113
WHERE validator_index = $1 AND block_number <= $2 AND tx_index <= $3 AND log_index <= $4
114114
ORDER BY block_number DESC, tx_index DESC, log_index DESC
115-
LIMIT 1;
115+
LIMIT 1;
116+
117+
-- name: GetNumValidatorRegistrations :one
118+
SELECT COUNT(*) FROM validator_registrations;

rolling-shutter/keyperimpl/gnosis/handlers.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package gnosis
33
import (
44
"context"
55
"database/sql"
6+
"fmt"
67
"math"
78

89
"github.com/jackc/pgx/v4"
@@ -290,5 +291,8 @@ func (h *DecryptionKeysHandler) HandleMessage(ctx context.Context, msg p2pmsg.Me
290291
if err != nil {
291292
return []p2pmsg.Message{}, errors.Wrap(err, "failed to set tx pointer")
292293
}
294+
eonString := fmt.Sprint(keys.Eon)
295+
metricsTxPointer.WithLabelValues(eonString).Set(float64(newTxPointer))
296+
metricsTxPointerAge.WithLabelValues(eonString).Set(0)
293297
return []p2pmsg.Message{}, nil
294298
}

rolling-shutter/keyperimpl/gnosis/messagingmiddleware.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"database/sql"
7+
"fmt"
78

89
"github.com/jackc/pgx/v4"
910
"github.com/jackc/pgx/v4/pgxpool"
@@ -294,5 +295,8 @@ func (i *MessagingMiddleware) advanceTxPointer(ctx context.Context, msg *p2pmsg.
294295
if err != nil {
295296
return errors.Wrap(err, "failed to set tx pointer")
296297
}
298+
eonString := fmt.Sprint(msg.Eon)
299+
metricsTxPointer.WithLabelValues(eonString).Set(float64(newTxPointer))
300+
metricsTxPointerAge.WithLabelValues(eonString).Set(0)
297301
return nil
298302
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package gnosis
2+
3+
import "github.com/prometheus/client_golang/prometheus"
4+
5+
var metricsTxPointer = prometheus.NewGaugeVec(
6+
prometheus.GaugeOpts{
7+
Namespace: "shutter",
8+
Subsystem: "gnosis",
9+
Name: "tx_pointer",
10+
Help: "Current value of the tx pointer",
11+
},
12+
[]string{"eon"},
13+
)
14+
15+
var metricsTxPointerAge = prometheus.NewGaugeVec(
16+
prometheus.GaugeOpts{
17+
Namespace: "shutter",
18+
Subsystem: "gnosis",
19+
Name: "tx_pointer_age_blocks",
20+
Help: "Current age of the tx pointer",
21+
},
22+
[]string{"eon"},
23+
)
24+
25+
var metricsLatestTxSubmittedEventIndex = prometheus.NewGaugeVec(
26+
prometheus.GaugeOpts{
27+
Namespace: "shutter",
28+
Subsystem: "gnosis",
29+
Name: "latest_tx_submitted_event_index",
30+
Help: "Index of the latest TxSubmitted event",
31+
},
32+
[]string{"eon"},
33+
)
34+
35+
var metricsTxSubmittedEventsSyncedUntil = prometheus.NewGauge(
36+
prometheus.GaugeOpts{
37+
Namespace: "shutter",
38+
Subsystem: "gnosis",
39+
Name: "tx_submitted_events_synced_until",
40+
Help: "Block number until which TxSubmitted events have been synced",
41+
},
42+
)
43+
44+
var metricsValidatorRegistrationsSyncedUntil = prometheus.NewGauge(
45+
prometheus.GaugeOpts{
46+
Namespace: "shutter",
47+
Subsystem: "gnosis",
48+
Name: "validator_registrations_synced_until",
49+
Help: "Block number until which validator registration events have been synced",
50+
},
51+
)
52+
53+
var metricsNumValidatorRegistrations = prometheus.NewGauge(
54+
prometheus.GaugeOpts{
55+
Namespace: "shutter",
56+
Subsystem: "gnosis",
57+
Name: "num_validator_registrations_total",
58+
Help: "Number of synced validator registrations",
59+
},
60+
)
61+
62+
func init() {
63+
prometheus.MustRegister(metricsTxPointer)
64+
prometheus.MustRegister(metricsTxPointerAge)
65+
prometheus.MustRegister(metricsLatestTxSubmittedEventIndex)
66+
prometheus.MustRegister(metricsTxSubmittedEventsSyncedUntil)
67+
prometheus.MustRegister(metricsValidatorRegistrationsSyncedUntil)
68+
prometheus.MustRegister(metricsNumValidatorRegistrations)
69+
}

rolling-shutter/keyperimpl/gnosis/newslot.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ func getTxPointer(ctx context.Context, db *pgxpool.Pool, eon int64, maxTxPointer
163163
var txPointer int64
164164
var txPointerAge int64
165165
var txPointerOutdated bool
166+
eonString := fmt.Sprint(eon)
166167
txPointerDB, err := gnosisKeyperDB.GetTxPointer(ctx, eon)
167168
if err == pgx.ErrNoRows {
168169
log.Info().Int64("eon", eon).Msg("initializing tx pointer")
@@ -192,6 +193,7 @@ func getTxPointer(ctx context.Context, db *pgxpool.Pool, eon int64, maxTxPointer
192193
if txPointerDB.Age.Valid {
193194
txPointerOutdated = txPointerAge > maxTxPointerAge
194195
} else {
196+
txPointerAge = math.MaxInt64
195197
txPointerOutdated = true
196198
}
197199
}
@@ -214,6 +216,8 @@ func getTxPointer(ctx context.Context, db *pgxpool.Pool, eon int64, maxTxPointer
214216
return 0, errors.Wrap(err, "failed to query transaction submitted event count from db")
215217
}
216218
}
219+
metricsTxPointer.WithLabelValues(eonString).Set(float64(txPointer))
220+
metricsTxPointerAge.WithLabelValues(eonString).Set(float64(txPointerAge))
217221
return txPointer, nil
218222
}
219223

rolling-shutter/keyperimpl/gnosis/sequencersyncer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ func (s *SequencerSyncer) syncRange(
9494
Int("num-inserted-events", len(filteredEvents)).
9595
Int("num-discarded-events", len(events)-len(filteredEvents)).
9696
Msg("synced sequencer contract")
97+
metricsTxSubmittedEventsSyncedUntil.Set(float64(end))
9798
return nil
9899
}
99100

@@ -178,6 +179,7 @@ func (s *SequencerSyncer) insertTransactionSubmittedEvents(
178179
if err != nil {
179180
return errors.Wrap(err, "failed to insert transaction submitted event into db")
180181
}
182+
metricsLatestTxSubmittedEventIndex.WithLabelValues(string(event.Eon)).Set(float64(nextEventIndex))
181183
nextEventIndices[event.Eon]++
182184
log.Debug().
183185
Int64("index", nextEventIndex).

rolling-shutter/keyperimpl/gnosis/validatorsyncer.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,19 @@ func (v *ValidatorSyncer) syncRange(ctx context.Context, start, end uint64) erro
9696
if err != nil {
9797
return err
9898
}
99+
numRegistrations, err := db.GetNumValidatorRegistrations(ctx)
100+
if err != nil {
101+
return errors.Wrap(err, "failed to get number of validator registrations")
102+
}
99103
log.Info().
100104
Uint64("start-block", start).
101105
Uint64("end-block", end).
102106
Int("num-inserted-events", len(filteredEvents)).
103107
Int("num-discarded-events", len(events)-len(filteredEvents)).
108+
Int64("num-registrations", numRegistrations).
104109
Msg("synced validator registry")
110+
metricsNumValidatorRegistrations.Set(float64(numRegistrations))
111+
metricsValidatorRegistrationsSyncedUntil.Set(float64(end))
105112
return nil
106113
}
107114

0 commit comments

Comments
 (0)