From 44f7d6f076566505012eae91c1d4ea3c2e3ef531 Mon Sep 17 00:00:00 2001 From: Varun <48163435+varunch77@users.noreply.github.com> Date: Tue, 28 Jan 2025 11:05:01 -0500 Subject: [PATCH] Add comments about updating payload calculations with entity data (#1483) --- .golangci.yml | 2 +- plugins/outputs/cloudwatch/cloudwatch.go | 13 +++++++++++++ plugins/outputs/cloudwatch/util.go | 13 +++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 33fff94918..71da5c3e50 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -19,7 +19,7 @@ run: output: # colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number" - format: colored-line-number + formats: colored-line-number # print lines of code with issue, default is true print-issued-lines: true diff --git a/plugins/outputs/cloudwatch/cloudwatch.go b/plugins/outputs/cloudwatch/cloudwatch.go index 124ff76d22..8acf14db60 100644 --- a/plugins/outputs/cloudwatch/cloudwatch.go +++ b/plugins/outputs/cloudwatch/cloudwatch.go @@ -174,6 +174,19 @@ func (c *CloudWatch) pushMetricDatum() { case metric := <-c.metricChan: entity, datums := c.BuildMetricDatum(metric) numberOfPartitions := len(datums) + /* We currently do not account for entity information as a part of the payload size. + This is by design and should be revisited once the SDK protocol changes. + In the meantime there has been a payload limit increase applied in the background to accommodate this decision + + Otherwise to include entity size you would do something like this: + c.metricDatumBatch.Size += calculateEntitySize(entity) + + In addition to calculating the size of the entity object, you might also need to account for any extra bytes that get + added on an individual metric level when entity data is present (depends on how the sdk protocol changes)—something like: + c.metricDatumBatch.Size += payload(datums[i], entityPresent=true) + + File diff that could be useful: https://github.com/aws/amazon-cloudwatch-agent/compare/af960d7...459ef7c + */ for i := 0; i < numberOfPartitions; i++ { entityStr := entityToString(entity) c.metricDatumBatch.Partition[entityStr] = append(c.metricDatumBatch.Partition[entityStr], datums[i]) diff --git a/plugins/outputs/cloudwatch/util.go b/plugins/outputs/cloudwatch/util.go index 6a2149365c..2f1fec4ba4 100644 --- a/plugins/outputs/cloudwatch/util.go +++ b/plugins/outputs/cloudwatch/util.go @@ -46,6 +46,19 @@ const ( valueOverheads = 47 // &MetricData.member.1.Unit=Kilobytes/Second unitOverheads = 42 + + /* Entity overheads - these would be used to calculate entity size if we decide to include it as a part of the payload. + The three main components are the KeyAttributes key/value pair, Attributes key/value pair, and StrictEntityValidation + + // &StrictEntityValidation=false + strictEntityValidationSize = 29 + // &EntityMetricData.member.100.Entity.KeyAttributes.entry.1.key= &EntityMetricData.member.100.Entity.KeyAttributes.entry.1.value= + entityKeyAttributesOverhead = 62 + 64 + // &EntityMetricData.member.100.Entity.Attributes.entry.1.key= &EntityMetricData.member.100.Entity.Attributes.entry.1.value= + entityAttributesOverhead = 59 + 61 + // EntityMetricData.member.100. + entityMetricDataPrefixOverhead = 28 + */ ) // Set seed once.