Skip to content

Commit

Permalink
Remove librato
Browse files Browse the repository at this point in the history
  • Loading branch information
norkans7 committed Dec 16, 2024
1 parent 9b91ac2 commit be4f469
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 39 deletions.
15 changes: 1 addition & 14 deletions backends/rapidpro/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/jmoiron/sqlx"
"github.com/nyaruka/courier"
"github.com/nyaruka/courier/queue"
"github.com/nyaruka/gocommon/analytics"
"github.com/nyaruka/gocommon/aws/cwatch"
"github.com/nyaruka/gocommon/aws/dynamo"
"github.com/nyaruka/gocommon/aws/s3x"
Expand Down Expand Up @@ -783,7 +782,6 @@ func (b *backend) Heartbeat() error {
b.stats.dbWaitCount = dbStats.WaitCount
b.stats.redisWaitDuration = redisStats.WaitDuration
b.stats.redisWaitCount = redisStats.WaitCount

dims := []cwtypes.Dimension{
{Name: aws.String("Host"), Value: aws.String(b.config.InstanceID)},
{Name: aws.String("App"), Value: aws.String("courier")},
Expand Down Expand Up @@ -858,18 +856,7 @@ func (b *backend) Heartbeat() error {
slog.Error("error putting metrics", "error", err)
}

analytics.Gauge("courier.db_busy", float64(dbStats.InUse))
analytics.Gauge("courier.db_idle", float64(dbStats.Idle))
analytics.Gauge("courier.db_wait_ms", float64(dbWaitDurationInPeriod/time.Millisecond))
analytics.Gauge("courier.db_wait_count", float64(dbWaitCountInPeriod))
analytics.Gauge("courier.redis_active", float64(redisStats.ActiveCount))
analytics.Gauge("courier.redis_idle", float64(redisStats.IdleCount))
analytics.Gauge("courier.redis_wait_ms", float64(redisWaitDurationInPeriod/time.Millisecond))
analytics.Gauge("courier.redis_wait_count", float64(redisWaitCountInPeriod))
analytics.Gauge("courier.bulk_queue", float64(bulkSize))
analytics.Gauge("courier.priority_queue", float64(prioritySize))

slog.Info("current analytics", "db_busy", dbStats.InUse,
slog.Info("current metrics", "db_busy", dbStats.InUse,
"db_idle", dbStats.Idle,
"db_wait_time", dbWaitDurationInPeriod,
"db_wait_count", dbWaitCountInPeriod,
Expand Down
2 changes: 1 addition & 1 deletion backends/rapidpro/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ func (ts *BackendTestSuite) TestHealth() {
}

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

Expand Down
4 changes: 1 addition & 3 deletions backends/rapidpro/contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/jmoiron/sqlx"
"github.com/nyaruka/courier"
"github.com/nyaruka/gocommon/analytics"
"github.com/nyaruka/gocommon/dbutil"
"github.com/nyaruka/gocommon/urns"
"github.com/nyaruka/gocommon/uuids"
Expand Down Expand Up @@ -219,8 +218,7 @@ func contactForURN(ctx context.Context, b *backend, org OrgID, channel *Channel,
// store this URN on our contact
contact.URNID_ = contactURN.ID

// log that we created a new contact to librato
analytics.Gauge("courier.new_contact", float64(1))
// log that we created a new contact to cloudwatch
b.cw.Send(ctx, types.MetricDatum{MetricName: aws.String("NewContact"), Value: aws.Float64(float64(1)), Unit: types.StandardUnitCount})

// and return it
Expand Down
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Config struct {

DynamoEndpoint string `help:"DynamoDB service endpoint, e.g. https://dynamodb.us-east-1.amazonaws.com"`
DynamoTablePrefix string `help:"prefix to use for DynamoDB tables"`
InstanceID string `help:"the instance identifier to use for metrics"`

Check failure on line 39 in config.go

View workflow job for this annotation

GitHub Actions / Test

InstanceID redeclared

Check failure on line 39 in config.go

View workflow job for this annotation

GitHub Actions / Test

InstanceID redeclared

S3Endpoint string `help:"S3 service endpoint, e.g. https://s3.amazonaws.com"`
S3AttachmentsBucket string `help:"S3 bucket to write attachments to"`
Expand Down
3 changes: 0 additions & 3 deletions sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/cloudwatch/types"
"github.com/nyaruka/courier/utils/clogs"
"github.com/nyaruka/gocommon/analytics"
"github.com/nyaruka/gocommon/urns"
)

Expand Down Expand Up @@ -337,11 +336,9 @@ func (w *Sender) sendMessage(msg MsgOut) {

// report to librato
if status.Status() == MsgStatusErrored || status.Status() == MsgStatusFailed {
analytics.Gauge(fmt.Sprintf("courier.msg_send_error_%s", msg.Channel().ChannelType()), secondDuration)
backend.CloudWatchService().Send(sendCTX, types.MetricDatum{MetricName: aws.String(fmt.Sprintf("MsgSendError_%s", msg.Channel().ChannelType())), Value: aws.Float64(float64(secondDuration)), Unit: types.StandardUnitSeconds})

} else {
analytics.Gauge(fmt.Sprintf("courier.msg_send_%s", msg.Channel().ChannelType()), secondDuration)
backend.CloudWatchService().Send(sendCTX, types.MetricDatum{MetricName: aws.String(fmt.Sprintf("MsgSend_%s", msg.Channel().ChannelType())), Value: aws.Float64(float64(secondDuration)), Unit: types.StandardUnitSeconds})
}
}
Expand Down
19 changes: 1 addition & 18 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"log"
"log/slog"
"net/http"
"os"
"runtime/debug"
"slices"
"sort"
Expand All @@ -22,7 +21,6 @@ import (
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/nyaruka/courier/utils/clogs"
"github.com/nyaruka/gocommon/analytics"
"github.com/nyaruka/gocommon/httpx"
"github.com/nyaruka/gocommon/jsonx"
)
Expand Down Expand Up @@ -94,14 +92,6 @@ func NewServerWithLogger(config *Config, backend Backend, logger *slog.Logger) S
// if it encounters any unrecoverable (or ignorable) error, though its bias is to move forward despite
// connection errors
func (s *server) Start() error {
// configure librato if we have configuration options for it
host, _ := os.Hostname()
if s.config.LibratoUsername != "" {
analytics.RegisterBackend(analytics.NewLibrato(s.config.LibratoUsername, s.config.LibratoToken, host, time.Second, s.waitGroup))
}

analytics.Start()

// start our backend
err := s.backend.Start()
if err != nil {
Expand Down Expand Up @@ -197,8 +187,6 @@ func (s *server) Stop() error {
return err
}

analytics.Stop()

// wait for everything to stop
s.waitGroup.Wait()

Expand Down Expand Up @@ -318,14 +306,12 @@ func (s *server) channelHandleWrapper(handler ChannelHandler, handlerFunc Channe
}

if channel != nil {
// if we have a channel but no events were created, we still log this to analytics
// if we have a channel but no events were created, we still log this to cloudwatch
if len(events) == 0 {
if hErr != nil {
s.Backend().CloudWatchService().Send(ctx, types.MetricDatum{MetricName: aws.String(fmt.Sprintf("ChannelError_%s", channel.ChannelType())), Value: aws.Float64(float64(secondDuration)), Unit: types.StandardUnitSeconds})
analytics.Gauge(fmt.Sprintf("courier.channel_error_%s", channel.ChannelType()), secondDuration)
} else {
s.Backend().CloudWatchService().Send(ctx, types.MetricDatum{MetricName: aws.String(fmt.Sprintf("ChannelIgnored_%s", channel.ChannelType())), Value: aws.Float64(float64(secondDuration)), Unit: types.StandardUnitSeconds})
analytics.Gauge(fmt.Sprintf("courier.channel_ignored_%s", channel.ChannelType()), secondDuration)
}
}

Expand All @@ -334,16 +320,13 @@ func (s *server) channelHandleWrapper(handler ChannelHandler, handlerFunc Channe
case MsgIn:
clog.SetAttached(true)
s.Backend().CloudWatchService().Send(ctx, types.MetricDatum{MetricName: aws.String(fmt.Sprintf("MsgReceive_%s", channel.ChannelType())), Value: aws.Float64(float64(secondDuration)), Unit: types.StandardUnitSeconds})
analytics.Gauge(fmt.Sprintf("courier.msg_receive_%s", channel.ChannelType()), secondDuration)
LogMsgReceived(r, e)
case StatusUpdate:
clog.SetAttached(true)
s.Backend().CloudWatchService().Send(ctx, types.MetricDatum{MetricName: aws.String(fmt.Sprintf("MsgStatus_%s", channel.ChannelType())), Value: aws.Float64(float64(secondDuration)), Unit: types.StandardUnitSeconds})
analytics.Gauge(fmt.Sprintf("courier.msg_status_%s", channel.ChannelType()), secondDuration)
LogMsgStatusReceived(r, e)
case ChannelEvent:
s.Backend().CloudWatchService().Send(ctx, types.MetricDatum{MetricName: aws.String(fmt.Sprintf("EvtReceive_%s", channel.ChannelType())), Value: aws.Float64(float64(secondDuration)), Unit: types.StandardUnitSeconds})
analytics.Gauge(fmt.Sprintf("courier.evt_receive_%s", channel.ChannelType()), secondDuration)
LogChannelEventReceived(r, e)
}
}
Expand Down

0 comments on commit be4f469

Please sign in to comment.