Skip to content

Commit

Permalink
Clean up old analytics use
Browse files Browse the repository at this point in the history
  • Loading branch information
norkans7 committed Dec 13, 2024
1 parent 5149068 commit f0f5926
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")

Check warning on line 80 in daemon.go

View check run for this annotation

Codecov / codecov/patch

daemon.go#L80

Added line #L80 was not covered by tests
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 f0f5926

Please sign in to comment.