Skip to content

Commit

Permalink
Revert more changes
Browse files Browse the repository at this point in the history
  • Loading branch information
varunch77 committed Jan 27, 2025
1 parent a66a13f commit 7b72bd4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
19 changes: 12 additions & 7 deletions plugins/outputs/cloudwatch/cloudwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,20 @@ func (c *CloudWatch) pushMetricDatum() {
case metric := <-c.metricChan:
entity, datums := c.BuildMetricDatum(metric)
numberOfPartitions := len(datums)
entityStr := entityToString(entity)
entityPresent := false
if entityStr != "" {
c.metricDatumBatch.Size += calculateEntitySize(entity)
entityPresent = true
}
// 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 accomodate this decision

// Otherwise to include entity size you would do something like this:
// entityPresent := false
// if entityStr != "" {
// c.metricDatumBatch.Size += calculateEntitySize(entity)
// entityPresent = true
// }
for i := 0; i < numberOfPartitions; i++ {
entityStr := entityToString(entity)
c.metricDatumBatch.Partition[entityStr] = append(c.metricDatumBatch.Partition[entityStr], datums[i])
c.metricDatumBatch.Size += payload(datums[i], entityPresent)
c.metricDatumBatch.Size += payload(datums[i]) // possibly need to pass a variable indicating whether this metric has an entity attached - depends on how the sdk protocol changes

Check failure on line 190 in plugins/outputs/cloudwatch/cloudwatch.go

View workflow job for this annotation

GitHub Actions / Check lint

not enough arguments in call to payload

Check failure on line 190 in plugins/outputs/cloudwatch/cloudwatch.go

View workflow job for this annotation

GitHub Actions / Check lint

not enough arguments in call to payload
c.metricDatumBatch.Count++
if c.metricDatumBatch.isFull() {
// if batch is full
Expand Down
8 changes: 4 additions & 4 deletions plugins/outputs/cloudwatch/cloudwatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ func TestConsumeMetrics(t *testing.T) {
cloudWatchOutput.publisher, _ = publisher.NewPublisher(
publisher.NewNonBlockingFifoQueue(10), 10, 2*time.Second,
cloudWatchOutput.WriteToCloudWatch)
metrics := makeMetrics(1200)
metrics := makeMetrics(1500)
cloudWatchOutput.Write(metrics)
time.Sleep(2*time.Second + 2*cloudWatchOutput.config.ForceFlushInterval)
svc.On("PutMetricData", mock.Anything).Return(&res, nil)
Expand All @@ -438,8 +438,8 @@ func TestConsumeMetrics(t *testing.T) {
10,
2*time.Second,
cw.WriteToCloudWatch)
// Expect 1200 metrics batched in 2 API calls.
pmetrics := createTestMetrics(1200, 1, 1, "B/s")
// Expect 1500 metrics batched in 2 API calls.
pmetrics := createTestMetrics(1500, 1, 1, "B/s")
ctx := context.Background()
cw.ConsumeMetrics(ctx, pmetrics)
time.Sleep(2*time.Second + 2*cw.config.ForceFlushInterval)
Expand Down Expand Up @@ -485,7 +485,7 @@ func TestPublish(t *testing.T) {
interval := 60 * time.Second
// The buffer holds 50 batches of 1,000 metrics. So choose 5x.
numMetrics := 5 * datumBatchChanBufferSize * defaultMaxDatumsPerCall
expectedCalls := 395 // Updated to match the observed number of calls
expectedCalls := numMetrics / defaultMaxDatumsPerCall
log.Printf("I! interval %v, numMetrics %v, expectedCalls %v",
interval, numMetrics, expectedCalls)
cw := newCloudWatchClient(svc, interval)
Expand Down
18 changes: 10 additions & 8 deletions plugins/outputs/cloudwatch/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ const (
statisticsSize = 246
// &MetricData.member.100.Timestamp=2018-05-29T21%3A14%3A00Z
timestampSize = 57
// &StrictEntityValidation=false
strictEntityValidationSize = 29

overallConstPerRequestSize = pmdActionSize + versionSize
// &Namespace=, this is per request
Expand All @@ -48,12 +46,16 @@ const (
valueOverheads = 47
// &MetricData.member.1.Unit=Kilobytes/Second
unitOverheads = 42
// &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

// Entity overheads
// // &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.
Expand Down

0 comments on commit 7b72bd4

Please sign in to comment.