|
6 | 6 | "encoding/json" |
7 | 7 | "fmt" |
8 | 8 | "io" |
9 | | - "math" |
10 | 9 | "net/http" |
11 | 10 | "net/url" |
12 | 11 | "strings" |
@@ -630,39 +629,41 @@ func collectNotificationQueueMetrics() { |
630 | 629 | eventType := GetEventLabelForNotification(notification) |
631 | 630 |
|
632 | 631 | // Record the amount of time records that were sent (and that still exist in the queue) took to sent |
633 | | - metrics.NotificationsQueue_Sent_Time.WithLabelValues(notification.Channel, eventType).Observe(GetTimeDiffMilliseconds(*notification.Sent, *notification.Created)) |
| 632 | + duration := notification.Created.Sub(*notification.Sent).Abs() |
| 633 | + metrics.NotificationsQueueSentTime.WithLabelValues(notification.Channel, eventType).Observe(duration.Seconds()) |
634 | 634 | } |
635 | 635 |
|
636 | 636 | // Record for each pending notification how long it has been in the queue |
637 | 637 | for _, notification := range pendingNotifications { |
638 | 638 | eventType := GetEventLabelForNotification(notification) |
639 | 639 |
|
640 | 640 | // Record the amount of time these records have been waiting to been sent |
641 | | - metrics.NotificationsQueue_Pending_Time.WithLabelValues(notification.Channel, eventType).Observe(GetTimeDiffMilliseconds(*notification.Created, now)) |
| 641 | + duration := notification.Created.Sub(now).Abs() |
| 642 | + metrics.NotificationsQueuePendingTime.WithLabelValues(notification.Channel, eventType).Observe(duration.Seconds()) |
642 | 643 | } |
643 | 644 |
|
644 | 645 | // Count number of pending notifications in the queue by event type |
645 | 646 | eventTypeCount := CountByEventType(pendingNotifications) |
646 | 647 | for eventType, numNotifications := range eventTypeCount { |
647 | | - metrics.NotificationsQueue_Event_Size.WithLabelValues(eventType, string(Pending)).Set(float64(numNotifications)) |
| 648 | + metrics.NotificationsQueueEventSize.WithLabelValues(eventType, string(Pending)).Set(float64(numNotifications)) |
648 | 649 | } |
649 | 650 |
|
650 | 651 | // Count number of sent notifications in the queue by event type |
651 | 652 | eventTypeCount = CountByEventType(sentNotifications) |
652 | 653 | for eventType, numNotifications := range eventTypeCount { |
653 | | - metrics.NotificationsQueue_Event_Size.WithLabelValues(eventType, string(Sent)).Set(float64(numNotifications)) |
| 654 | + metrics.NotificationsQueueEventSize.WithLabelValues(eventType, string(Sent)).Set(float64(numNotifications)) |
654 | 655 | } |
655 | 656 |
|
656 | 657 | // Count number of pending notifications in the queue by channel |
657 | 658 | channelCount := CountByChannel(pendingNotifications) |
658 | 659 | for channelType, numNotifications := range channelCount { |
659 | | - metrics.NotificationsQueue_Channel_Size.WithLabelValues(channelType, string(Pending)).Set(float64(numNotifications)) |
| 660 | + metrics.NotificationsQueueChannelSize.WithLabelValues(channelType, string(Pending)).Set(float64(numNotifications)) |
660 | 661 | } |
661 | 662 |
|
662 | 663 | // Count number of sent notifications in the queue by channel |
663 | 664 | channelCount = CountByChannel(sentNotifications) |
664 | 665 | for channelType, numNotifications := range channelCount { |
665 | | - metrics.NotificationsQueue_Channel_Size.WithLabelValues(channelType, string(Sent)).Set(float64(numNotifications)) |
| 666 | + metrics.NotificationsQueueChannelSize.WithLabelValues(channelType, string(Sent)).Set(float64(numNotifications)) |
666 | 667 | } |
667 | 668 | } |
668 | 669 |
|
@@ -736,12 +737,3 @@ func CountByChannel(notifications []Notification) map[string]int { |
736 | 737 | } |
737 | 738 | return channelCountMap |
738 | 739 | } |
739 | | - |
740 | | -/** |
741 | | - * Returns the amount of milliseconds between two timestamps. Always returns a positive |
742 | | - * duration, so you don't have to worry about date ordering |
743 | | - */ |
744 | | -func GetTimeDiffMilliseconds(time1 time.Time, time2 time.Time) float64 { |
745 | | - duration := time1.Sub(time2) |
746 | | - return math.Abs(float64(duration.Milliseconds())) |
747 | | -} |
0 commit comments