Skip to content

Commit

Permalink
fix(cannon): Wire up decorated event metrics (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
samcm committed Sep 12, 2023
1 parent 2e3b2a9 commit 260474c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion pkg/cannon/cannon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
})
Expand Down
12 changes: 6 additions & 6 deletions pkg/cannon/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
}

0 comments on commit 260474c

Please sign in to comment.