From db8373b81d6a00dde0cdacabd9f38480af97c3e5 Mon Sep 17 00:00:00 2001 From: Matt Johnstone Date: Fri, 4 Oct 2024 13:04:23 +0200 Subject: [PATCH] added leader-slot-addresses to SlotWatcher --- cmd/solana_exporter/exporter.go | 6 +++--- cmd/solana_exporter/slots.go | 6 ++++++ cmd/solana_exporter/slots_test.go | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/cmd/solana_exporter/exporter.go b/cmd/solana_exporter/exporter.go index 852924d..e7556d4 100644 --- a/cmd/solana_exporter/exporter.go +++ b/cmd/solana_exporter/exporter.go @@ -35,8 +35,8 @@ type solanaCollector struct { rpcClient rpc.Provider // config: - slotPace time.Duration - balanceAddresses []string + slotPace time.Duration + balanceAddresses []string leaderSlotAddresses []string /// descriptors: @@ -243,7 +243,7 @@ func main() { collector := NewSolanaCollector(*rpcAddr, balAddresses, lsAddresses) - slotWatcher := SlotWatcher{client: collector.rpcClient} + slotWatcher := NewCollectorSlotWatcher(collector) go slotWatcher.WatchSlots(context.Background(), collector.slotPace) prometheus.MustRegister(collector) diff --git a/cmd/solana_exporter/slots.go b/cmd/solana_exporter/slots.go index 907f648..f8cf953 100644 --- a/cmd/solana_exporter/slots.go +++ b/cmd/solana_exporter/slots.go @@ -18,6 +18,8 @@ const ( type SlotWatcher struct { client rpc.Provider + leaderSlotAddresses []string + // currentEpoch is the current epoch we are watching currentEpoch int64 // firstSlot is the first slot [inclusive] of the current epoch which we are watching @@ -71,6 +73,10 @@ var ( ) ) +func NewCollectorSlotWatcher(collector *solanaCollector) *SlotWatcher { + return &SlotWatcher{client: collector.rpcClient, leaderSlotAddresses: collector.leaderSlotAddresses} +} + func init() { prometheus.MustRegister(totalTransactionsTotal) prometheus.MustRegister(confirmedSlotHeight) diff --git a/cmd/solana_exporter/slots_test.go b/cmd/solana_exporter/slots_test.go index ce0c013..2d2ee88 100644 --- a/cmd/solana_exporter/slots_test.go +++ b/cmd/solana_exporter/slots_test.go @@ -92,7 +92,7 @@ func TestSolanaCollector_WatchSlots_Static(t *testing.T) { leaderSlotsByEpoch.Reset() collector := createSolanaCollector(&staticRPCClient{}, 100*time.Millisecond, identities, []string{}) - watcher := SlotWatcher{client: collector.rpcClient} + watcher := NewCollectorSlotWatcher(collector) prometheus.NewPedanticRegistry().MustRegister(collector) ctx, cancel := context.WithCancel(context.Background()) defer cancel()