Skip to content
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
17 changes: 10 additions & 7 deletions internal/alert/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,28 +175,31 @@ func (m *alertMonitor) HandleAttempt(ctx context.Context, attempt DeliveryAttemp
}

m.logger.Ctx(ctx).Audit("destination disabled",
zap.String("destination_id", attempt.Destination.ID),
zap.String("event_id", attempt.DeliveryEvent.Event.ID),
zap.String("tenant_id", attempt.Destination.TenantID),
zap.String("topic", alert.Topic),
zap.String("destination_id", attempt.Destination.ID),
zap.String("destination_type", attempt.Destination.Type),
)
}

// Send alert if notifier is configured
if m.notifier != nil {
if err := m.notifier.Notify(ctx, alert); err != nil {
m.logger.Ctx(ctx).Error("failed to send alert",
zap.String("destination_id", attempt.Destination.ID),
zap.String("tenant_id", attempt.Destination.TenantID),
zap.String("topic", alert.Topic),
zap.Error(err),
zap.String("event_id", attempt.DeliveryEvent.Event.ID),
zap.String("tenant_id", attempt.Destination.TenantID),
zap.String("destination_id", attempt.Destination.ID),
zap.String("destination_type", attempt.Destination.Type),
)
return fmt.Errorf("failed to send alert: %w", err)
}

m.logger.Ctx(ctx).Audit("alert sent",
zap.String("destination_id", attempt.Destination.ID),
zap.String("event_id", attempt.DeliveryEvent.Event.ID),
zap.String("tenant_id", attempt.Destination.TenantID),
zap.String("topic", alert.Topic),
zap.String("destination_id", attempt.Destination.ID),
zap.String("destination_type", attempt.Destination.Type),
)
}

Expand Down
4 changes: 3 additions & 1 deletion internal/apirouter/retry_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ func (h *RetryHandlers) Retry(c *gin.Context) {

h.logger.Ctx(c).Audit("manual retry initiated",
zap.String("event_id", event.ID),
zap.String("destination_id", destination.ID))
zap.String("tenant_id", tenantID),
zap.String("destination_id", destination.ID),
zap.String("destination_type", destination.Type))

