Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions metrics/cloudwatch/cloudwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,16 @@ func (cw *CloudWatch) Send() error {
})

cw.gauges.Reset().Walk(func(name string, lvs lv.LabelValues, values []float64) bool {
if len(values) == 0 {
return true
}

datum := &cloudwatch.MetricDatum{
MetricName: aws.String(name),
Dimensions: makeDimensions(lvs...),
Timestamp: aws.Time(now),
}

if len(values) == 0 {
return true
}

// CloudWatch Put Metrics API (https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_MetricDatum.html)
// expects batch of unique values including the array of corresponding counts
valuesCounter := make(map[float64]int)
Expand Down
2 changes: 1 addition & 1 deletion metrics/cloudwatch/cloudwatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ func TestGauge(t *testing.T) {
t.Fatal(err)
}
svc.mtx.RLock()
defer svc.mtx.RUnlock()
res := svc.valuesReceived[name]
delete(svc.valuesReceived, name)
defer svc.mtx.RUnlock()
return res
}

Expand Down
20 changes: 17 additions & 3 deletions metrics/teststat/teststat.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"math"
"math/rand"
"reflect"
"sort"
"strings"

"github.com/go-kit/kit/metrics"
Expand Down Expand Up @@ -53,11 +54,24 @@ func TestGauge(gauge metrics.Gauge, value func() []float64) error {
for i := 0; i < n; i++ {
f := float64(a[i])
gauge.Add(f)
want[len(want)-1] += f
want = append(want, want[len(want)-1]+f)
}

if have := value(); reflect.DeepEqual(want, have) {
return fmt.Errorf("want %f, have %f", want, have)
have := value()

switch len(have) {
case 0:
return fmt.Errorf("got 0 values")
case 1: // provider doesn't support multi value
if have[0] != want[len(want)-1] {
return fmt.Errorf("want %f, have %f", want, have)
}
default: // provider support multi value gauges
sort.Float64s(want)
sort.Float64s(have)
if !reflect.DeepEqual(want, have) {
return fmt.Errorf("want %f, have %f", want, have)
}
}

return nil
Expand Down