mirror of
https://github.com/christianselig/apollo-backend
synced 2024-11-25 13:17:42 +00:00
measure runtime
This commit is contained in:
parent
63cc67cd86
commit
73da53ab70
1 changed files with 7 additions and 3 deletions
|
@ -135,13 +135,19 @@ func NewNotificationsConsumer(nw *notificationsWorker, tag int) *notificationsCo
|
|||
}
|
||||
|
||||
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()
|
||||
key := fmt.Sprintf("locks:accounts:%s", id)
|
||||
|
||||
// Measure queue latency
|
||||
ttl := nc.redis.TTL(nc, key).Val()
|
||||
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() {
|
||||
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)
|
||||
if err != nil {
|
||||
nc.logger.Error("failed to fetch account from database", zap.Error(err), zap.String("account#reddit_account_id", id))
|
||||
|
|
Loading…
Reference in a new issue