Merge pull request #1616 from barryoneill/bugfix/1615-cloudwatch-statistics

Issue 1615 - missing Value should not kill put_metric_data
This commit is contained in:
Steve Pulec 2018-05-29 22:19:41 -04:00 committed by GitHub
commit f612d21129
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 1 deletions

View File

@ -235,7 +235,7 @@ class CloudWatchBackend(BaseBackend):
timestamp = datetime.strptime(timestamp, '%Y-%m-%dT%H:%M:%S.%fZ')
timestamp = timestamp.replace(tzinfo=tzutc())
self.metric_data.append(MetricDatum(
namespace, metric_member['MetricName'], float(metric_member['Value']), metric_member.get('Dimensions.member', _EMPTY_LIST), timestamp))
namespace, metric_member['MetricName'], float(metric_member.get('Value', 0)), metric_member.get('Dimensions.member', _EMPTY_LIST), timestamp))
def get_metric_statistics(self, namespace, metric_name, start_time, end_time, period, stats):
period_delta = timedelta(seconds=period)

31
tests/test_cloudwatch/test_cloudwatch_boto3.py Normal file → Executable file
View File

@ -162,6 +162,37 @@ def test_put_metric_data_no_dimensions():
metric['MetricName'].should.equal('metric')
@mock_cloudwatch
def test_put_metric_data_with_statistics():
conn = boto3.client('cloudwatch', region_name='us-east-1')
conn.put_metric_data(
Namespace='tester',
MetricData=[
dict(
MetricName='statmetric',
Timestamp=datetime(2015, 1, 1),
# no Value to test https://github.com/spulec/moto/issues/1615
StatisticValues=dict(
SampleCount=123.0,
Sum=123.0,
Minimum=123.0,
Maximum=123.0
),
Unit='Milliseconds',
StorageResolution=123
)
]
)
metrics = conn.list_metrics()['Metrics']
metrics.should.have.length_of(1)
metric = metrics[0]
metric['Namespace'].should.equal('tester')
metric['MetricName'].should.equal('statmetric')
# TODO: test statistics - https://github.com/spulec/moto/issues/1615
@mock_cloudwatch
def test_get_metric_statistics():
conn = boto3.client('cloudwatch', region_name='us-east-1')