Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prometheus: add service_id to created alerts and sent notification counters #3603

Merged
merged 4 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions alert/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
)

var (
metricCreatedTotal = promauto.NewCounter(prometheus.CounterOpts{
metricCreatedTotal = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: "goalert",
Subsystem: "alert",
Name: "created_total",
Help: "The total number of created alerts.",
})
}, []string{"service_id"})
)
4 changes: 2 additions & 2 deletions alert/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ func (s *Store) Create(ctx context.Context, a *Alert) (*Alert, error) {

ctx = log.WithFields(ctx, log.Fields{"AlertID": n.ID, "ServiceID": n.ServiceID})
log.Logf(ctx, "Alert created.")
metricCreatedTotal.Inc()
metricCreatedTotal.WithLabelValues(n.ServiceID).Inc()

return n, nil
}
Expand Down Expand Up @@ -652,7 +652,7 @@ func (s *Store) CreateOrUpdate(ctx context.Context, a *Alert) (*Alert, bool, err
if isNew {
ctx = log.WithFields(ctx, log.Fields{"AlertID": n.ID, "ServiceID": n.ServiceID})
log.Logf(ctx, "Alert created.")
metricCreatedTotal.Inc()
metricCreatedTotal.WithLabelValues(n.ServiceID).Inc()
}

return n, isNew, nil
Expand Down
1 change: 1 addition & 0 deletions engine/sendmessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ func (p *Engine) sendMessage(ctx context.Context, msg *message.Message) (*notifi
notifMsg = notification.AlertStatus{
Dest: msg.Dest,
AlertID: e.AlertID(),
ServiceID: a.ServiceID,
CallbackID: msg.ID,
LogEntry: e.String(ctx),
Summary: a.Summary,
Expand Down
1 change: 1 addition & 0 deletions notification/alertstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type AlertStatus struct {
CallbackID string
AlertID int
LogEntry string
ServiceID string

// Summary of the alert that this status is in regards to.
Summary string
Expand Down
15 changes: 14 additions & 1 deletion notification/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (mgr *Manager) SendMessage(ctx context.Context, msg Message) (*SendResult,
}
log.Logf(sendCtx, "notification sent")
metricSentTotal.
WithLabelValues(msg.Destination().Type.String(), msg.Type().String()).
WithLabelValues(msg.Destination().Type.String(), msg.Type().String(), msgSvcID(msg)).
Inc()
// status already wrapped via namedSender
return res, nil
Expand All @@ -161,3 +161,16 @@ func (mgr *Manager) SendMessage(ctx context.Context, msg Message) (*SendResult,

return nil, errors.New("all notification senders failed")
}

func msgSvcID(msg Message) string {
switch msg := msg.(type) {
case Alert:
return msg.ServiceID
case AlertBundle:
return msg.ServiceID
case AlertStatus:
return msg.ServiceID
}

return ""
}
2 changes: 1 addition & 1 deletion notification/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var (
Subsystem: "notification",
Name: "sent_total",
Help: "Total number of sent notifications.",
}, []string{"dest_type", "message_type"})
}, []string{"dest_type", "message_type", "service_id"})
metricRecvTotal = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: "goalert",
Subsystem: "notification",
Expand Down