From 954100417e16572a2d2d49a9cde354504e1ca4d7 Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Thu, 19 Dec 2024 17:21:05 -0500 Subject: [PATCH] Remove previously added aggregated versions of channel type specific metrics because apparently we don't need them --- backends/rapidpro/stats.go | 18 +----------------- backends/rapidpro/stats_test.go | 12 ++---------- 2 files changed, 3 insertions(+), 27 deletions(-) diff --git a/backends/rapidpro/stats.go b/backends/rapidpro/stats.go index 10c71282..8905b367 100644 --- a/backends/rapidpro/stats.go +++ b/backends/rapidpro/stats.go @@ -14,14 +14,9 @@ type CountByType map[courier.ChannelType]int // converts per channel counts into a set of cloudwatch metrics with type as a dimension, and a total count without type func (c CountByType) metrics(name string) []types.MetricDatum { m := make([]types.MetricDatum, 0, len(c)+1) - total := 0 for typ, count := range c { m = append(m, cwatch.Datum(name, float64(count), types.StandardUnitCount, cwatch.Dimension("ChannelType", string(typ)))) - - total += count } - - m = append(m, cwatch.Datum(name, float64(total), types.StandardUnitCount)) return m } @@ -29,20 +24,9 @@ type DurationByType map[courier.ChannelType]time.Duration func (c DurationByType) metrics(name string, avgDenom func(courier.ChannelType) int) []types.MetricDatum { m := make([]types.MetricDatum, 0, len(c)+1) - totalDuration := time.Duration(0) - totalDenom := 0 for typ, d := range c { // convert to averages - denom := avgDenom(typ) - avgTime := d / time.Duration(denom) + avgTime := d / time.Duration(avgDenom(typ)) m = append(m, cwatch.Datum(name, float64(avgTime)/float64(time.Second), types.StandardUnitSeconds, cwatch.Dimension("ChannelType", string(typ)))) - - totalDuration += d - totalDenom += denom - } - - if totalDenom > 0 { - overallAvg := float64(totalDuration) / float64(totalDenom) - m = append(m, cwatch.Datum(name, overallAvg/float64(time.Second), types.StandardUnitSeconds)) } return m } diff --git a/backends/rapidpro/stats_test.go b/backends/rapidpro/stats_test.go index 12d5477f..d0172e56 100644 --- a/backends/rapidpro/stats_test.go +++ b/backends/rapidpro/stats_test.go @@ -35,7 +35,7 @@ func TestStats(t *testing.T) { assert.Equal(t, rapidpro.DurationByType{"T": time.Second * 2, "FBA": time.Second * 3}, stats.OutgoingDuration) metrics := stats.ToMetrics() - assert.Len(t, metrics, 17) + assert.Len(t, metrics, 8) sc.RecordOutgoing("FBA", true, time.Second) sc.RecordOutgoing("FBA", true, time.Second) @@ -53,18 +53,10 @@ func TestStats(t *testing.T) { assert.Equal(t, rapidpro.DurationByType{"FBA": time.Second * 2}, stats.OutgoingDuration) metrics = stats.ToMetrics() - assert.Len(t, metrics, 11) + assert.Len(t, metrics, 3) assert.Equal(t, []types.MetricDatum{ - cwatch.Datum("IncomingRequests", 0, "Count"), - cwatch.Datum("IncomingMessages", 0, "Count"), - cwatch.Datum("IncomingStatuses", 0, "Count"), - cwatch.Datum("IncomingEvents", 0, "Count"), - cwatch.Datum("IncomingIgnored", 0, "Count"), cwatch.Datum("OutgoingSends", 2, "Count", cwatch.Dimension("ChannelType", "FBA")), - cwatch.Datum("OutgoingSends", 2, "Count"), - cwatch.Datum("OutgoingErrors", 0, "Count"), cwatch.Datum("OutgoingDuration", 1, "Seconds", cwatch.Dimension("ChannelType", "FBA")), - cwatch.Datum("OutgoingDuration", 1, "Seconds"), cwatch.Datum("ContactsCreated", 0, "Count"), }, metrics) }