diff --git a/plugins/outputs/cloudwatch/cloudwatch.go b/plugins/outputs/cloudwatch/cloudwatch.go index c583a657ec..b8b1332faa 100644 --- a/plugins/outputs/cloudwatch/cloudwatch.go +++ b/plugins/outputs/cloudwatch/cloudwatch.go @@ -175,12 +175,14 @@ func (c *CloudWatch) pushMetricDatum() { entity, datums := c.BuildMetricDatum(metric) numberOfPartitions := len(datums) entityStr := entityToString(entity) + entityPresent := false if entityStr != "" { c.metricDatumBatch.Size += calculateEntitySize(entity) + entityPresent = true } for i := 0; i < numberOfPartitions; i++ { c.metricDatumBatch.Partition[entityStr] = append(c.metricDatumBatch.Partition[entityStr], datums[i]) - c.metricDatumBatch.Size += payload(datums[i]) + c.metricDatumBatch.Size += payload(datums[i], entityPresent) c.metricDatumBatch.Count++ if c.metricDatumBatch.isFull() { // if batch is full diff --git a/plugins/outputs/cloudwatch/cloudwatch_test.go b/plugins/outputs/cloudwatch/cloudwatch_test.go index 0b481b902f..9c844ac6a5 100644 --- a/plugins/outputs/cloudwatch/cloudwatch_test.go +++ b/plugins/outputs/cloudwatch/cloudwatch_test.go @@ -819,7 +819,7 @@ func (c *CloudWatch) calculateTotalPayloadSize(metrics pmetric.Metrics, entity * for _, agg := range aggregations { _, datums := c.BuildMetricDatum(agg) for _, datum := range datums { - totalSize += payload(datum) + totalSize += payload(datum, false) } } if entity != nil { diff --git a/plugins/outputs/cloudwatch/util.go b/plugins/outputs/cloudwatch/util.go index 3912e46905..711e38dc57 100644 --- a/plugins/outputs/cloudwatch/util.go +++ b/plugins/outputs/cloudwatch/util.go @@ -101,7 +101,7 @@ func resize(dist distribution.Distribution, listMaxSize int) (distList []distrib return } -func payload(datum *cloudwatch.MetricDatum) int { +func payload(datum *cloudwatch.MetricDatum, entityPresent bool) int { size := timestampSize for _, dimension := range datum.Dimensions { @@ -117,17 +117,30 @@ func payload(datum *cloudwatch.MetricDatum) int { size += highResolutionOverheads } + entityValueMultipler := 0 valuesCountsLen := len(datum.Values) if valuesCountsLen != 0 { size += valuesCountsLen*valuesCountsOverheads + statisticsSize + entityValueMultipler += 2*valuesCountsLen + 4 } else { size += valueOverheads + entityValueMultipler += 1 } if datum.Unit != nil { size += unitOverheads } + if entityPresent { + entityPrefixMultiplier := 1 + // timestamp + 2*len(datum.Dimensions) + // dimensions + 1 + // metric name + 1 + // storage resolution + entityValueMultipler + // values + 1 // unit + size += entityPrefixMultiplier * entityMetricDataPrefixOverhead + } + return size } diff --git a/plugins/outputs/cloudwatch/util_test.go b/plugins/outputs/cloudwatch/util_test.go index 334d1dcf02..985de5d0bc 100644 --- a/plugins/outputs/cloudwatch/util_test.go +++ b/plugins/outputs/cloudwatch/util_test.go @@ -118,7 +118,7 @@ func TestPayload_ValuesAndCounts(t *testing.T) { datum.SetStorageResolution(1) datum.SetTimestamp(time.Now()) datum.SetUnit("None") - assert.Equal(t, 867, payload(datum)) + assert.Equal(t, 867, payload(datum, false)) } func TestPayload_Value(t *testing.T) { @@ -131,7 +131,7 @@ func TestPayload_Value(t *testing.T) { datum.SetStorageResolution(1) datum.SetTimestamp(time.Now()) datum.SetUnit("None") - assert.Equal(t, 356, payload(datum)) + assert.Equal(t, 356, payload(datum, false)) } func TestPayload_Min(t *testing.T) { @@ -139,7 +139,7 @@ func TestPayload_Min(t *testing.T) { datum.SetValue(1.23456789) datum.SetMetricName("MetricName") datum.SetTimestamp(time.Now()) - assert.Equal(t, 148, payload(datum)) + assert.Equal(t, 148, payload(datum, false)) } func TestCalculateEntitySize(t *testing.T) {