diff --git a/CHANGELOG.md b/CHANGELOG.md index 47e091f..8d1a00c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,18 +4,30 @@ Change Log All notable changes to this project are noted in this file. This project adheres to [Semantic Versioning](http://semver.org/). +0.4.1 +----- + +- Fixed issue (https://github.com/blue-yonder/azure-cost-mon/issues/12) + where the sum of multiple time series was numerically instable by + emitting only integer values. The instability resulted in more counter + resets within Prometheus than necessary, so that `increase` gave wrong + results! + + 0.4.0 ----- - Use the `X-Prometheus-Scrape-Timeout-Seconds` header sent by prometheus to overwrite the internal request timeout default. + 0.3.1 ----- - Fixed the exporter to cope with the non-standard response for months without usage details. + 0.3.0 ----- diff --git a/azure_costs_exporter/prometheus_collector.py b/azure_costs_exporter/prometheus_collector.py index 927c48e..c728c82 100644 --- a/azure_costs_exporter/prometheus_collector.py +++ b/azure_costs_exporter/prometheus_collector.py @@ -106,6 +106,6 @@ def collect(self): groups = df.groupby(base_columns).sum() for name, value in groups.iterrows(): - c.add_metric(name, value.ExtendedCost) + c.add_metric(name, int(round(value.ExtendedCost))) yield c diff --git a/tests/data.py b/tests/data.py index 113de08..c3b8ec1 100644 --- a/tests/data.py +++ b/tests/data.py @@ -11,7 +11,7 @@ u'Date': u'03/01/2017', u'Day': 1, u'DepartmentName': u'Engineering', - u'ExtendedCost': 0.71, + u'ExtendedCost': 0.499222332425423563466, u'InstanceId': u'platform-vnet', u'MeterCategory': u'Virtual Network', u'MeterId': u'c90286c8-adf0-438e-a257-4468387df385', @@ -42,7 +42,7 @@ u'Date': u'03/01/2017', u'Day': 1, u'DepartmentName': u'Engineering', - u'ExtendedCost': 0.24, + u'ExtendedCost': 0.50000011123124314235234522345, u'InstanceId': u'/subscriptions/abc3455ac-3feg-2b3c5-abe4-ec1111111e6/resourceGroups/my-group/providers/Microsoft.Storage/storageAccounts/ss7q3264domxo', u'MeterCategory': u'Windows Azure Storage', u'MeterId': u'd23a5753-ff85-4ddf-af28-8cc5cf2d3882', diff --git a/tests/test_collector.py b/tests/test_collector.py index 6b4439f..166e829 100644 --- a/tests/test_collector.py +++ b/tests/test_collector.py @@ -57,8 +57,8 @@ def test_extract_metrics(api_url, enrollment): result = generate_latest(registry).decode('utf8').split('\n') assert len(result) == 5 - expected_0 = 'costs{AccountName="platform",DepartmentName="engineering",MeterCategory="virtual network",MeterName="hours",MeterSubCategory="gateway hour",ResourceGroup="",SubscriptionName="production"} 0.71' - expected_1 = 'costs{AccountName="platform",DepartmentName="engineering",MeterCategory="windows azure storage",MeterName="standard io - page blob/disk (gb)",MeterSubCategory="locally redundant",ResourceGroup="my-group",SubscriptionName="production"} 0.24' + expected_0 = 'costs{AccountName="platform",DepartmentName="engineering",MeterCategory="virtual network",MeterName="hours",MeterSubCategory="gateway hour",ResourceGroup="",SubscriptionName="production"} 0.0' + expected_1 = 'costs{AccountName="platform",DepartmentName="engineering",MeterCategory="windows azure storage",MeterName="standard io - page blob/disk (gb)",MeterSubCategory="locally redundant",ResourceGroup="my-group",SubscriptionName="production"} 1.0' assert result[2] == expected_0 assert result[3] == expected_1