Skip to content

Commit

Permalink
Use analytics package from gocommon instead of librato directly
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed May 26, 2022
1 parent a846409 commit 3eb9f0c
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 29 deletions.
12 changes: 6 additions & 6 deletions core/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (

"github.com/gomodule/redigo/redis"
"github.com/jmoiron/sqlx"
"github.com/nyaruka/gocommon/analytics"
"github.com/nyaruka/goflow/assets"
"github.com/nyaruka/goflow/excellent/types"
"github.com/nyaruka/goflow/flows"
"github.com/nyaruka/goflow/flows/triggers"
"github.com/nyaruka/librato"
"github.com/nyaruka/mailroom/core/goflow"
"github.com/nyaruka/mailroom/core/models"
"github.com/nyaruka/mailroom/core/queue"
Expand Down Expand Up @@ -243,8 +243,8 @@ func StartFlowBatch(
}

// log both our total and average
librato.Gauge("mr.flow_batch_start_elapsed", float64(time.Since(start))/float64(time.Second))
librato.Gauge("mr.flow_batch_start_count", float64(len(sessions)))
analytics.Gauge("mr.flow_batch_start_elapsed", float64(time.Since(start))/float64(time.Second))
analytics.Gauge("mr.flow_batch_start_count", float64(len(sessions)))

return sessions, nil
}
Expand Down Expand Up @@ -393,8 +393,8 @@ func FireCampaignEvents(
}

// log both our total and average
librato.Gauge("mr.campaign_event_elapsed", float64(time.Since(start))/float64(time.Second))
librato.Gauge("mr.campaign_event_count", float64(len(sessions)))
analytics.Gauge("mr.campaign_event_elapsed", float64(time.Since(start))/float64(time.Second))
analytics.Gauge("mr.campaign_event_count", float64(len(sessions)))

// build the list of contacts actually started
startedContacts := make([]models.ContactID, len(sessions))
Expand Down Expand Up @@ -559,7 +559,7 @@ func StartFlowForContacts(
continue
}
log.WithField("elapsed", time.Since(start)).Info("flow engine start")
librato.Gauge("mr.flow_start_elapsed", float64(time.Since(start)))
analytics.Gauge("mr.flow_start_elapsed", float64(time.Since(start)))

sessions = append(sessions, session)
sprints = append(sprints, sprint)
Expand Down
18 changes: 9 additions & 9 deletions core/tasks/analytics/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"time"

"github.com/nyaruka/librato"
"github.com/nyaruka/gocommon/analytics"
"github.com/nyaruka/mailroom"
"github.com/nyaruka/mailroom/core/queue"
"github.com/nyaruka/mailroom/runtime"
Expand Down Expand Up @@ -60,14 +60,14 @@ func reportAnalytics(ctx context.Context, rt *runtime.Runtime) error {
redisWaitDuration = redisStats.WaitDuration
redisWaitCount = redisStats.WaitCount

librato.Gauge("mr.db_busy", float64(dbStats.InUse))
librato.Gauge("mr.db_idle", float64(dbStats.Idle))
librato.Gauge("mr.db_wait_ms", float64(dbWaitDurationInPeriod/time.Millisecond))
librato.Gauge("mr.db_wait_count", float64(dbWaitCountInPeriod))
librato.Gauge("mr.redis_wait_ms", float64(redisWaitDurationInPeriod/time.Millisecond))
librato.Gauge("mr.redis_wait_count", float64(redisWaitCountInPeriod))
librato.Gauge("mr.handler_queue", float64(handlerSize))
librato.Gauge("mr.batch_queue", float64(batchSize))
analytics.Gauge("mr.db_busy", float64(dbStats.InUse))
analytics.Gauge("mr.db_idle", float64(dbStats.Idle))
analytics.Gauge("mr.db_wait_ms", float64(dbWaitDurationInPeriod/time.Millisecond))
analytics.Gauge("mr.db_wait_count", float64(dbWaitCountInPeriod))
analytics.Gauge("mr.redis_wait_ms", float64(redisWaitDurationInPeriod/time.Millisecond))
analytics.Gauge("mr.redis_wait_count", float64(redisWaitCountInPeriod))
analytics.Gauge("mr.handler_queue", float64(handlerSize))
analytics.Gauge("mr.batch_queue", float64(batchSize))

logrus.WithFields(logrus.Fields{
"db_busy": dbStats.InUse,
Expand Down
6 changes: 3 additions & 3 deletions core/tasks/campaigns/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"time"

"github.com/gomodule/redigo/redis"
"github.com/nyaruka/gocommon/analytics"
"github.com/nyaruka/goflow/assets"
"github.com/nyaruka/librato"
"github.com/nyaruka/mailroom"
"github.com/nyaruka/mailroom/core/models"
"github.com/nyaruka/mailroom/core/queue"
Expand Down Expand Up @@ -107,8 +107,8 @@ func QueueEventFires(ctx context.Context, rt *runtime.Runtime) error {
numTasks++
}

librato.Gauge("mr.campaign_event_cron_elapsed", float64(time.Since(start))/float64(time.Second))
librato.Gauge("mr.campaign_event_cron_count", float64(numFires))
analytics.Gauge("mr.campaign_event_cron_elapsed", float64(time.Since(start))/float64(time.Second))
analytics.Gauge("mr.campaign_event_cron_count", float64(numFires))
log.WithFields(logrus.Fields{
"elapsed": time.Since(start),
"fires": numFires,
Expand Down
6 changes: 3 additions & 3 deletions core/tasks/handler/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/gomodule/redigo/redis"
"github.com/jmoiron/sqlx"
"github.com/nyaruka/gocommon/analytics"
"github.com/nyaruka/gocommon/dbutil"
"github.com/nyaruka/gocommon/urns"
"github.com/nyaruka/goflow/excellent/types"
Expand All @@ -17,7 +18,6 @@ import (
"github.com/nyaruka/goflow/flows/resumes"
"github.com/nyaruka/goflow/flows/triggers"
"github.com/nyaruka/goflow/utils"
"github.com/nyaruka/librato"
"github.com/nyaruka/mailroom"
"github.com/nyaruka/mailroom/core/models"
"github.com/nyaruka/mailroom/core/queue"
Expand Down Expand Up @@ -159,10 +159,10 @@ func handleContactEvent(ctx context.Context, rt *runtime.Runtime, task *queue.Ta
}

// log our processing time to librato
librato.Gauge(fmt.Sprintf("mr.%s_elapsed", contactEvent.Type), float64(time.Since(start))/float64(time.Second))
analytics.Gauge(fmt.Sprintf("mr.%s_elapsed", contactEvent.Type), float64(time.Since(start))/float64(time.Second))

// and total latency for this task since it was queued
librato.Gauge(fmt.Sprintf("mr.%s_latency", contactEvent.Type), float64(time.Since(task.QueuedOn))/float64(time.Second))
analytics.Gauge(fmt.Sprintf("mr.%s_latency", contactEvent.Type), float64(time.Since(task.QueuedOn))/float64(time.Second))

// if we get an error processing an event, requeue it for later and return our error
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ require (
github.com/jmoiron/sqlx v1.3.4
github.com/lib/pq v1.10.4
github.com/nyaruka/ezconf v0.2.1
github.com/nyaruka/gocommon v1.20.0
github.com/nyaruka/gocommon v1.21.0
github.com/nyaruka/goflow v0.159.2
github.com/nyaruka/librato v1.0.0
github.com/nyaruka/logrus_sentry v0.8.2-0.20190129182604-c2962b80ba7d
github.com/nyaruka/null v1.2.0
github.com/nyaruka/redisx v0.2.1
Expand Down Expand Up @@ -54,6 +53,7 @@ require (
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/naoina/go-stringutil v0.1.0 // indirect
github.com/naoina/toml v0.1.1 // indirect
github.com/nyaruka/librato v1.0.0 // indirect
github.com/nyaruka/phonenumbers v1.0.75 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ github.com/naoina/toml v0.1.1 h1:PT/lllxVVN0gzzSqSlHEmP8MJB4MY2U7STGxiouV4X8=
github.com/naoina/toml v0.1.1/go.mod h1:NBIhNtsFMo3G2szEBne+bO4gS192HuIYRqfvOWb4i1E=
github.com/nyaruka/ezconf v0.2.1 h1:TDXWoqjqYya1uhou1mAJZg7rgFYL98EB0Tb3+BWtUh0=
github.com/nyaruka/ezconf v0.2.1/go.mod h1:ey182kYkw2MIi4XiWe1FR/mzI33WCmTWuceDYYxgnQw=
github.com/nyaruka/gocommon v1.20.0 h1:qbxRsBBPvpfGbuBq08jlQGxa5t+UZX/YGV7+kR+/moM=
github.com/nyaruka/gocommon v1.20.0/go.mod h1:JrQSLAPo9ezSy1AzsJ1zDr1HW0/eu+aipICJkN/+kpg=
github.com/nyaruka/gocommon v1.21.0 h1:nu7M2cdSPrkqUPdGsEeWX047+neo69H4x+4g/OKpoLM=
github.com/nyaruka/gocommon v1.21.0/go.mod h1:cv9r6amof1gSktfPZROClZhLFzdSIH/N9KbW6Nny4g8=
github.com/nyaruka/goflow v0.159.2 h1:tyAILWt7DGQ5nfd2/ZN4BNlVxPbm/Omoz/CHS6hs+UM=
github.com/nyaruka/goflow v0.159.2/go.mod h1:iLYZOLLggFRR8e5dVgFEmB95W4FPrIKbz3w3C6Ia/0g=
github.com/nyaruka/librato v1.0.0 h1:Vznj9WCeC1yZXbBYyYp40KnbmXLbEkjKmHesV/v2SR0=
Expand Down
9 changes: 5 additions & 4 deletions mailroom.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"sync"
"time"

"github.com/nyaruka/gocommon/analytics"
"github.com/nyaruka/gocommon/storage"
"github.com/nyaruka/mailroom/core/queue"
"github.com/nyaruka/mailroom/runtime"
Expand All @@ -16,7 +17,6 @@ import (

"github.com/gomodule/redigo/redis"
"github.com/jmoiron/sqlx"
"github.com/nyaruka/librato"
"github.com/olivere/elastic/v7"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -172,10 +172,11 @@ func (mr *Mailroom) Start() error {

// if we have a librato token, configure it
if c.LibratoToken != "" {
librato.Configure(c.LibratoUsername, c.LibratoToken, c.InstanceName, time.Second, mr.wg)
librato.Start()
analytics.RegisterBackend(analytics.NewLibrato(c.LibratoUsername, c.LibratoToken, c.InstanceName, time.Second, mr.wg))
}

analytics.Start()

// init our foremen and start it
mr.batchForeman.Start()
mr.handlerForeman.Start()
Expand All @@ -194,7 +195,7 @@ func (mr *Mailroom) Stop() error {
logrus.Info("mailroom stopping")
mr.batchForeman.Stop()
mr.handlerForeman.Stop()
librato.Stop()
analytics.Stop()
close(mr.quit)
mr.cancel()

Expand Down

0 comments on commit 3eb9f0c

Please sign in to comment.