Skip to content

Commit

Permalink
Remove previously added aggregated versions of channel type specific …
Browse files Browse the repository at this point in the history
…metrics because apparently we don't need them
  • Loading branch information
rowanseymour committed Dec 19, 2024
1 parent 915d440 commit 9541004
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 27 deletions.
18 changes: 1 addition & 17 deletions backends/rapidpro/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,19 @@ 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
}

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
}
Expand Down
12 changes: 2 additions & 10 deletions backends/rapidpro/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}

0 comments on commit 9541004

Please sign in to comment.