From 131205a0cb61a8a8157da3c3a91acde0d58d1d6d Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Wed, 13 Jul 2022 13:42:21 -0400 Subject: [PATCH] better latency measurements --- internal/worker/notifications.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/internal/worker/notifications.go b/internal/worker/notifications.go index c95c196..47152f9 100644 --- a/internal/worker/notifications.go +++ b/internal/worker/notifications.go @@ -214,13 +214,6 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) { rac = nc.reddit.NewAuthenticatedClient(account.AccountID, tokens.RefreshToken, tokens.AccessToken) } - // Only update delay on accounts we can actually check, otherwise it skews - // the numbers too much. - if !newAccount { - latency := now.Sub(previousNextCheck) - _ = nc.statsd.Histogram("apollo.queue.delay", float64(latency.Milliseconds()), []string{}, rate) - } - nc.logger.Debug("fetching message inbox", zap.String("account#reddit_account_id", id), zap.String("account#username", account.NormalizedUsername())) opts := []reddit.RequestOption{reddit.WithQuery("limit", "10")} @@ -313,6 +306,11 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) { continue } + // Latency is the time difference between the appearence of the new message and the + // time we notified at. + latency := now.Sub(msg.CreatedAt) + _ = nc.statsd.Histogram("apollo.queue.delay", float64(latency.Milliseconds()), []string{}, rate) + notification := &apns2.Notification{} notification.Topic = "com.christianselig.Apollo" notification.Payload = payloadFromMessage(account, msg, msgs.Count)