Skip to content

Commit

Permalink
Merge pull request #92 from nyaruka/remove-old-analytics
Browse files Browse the repository at this point in the history
Clean up old analytics use
  • Loading branch information
rowanseymour authored Dec 13, 2024
2 parents 5149068 + f0f5926 commit a2fd407
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/cloudwatch/types"
"github.com/nyaruka/gocommon/analytics"
"github.com/nyaruka/rp-indexer/v9/indexers"
"github.com/nyaruka/rp-indexer/v9/runtime"
)
Expand Down Expand Up @@ -78,7 +77,7 @@ func (d *Daemon) startStatsReporter(interval time.Duration) {

go func() {
defer func() {
slog.Info("analytics exiting")
slog.Info("metrics reporter exiting")
d.wg.Done()
}()

Expand All @@ -100,7 +99,6 @@ func (d *Daemon) reportStats(includeLag bool) {
defer cancel()

log := slog.New(slog.Default().Handler())
guages := make(map[string]float64, len(d.indexers)*3)
metrics := make([]types.MetricDatum, 0, len(d.indexers)*3)

for _, ix := range d.indexers {
Expand All @@ -115,10 +113,6 @@ func (d *Daemon) reportStats(includeLag bool) {
rateInPeriod = float64(indexedInPeriod) / (float64(elapsedInPeriod) / float64(time.Second))
}

guages[ix.Name()+"_indexed"] = float64(indexedInPeriod)
guages[ix.Name()+"_deleted"] = float64(deletedInPeriod)
guages[ix.Name()+"_rate"] = rateInPeriod

dims := []types.Dimension{{Name: aws.String("Index"), Value: aws.String(ix.Name())}}

metrics = append(metrics,
Expand All @@ -134,18 +128,12 @@ func (d *Daemon) reportStats(includeLag bool) {
if err != nil {
log.Error("error getting db last modified", "index", ix.Name(), "error", err)
} else {
guages[ix.Name()+"_lag"] = lag.Seconds()

metrics = append(metrics, types.MetricDatum{MetricName: aws.String("IndexerLag"), Dimensions: dims, Value: aws.Float64(lag.Seconds()), Unit: types.StandardUnitSeconds})
}
}
}

for k, v := range guages {
analytics.Gauge("indexer."+k, v)
log = log.With(k, v)
}

if err := d.rt.CW.Send(ctx, metrics...); err != nil {
log.Error("error putting metrics", "error", err)
}
Expand All @@ -170,7 +158,6 @@ func (d *Daemon) calculateLag(ctx context.Context, ix indexers.Indexer) (time.Du
// Stop stops this daemon
func (d *Daemon) Stop() {
slog.Info("daemon stopping")
analytics.Stop()

close(d.quit)
d.wg.Wait()
Expand Down

0 comments on commit a2fd407

Please sign in to comment.