Fix cloudwatch list metrics localstack #5000 (#4732)

This commit is contained in:
Ranjithkumar Krishnan 2021-12-31 16:55:48 +01:00 committed by GitHub
parent d2ca16cab5
commit 3f79f7f6c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 3 deletions

View File

@ -220,9 +220,14 @@ class MetricDatum(BaseModel):
return False
for metric in already_present_metrics or []:
if self.dimensions and are_dimensions_same(
metric.dimensions, self.dimensions
):
if (
(
self.dimensions
and are_dimensions_same(metric.dimensions, self.dimensions)
)
and self.name == metric.name
and self.namespace == metric.namespace
): # should be considered as already present only when name, namespace and dimensions all three are same
return False
if dimensions and any(

View File

@ -400,6 +400,53 @@ def test_list_metrics_without_value():
results[0]["Dimensions"].should.equal([{"Name": "D1", "Value": "V1"}])
@mock_cloudwatch
def test_list_metrics_with_same_dimensions_different_metric_name():
cloudwatch = boto3.client("cloudwatch", "eu-west-1")
# create metrics with same namespace and dimensions but different metric names
cloudwatch.put_metric_data(
Namespace="unique/",
MetricData=[
{
"MetricName": "metric1",
"Dimensions": [{"Name": "D1", "Value": "V1"}],
"Unit": "Seconds",
}
],
)
cloudwatch.put_metric_data(
Namespace="unique/",
MetricData=[
{
"MetricName": "metric2",
"Dimensions": [{"Name": "D1", "Value": "V1"}],
"Unit": "Seconds",
}
],
)
results = cloudwatch.list_metrics()["Metrics"]
results.should.have.length_of(2)
# duplicating existing metric
cloudwatch.put_metric_data(
Namespace="unique/",
MetricData=[
{
"MetricName": "metric1",
"Dimensions": [{"Name": "D1", "Value": "V1"}],
"Unit": "Seconds",
}
],
)
# asserting only unique values are returned
results = cloudwatch.list_metrics()["Metrics"]
results.should.have.length_of(2)
def create_metrics(cloudwatch, namespace, metrics=5, data_points=5):
for i in range(0, metrics):
metric_name = "metric" + str(i)