Skip to content

Commit 5dba51a

Browse files
authored
Initialize Prometheus Counters to 0 when service(s) start (#3906)
Signed-off-by: Aaron Mell <aaronamell@gmail.com>
1 parent 6359cbf commit 5dba51a

4 files changed

Lines changed: 21 additions & 1 deletion

File tree

USERS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Organizations below are **officially** using Argo Events. Please send a PR with
3535
1. [FikaWorks](https://fika.works/)
3636
1. [Kraken Technologies Ltd.](https://kraken.tech/)
3737
1. [Loam](https://www.getloam.com/)
38+
1. [Lumin Digital](https://lumindigital.com)
3839
1. [MariaDB](https://mariadb.com/)
3940
1. [Mobimeo GmbH](https://mobimeo.com/en/home/)
4041
1. [OneCause](https://www.onecause.com/)
@@ -63,4 +64,4 @@ Organizations below are **officially** using Argo Events. Please send a PR with
6364
1. [Zillow Group](https://www.zillow.com)
6465
1. [AlpacaTech](https://www.alpaca-tech.ai)
6566
1. [SBAB Bank AB](https://www.sbab.se)
66-
1. [Terradue Srl](https://www.terradue.com)
67+
1. [Terradue Srl](https://www.terradue.com)

pkg/eventsources/eventing.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ func (e *EventSourceAdaptor) run(ctx context.Context, servers map[aev1.EventSour
478478
logger.Errorw("failed to connect to eventbus", zap.Error(err))
479479
return err
480480
}
481+
481482
defer e.eventBusConn.Close()
482483

483484
ctx, cancel := context.WithCancel(ctx)
@@ -527,6 +528,9 @@ func (e *EventSourceAdaptor) run(ctx context.Context, servers map[aev1.EventSour
527528
// Continue starting other event services instead of failing all of them
528529
continue
529530
}
531+
532+
e.metrics.InitEventMetrics(server.GetEventSourceName(), server.GetEventName())
533+
530534
wg.Add(1)
531535
go func(s EventingServer) {
532536
defer wg.Done()

pkg/metrics/metrics.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,19 @@ func (m *Metrics) Describe(ch chan<- *prometheus.Desc) {
152152
m.actionDuration.Describe(ch)
153153
}
154154

155+
func (m *Metrics) InitSensorMetrics(sensorName string, triggerName string) {
156+
m.actionTriggered.WithLabelValues(sensorName, triggerName).Add(0)
157+
m.actionFailed.WithLabelValues(sensorName, triggerName).Add(0)
158+
m.actionRetriesFailed.WithLabelValues(sensorName, triggerName).Add(0)
159+
}
160+
161+
func (m *Metrics) InitEventMetrics(eventSourceName string, eventName string) {
162+
m.runningEventServices.WithLabelValues(eventSourceName).Set(0)
163+
m.eventsSent.WithLabelValues(eventSourceName, eventName).Add(0)
164+
m.eventsSentFailed.WithLabelValues(eventSourceName, eventName).Add(0)
165+
m.eventsProcessingFailed.WithLabelValues(eventSourceName, eventName).Add(0)
166+
}
167+
155168
func (m *Metrics) IncRunningServices(eventSourceName string) {
156169
m.runningEventServices.WithLabelValues(eventSourceName).Inc()
157170
}

pkg/sensors/listener.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ func (sensorCtx *SensorContext) listenEvents(ctx context.Context) error {
124124

125125
wg := &sync.WaitGroup{}
126126
for _, t := range sensor.Spec.Triggers {
127+
sensorCtx.metrics.InitSensorMetrics(sensorCtx.sensor.Name, t.Template.Name)
128+
127129
initRateLimiter(t)
128130
wg.Add(1)
129131
go func(trigger v1alpha1.Trigger) {

0 commit comments

Comments
 (0)