From 260474c7dd4080407e7723a12e1fcf6f7e044fc2 Mon Sep 17 00:00:00 2001 From: Sam Calder-Mason Date: Tue, 12 Sep 2023 10:49:45 +1000 Subject: [PATCH] fix(cannon): Wire up decorated event metrics (#185) --- pkg/cannon/cannon.go | 4 +++- pkg/cannon/metrics.go | 12 ++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pkg/cannon/cannon.go b/pkg/cannon/cannon.go index 6cfd7d88..583ee847 100644 --- a/pkg/cannon/cannon.go +++ b/pkg/cannon/cannon.go @@ -257,6 +257,8 @@ func (c *Cannon) handleNewDecoratedEvent(ctx context.Context, event *xatu.Decora } } + c.metrics.AddDecoratedEvent(1, event, string(c.beacon.Metadata().Network.Name)) + return nil } @@ -363,7 +365,7 @@ func (c *Cannon) startBeaconBlockProcessor(ctx context.Context) error { }) d.OnLocationUpdated(ctx, func(ctx context.Context, location uint64) error { - c.metrics.SetDeriverLocation(location, d.CannonType()) + c.metrics.SetDeriverLocation(location, d.CannonType(), string(c.beacon.Metadata().Network.Name)) return nil }) diff --git a/pkg/cannon/metrics.go b/pkg/cannon/metrics.go index f0e3ea9a..57a5938e 100644 --- a/pkg/cannon/metrics.go +++ b/pkg/cannon/metrics.go @@ -16,12 +16,12 @@ func NewMetrics(namespace string) *Metrics { Namespace: namespace, Name: "decorated_event_total", Help: "Total number of decorated events created by the cannon", - }, []string{"type"}), + }, []string{"type", "network"}), deriverLocation: prometheus.NewGaugeVec(prometheus.GaugeOpts{ Namespace: namespace, Name: "deriver_location", Help: "Location of the cannon event deriver", - }, []string{"type"}), + }, []string{"type", "network"}), } prometheus.MustRegister(m.decoratedEventTotal) @@ -30,10 +30,10 @@ func NewMetrics(namespace string) *Metrics { return m } -func (m *Metrics) AddDecoratedEvent(count int, eventType xatu.CannonType) { - m.decoratedEventTotal.WithLabelValues(eventType.String()).Add(float64(count)) +func (m *Metrics) AddDecoratedEvent(count int, eventType *xatu.DecoratedEvent, network string) { + m.decoratedEventTotal.WithLabelValues(eventType.Event.Name.String(), network).Add(float64(count)) } -func (m *Metrics) SetDeriverLocation(location uint64, eventType xatu.CannonType) { - m.deriverLocation.WithLabelValues(eventType.String()).Set(float64(location)) +func (m *Metrics) SetDeriverLocation(location uint64, eventType xatu.CannonType, network string) { + m.deriverLocation.WithLabelValues(eventType.String(), network).Set(float64(location)) }