measure runtime

This commit is contained in:
Andre Medeiros 2022-07-13 18:25:00 -04:00
parent 63cc67cd86
commit 73da53ab70

View file

@ -135,13 +135,19 @@ func NewNotificationsConsumer(nw *notificationsWorker, tag int) *notificationsCo
} }
func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) { func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) {
now := time.Now()
defer func() {
elapsed := time.Now().Sub(now).Milliseconds()
_ = nc.statsd.Histogram("apollo.queue.runtime", float64(elapsed), []string{"queue:notifications"}, 0.1)
}()
id := delivery.Payload() id := delivery.Payload()
key := fmt.Sprintf("locks:accounts:%s", id) key := fmt.Sprintf("locks:accounts:%s", id)
// Measure queue latency // Measure queue latency
ttl := nc.redis.TTL(nc, key).Val() ttl := nc.redis.TTL(nc, key).Val()
age := (domain.NotificationCheckTimeout - ttl) age := (domain.NotificationCheckTimeout - ttl)
_ = nc.statsd.Histogram("apollo.dequeue.latency", float64(age.Milliseconds()), []string{"queue:notifications"}, 1.0) _ = nc.statsd.Histogram("apollo.dequeue.latency", float64(age.Milliseconds()), []string{"queue:notifications"}, 0.1)
defer func() { defer func() {
if err := nc.redis.Del(nc, key).Err(); err != nil { if err := nc.redis.Del(nc, key).Err(); err != nil {
@ -157,8 +163,6 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) {
} }
}() }()
now := time.Now()
account, err := nc.accountRepo.GetByRedditID(nc, id) account, err := nc.accountRepo.GetByRedditID(nc, id)
if err != nil { if err != nil {
nc.logger.Error("failed to fetch account from database", zap.Error(err), zap.String("account#reddit_account_id", id)) nc.logger.Error("failed to fetch account from database", zap.Error(err), zap.String("account#reddit_account_id", id))