vavavr00m / boto

Automatically exported from code.google.com/p/boto
1 stars 0 forks source link

CloudWatchConnection.put_metric_data : dimension value overwrites passed in value #553

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. import boto
2. cw = boto.connect_cloudwatch()
3. cw.put_metric_data(namespace='TEST', name='Received', 
dimensions={'channel':'channelA'}, value=1)

What is the expected output? What do you see instead?
The expected query string is:

Action=PutMetricData&MetricData.member.1.Dimensions.member.1.Name=channel&Metric
Data.member.1.Dimensions.member.1.Value=channelA&MetricData.member.1.MetricName=
Received&MetricData.member.1.Value=1&Namespace=TEST&SignatureMethod=HmacSHA256&S
ignatureVersion=2&Timestamp=2011-08-30T18%3A55%3A13Z&Version=2010-08-01 

with a True result

The actual query string is:
Action=PutMetricData&MetricData.member.1.Dimensions.member.1.Name=channel&Metric
Data.member.1.Dimensions.member.1.Value=channelA&MetricData.member.1.MetricName=
Received&MetricData.member.1.Value=channelA&Namespace=TEST&SignatureMethod=HmacS
HA256&SignatureVersion=2&Timestamp=2011-08-30T18%3A51%3A56Z&Version=2010-08-01

NOTE: MetricData.member.1.Value="channelA" instead of "1"

with an Error result
<ErrorResponse xmlns="http://monitoring.amazonaws.com/doc/2010-08-01/">
  <Error>
    <Type>Sender</Type>
    <Code>MalformedInput</Code>
  </Error>
  <RequestId>792b4473-d339-11e0-8b6e-d1d527db6fde</RequestId>
</ErrorResponse>

What version of the product are you using? On what operating system?

boto==2.0rc1 on Ubuntu 10.04

Please provide any additional information below.

I believe the error is at boto/ec2/cloudwatch/__init__.py line 337:

if dimensions:
    for i, (name, value) in enumerate(dimensions.iteritems(), 1):
        metric_data['Dimensions.member.%d.Name' % i] = name
        metric_data['Dimensions.member.%d.Value' % i] = value

NOTE: the "value" assignment in the for statement overwrites the method 
parameter "value", which has the effect of leaving the "value" parameter with 
the value of the last dimension.

I was able to fix the problem locally by changing the names assigned in the 
enumeration to something unique:

if dimensions:
    for i, (dimname, dimvalue) in enumerate(dimensions.iteritems(), 1):
        metric_data['dimensions.member.%d.name' % i] = dimname
        metric_data['dimensions.member.%d.value' % i] = dimvalue

Original issue reported on code.google.com by la...@absolutesw.com on 30 Aug 2011 at 7:14

GoogleCodeExporter commented 9 years ago
I am in the process of fixing a number of issues with the cloudwatch module.  
This is one of them.  I should be finished up by the end of the week, at the 
latest.  Thanks for the report

Original comment by Mitch.Ga...@gmail.com on 21 Sep 2011 at 2:05