Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send db and redis stats to librato in backed heartbeat #404

Merged
merged 1 commit into from
Jan 18, 2022
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
43 changes: 37 additions & 6 deletions backends/rapidpro/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"sync"
"time"

"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/gomodule/redigo/redis"
"github.com/jmoiron/sqlx"
"github.com/nyaruka/courier"
Expand Down Expand Up @@ -438,10 +437,39 @@ func (b *backend) Heartbeat() error {
bulkSize += count
}

// log our total
// get our DB and redis stats
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dbStats := b.db.Stats()
redisStats := b.redisPool.Stats()

dbWaitDurationInPeriod := dbStats.WaitDuration - b.dbWaitDuration
dbWaitCountInPeriod := dbStats.WaitCount - b.dbWaitCount
redisWaitDurationInPeriod := redisStats.WaitDuration - b.redisWaitDuration
redisWaitCountInPeriod := redisStats.WaitCount - b.redisWaitCount

b.dbWaitDuration = dbStats.WaitDuration
b.dbWaitCount = dbStats.WaitCount
b.redisWaitDuration = redisStats.WaitDuration
b.redisWaitCount = redisStats.WaitCount

librato.Gauge("courier.db_busy", float64(dbStats.InUse))
librato.Gauge("courier.db_idle", float64(dbStats.Idle))
librato.Gauge("courier.db_wait_ms", float64(dbWaitDurationInPeriod/time.Millisecond))
librato.Gauge("courier.db_wait_count", float64(dbWaitCountInPeriod))
librato.Gauge("courier.redis_wait_ms", float64(redisWaitDurationInPeriod/time.Millisecond))
librato.Gauge("courier.redis_wait_count", float64(redisWaitCountInPeriod))
librato.Gauge("courier.bulk_queue", float64(bulkSize))
librato.Gauge("courier.priority_queue", float64(prioritySize))
logrus.WithField("bulk_queue", bulkSize).WithField("priority_queue", prioritySize).Info("heartbeat queue sizes calculated")

logrus.WithFields(logrus.Fields{
"db_busy": dbStats.InUse,
"db_idle": dbStats.Idle,
"db_wait_time": dbWaitDurationInPeriod,
"db_wait_count": dbWaitCountInPeriod,
"redis_wait_time": dbWaitDurationInPeriod,
"redis_wait_count": dbWaitCountInPeriod,
"priority_size": prioritySize,
"bulk_size": bulkSize,
}).Info("current analytics")

return nil
}
Expand Down Expand Up @@ -753,10 +781,13 @@ type backend struct {
db *sqlx.DB
redisPool *redis.Pool
storage storage.Storage
awsCreds *credentials.Credentials

popScript *redis.Script
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not used


stopChan chan bool
waitGroup *sync.WaitGroup

// both sqlx and redis provide wait stats which are cummulative that we need to convert into increments
dbWaitDuration time.Duration
dbWaitCount int64
redisWaitDuration time.Duration
redisWaitCount int64
}
5 changes: 5 additions & 0 deletions backends/rapidpro/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,11 @@ func (ts *BackendTestSuite) TestHealth() {
ts.Equal(ts.b.Health(), "")
}

func (ts *BackendTestSuite) TestHeartbeat() {
// TODO make analytics abstraction layer so we can test what we report
ts.NoError(ts.b.Heartbeat())
}

func (ts *BackendTestSuite) TestDupes() {
r := ts.b.redisPool.Get()
defer r.Close()
Expand Down