[cloudwatch-input] dataQuery generation always returns the same dimension for a metric #10122
Labels
area/aws
AWS plugins including cloudwatch, ecs, kinesis
bug
unexpected problem or unintended behavior
platform/darwin
Relevent telegraf.conf
System info
macOS 12.0.1; go version go1.17.2 darwin/amd64; telegraf 1.20.4 (and master)
Docker
No response
Steps to reproduce
telegraf --config telegraf.conf --input-filter cloudwatch
Expected behavior
I can see the metric
BytesInFromDestination
for each NAT GWActual behavior
The value of the
BytesInFromDestination
metric is the same for all NAT GWAdditional info
I did some digging around and found out that this bug is related to the
getDataQueries
function of theCloudWatch
struct. In there it iterates over allfilteredMetrics
and takes the address of the metric from that list to store it in thedataQueries
map. However since go seems to re-use the same object for every iteration of the loop the pointer that is taken always points to the exact same memory location. Due to this theMetric
field will always contain the same pointer (and therefore value) after the for loop is done. The fix is easy and I will provide it as soon as I am done with this issue: the metric struct needs to be copied once to allocate new memory, after that the address can be taken.This is one of the places where this address-taking is done (line 480):
telegraf/plugins/inputs/cloudwatch/cloudwatch.go
Lines 476 to 484 in 34ad5aa
The weird thing is that this would affect everyone using the plugin and having more then one dimension per metric. Why didn't this show up earlier?
The text was updated successfully, but these errors were encountered: