Skip to content

Commit

Permalink
use batch api always
Browse files Browse the repository at this point in the history
  • Loading branch information
taraspos committed Feb 20, 2020
1 parent c30e406 commit 4fe2398
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions metrics/cloudwatch/cloudwatch.go
Expand Up @@ -181,25 +181,23 @@ func (cw *CloudWatch) Send() error {
Timestamp: aws.Time(now),
}

if l := len(values); l > 1 {
// 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)
for _, v := range values {
valuesCounter[v]++
}
if len(values) == 0 {
return true
}

for value, count := range valuesCounter {
if len(datum.Values) == maxValuesInABatch {
break
}
datum.Values = append(datum.Values, aws.Float64(value))
datum.Counts = append(datum.Counts, aws.Float64(float64(count)))
// 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)
for _, v := range values {
valuesCounter[v]++
}

for value, count := range valuesCounter {
if len(datum.Values) == maxValuesInABatch {
break
}
} else if l == 1 {
datum.Value = aws.Float64(values[0])
} else {
return true
datum.Values = append(datum.Values, aws.Float64(value))
datum.Counts = append(datum.Counts, aws.Float64(float64(count)))
}

datums = append(datums, datum)
Expand Down

0 comments on commit 4fe2398

Please sign in to comment.