c.JSON(http.StatusAccepted, gin.H{
"success": true,
Expand Down
62 changes: 43 additions & 19 deletions internal/deliverymq/messagehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ func (h *messageHandler) Handle(ctx context.Context, msg *mqs.Message) error {
}

h.logger.Ctx(ctx).Info("processing delivery event",
zap.String("delivery_event_id", deliveryEvent.ID),
zap.String("event_id", deliveryEvent.Event.ID),
zap.String("tenant_id", deliveryEvent.Event.TenantID),
zap.String("destination_id", deliveryEvent.DestinationID),
zap.Int("attempt", deliveryEvent.Attempt))

// Ensure event data
Expand Down Expand Up @@ -198,8 +199,10 @@ func (h *messageHandler) doHandle(ctx context.Context, deliveryEvent models.Deli

h.logger.Ctx(ctx).Error("failed to publish event",
zap.Error(err),
zap.String("delivery_event_id", deliveryEvent.ID),
zap.String("destination_id", destination.ID))
zap.String("event_id", deliveryEvent.Event.ID),
zap.String("tenant_id", deliveryEvent.Event.TenantID),
zap.String("destination_id", destination.ID),
zap.String("destination_type", destination.Type))
deliveryErr := &DeliveryError{err: err}

if h.shouldScheduleRetry(deliveryEvent, err) {
Expand All @@ -216,12 +219,18 @@ func (h *messageHandler) doHandle(ctx context.Context, deliveryEvent models.Deli
if err := h.retryScheduler.Cancel(ctx, deliveryEvent.GetRetryID()); err != nil {
h.logger.Ctx(ctx).Error("failed to cancel scheduled retry",
zap.Error(err),
zap.String("delivery_event_id", deliveryEvent.ID),
zap.String("event_id", deliveryEvent.Event.ID),
zap.String("tenant_id", deliveryEvent.Event.TenantID),
zap.String("destination_id", destination.ID),
zap.String("destination_type", destination.Type),
zap.String("retry_id", deliveryEvent.GetRetryID()))
return h.logDeliveryResult(ctx, &deliveryEvent, destination, delivery, err)
}
logger.Audit("scheduled retry canceled",
zap.String("delivery_event_id", deliveryEvent.ID),
zap.String("event_id", deliveryEvent.Event.ID),
zap.String("tenant_id", deliveryEvent.Event.TenantID),
zap.String("destination_id", destination.ID),
zap.String("destination_type", destination.Type),
zap.String("retry_id", deliveryEvent.GetRetryID()))
}
return h.logDeliveryResult(ctx, &deliveryEvent, destination, delivery, nil)
Expand All @@ -234,19 +243,22 @@ func (h *messageHandler) logDeliveryResult(ctx context.Context, deliveryEvent *m
deliveryEvent.Delivery = delivery

logger.Audit("event delivered",
zap.String("delivery_event_id", deliveryEvent.ID),
zap.String("destination_id", deliveryEvent.DestinationID),
zap.String("event_id", deliveryEvent.Event.ID),
zap.String("tenant_id", deliveryEvent.Event.TenantID),
zap.String("destination_id", destination.ID),
zap.String("destination_type", destination.Type),
zap.String("delivery_status", deliveryEvent.Delivery.Status),
zap.Int("attempt", deliveryEvent.Attempt),
zap.Bool("manual", deliveryEvent.Manual),
zap.String("destination_type", destination.Type))
zap.Bool("manual", deliveryEvent.Manual))

// Publish delivery log
if logErr := h.logMQ.Publish(ctx, *deliveryEvent); logErr != nil {
logger.Error("failed to publish delivery log",
zap.Error(logErr),
zap.String("delivery_event_id", deliveryEvent.ID))
zap.String("event_id", deliveryEvent.Event.ID),
zap.String("tenant_id", deliveryEvent.Event.TenantID),
zap.String("destination_id", destination.ID),
zap.String("destination_type", destination.Type))
if err != nil {
return &PostDeliveryError{err: errors.Join(err, logErr)}
}
Expand Down Expand Up @@ -315,14 +327,18 @@ func (h *messageHandler) handleAlertAttempt(ctx context.Context, deliveryEvent *
if monitorErr := h.alertMonitor.HandleAttempt(ctx, attempt); monitorErr != nil {
h.logger.Ctx(ctx).Error("failed to handle alert attempt",
zap.Error(monitorErr),
zap.String("delivery_event_id", deliveryEvent.ID),
zap.String("destination_id", destination.ID))
zap.String("event_id", deliveryEvent.Event.ID),
zap.String("tenant_id", destination.TenantID),
zap.String("destination_id", destination.ID),
zap.String("destination_type", destination.Type))
return
}

h.logger.Ctx(ctx).Info("alert attempt handled",
zap.String("delivery_event_id", deliveryEvent.ID),
zap.String("destination_id", destination.ID))
zap.String("event_id", deliveryEvent.Event.ID),
zap.String("tenant_id", destination.TenantID),
zap.String("destination_id", destination.ID),
zap.String("destination_type", destination.Type))
}

func (h *messageHandler) shouldScheduleRetry(deliveryEvent models.DeliveryEvent, err error) bool {
Expand Down Expand Up @@ -395,14 +411,18 @@ func (h *messageHandler) scheduleRetry(ctx context.Context, deliveryEvent models
if err := h.retryScheduler.Schedule(ctx, retryMessageStr, backoffDuration, scheduler.WithTaskID(deliveryEvent.GetRetryID())); err != nil {
h.logger.Ctx(ctx).Error("failed to schedule retry",
zap.Error(err),
zap.String("delivery_event_id", deliveryEvent.ID),
zap.String("event_id", deliveryEvent.Event.ID),
zap.String("tenant_id", deliveryEvent.Event.TenantID),
zap.String("destination_id", deliveryEvent.DestinationID),
zap.Int("attempt", deliveryEvent.Attempt),
zap.Duration("backoff", backoffDuration))
return err
}

h.logger.Ctx(ctx).Audit("retry scheduled",
zap.String("delivery_event_id", deliveryEvent.ID),
zap.String("event_id", deliveryEvent.Event.ID),
zap.String("tenant_id", deliveryEvent.Event.TenantID),
zap.String("destination_id", deliveryEvent.DestinationID),
zap.Int("attempt", deliveryEvent.Attempt),
zap.Duration("backoff", backoffDuration))

Expand Down Expand Up @@ -438,8 +458,9 @@ func (h *messageHandler) ensurePublishableDestination(ctx context.Context, deliv
logger := h.logger.Ctx(ctx)
fields := []zap.Field{
zap.Error(err),
zap.String("destination_id", deliveryEvent.DestinationID),
zap.String("event_id", deliveryEvent.Event.ID),
zap.String("tenant_id", deliveryEvent.Event.TenantID),
zap.String("destination_id", deliveryEvent.DestinationID),
}

if errors.Is(err, models.ErrDestinationDeleted) {
Expand All @@ -452,12 +473,15 @@ func (h *messageHandler) ensurePublishableDestination(ctx context.Context, deliv
}
if destination == nil {
h.logger.Ctx(ctx).Info("destination not found",
zap.String("destination_id", deliveryEvent.DestinationID),
zap.String("tenant_id", deliveryEvent.Event.TenantID))
zap.String("event_id", deliveryEvent.Event.ID),
zap.String("tenant_id", deliveryEvent.Event.TenantID),
zap.String("destination_id", deliveryEvent.DestinationID))
return nil, models.ErrDestinationNotFound
}
if destination.DisabledAt != nil {
h.logger.Ctx(ctx).Info("skipping disabled destination",
zap.String("event_id", deliveryEvent.Event.ID),
zap.String("tenant_id", deliveryEvent.Event.TenantID),
zap.String("destination_id", destination.ID),
zap.String("destination_type", destination.Type),
zap.Time("disabled_at", *destination.DisabledAt))
Expand Down
10 changes: 6 additions & 4 deletions internal/publishmq/eventhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func (h *eventHandler) Handle(ctx context.Context, event *models.Event) (*Handle
logger.Audit("processing event",
zap.String("event_id", event.ID),
zap.String("tenant_id", event.TenantID),
zap.String("topic", event.Topic),
zap.String("destination_id", event.DestinationID))
zap.String("destination_id", event.DestinationID),
zap.String("topic", event.Topic))

var matchedDestinations []models.DestinationSummary
var err error
Expand Down Expand Up @@ -159,6 +159,8 @@ func (h *eventHandler) matchSpecificDestination(ctx context.Context, event *mode
if err != nil {
h.logger.Ctx(ctx).Warn("failed to retrieve destination",
zap.Error(err),
zap.String("event_id", event.ID),
zap.String("tenant_id", event.TenantID),
zap.String("destination_id", event.DestinationID))
return []models.DestinationSummary{}, nil
}
Expand All @@ -179,17 +181,17 @@ func (h *eventHandler) enqueueDeliveryEvent(ctx context.Context, deliveryEvent m
if err := h.deliveryMQ.Publish(ctx, deliveryEvent); err != nil {
h.logger.Ctx(ctx).Error("failed to enqueue delivery event",
zap.Error(err),
zap.String("delivery_event_id", deliveryEvent.ID),
zap.String("event_id", deliveryEvent.Event.ID),
zap.String("tenant_id", deliveryEvent.Event.TenantID),
zap.String("destination_id", deliveryEvent.DestinationID))
deliverySpan.RecordError(err)
deliverySpan.End()
return err
}

h.logger.Ctx(ctx).Audit("delivery event enqueued",
zap.String("delivery_event_id", deliveryEvent.ID),
zap.String("event_id", deliveryEvent.Event.ID),
zap.String("tenant_id", deliveryEvent.Event.TenantID),
zap.String("destination_id", deliveryEvent.DestinationID))
deliverySpan.End()
return nil
Expand Down
Loading