Skip to content

Commit

Permalink
Update statistics handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ellation-mchau committed Jul 20, 2018
1 parent ed382aa commit 85d75c8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
16 changes: 7 additions & 9 deletions ses_account_monitor/services/cloudwatch_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
timedelta,
timezone)

from decimal import Decimal

import boto3

from ses_account_monitor.config import (
Expand Down Expand Up @@ -92,7 +94,7 @@ def get_last_metric(metric):

last_ts = max(metric['Timestamps'])
last_index = metric['Timestamps'].index(last_ts)
last_value = metric['Values'][last_index]
last_value = float(Decimal(str(metric['Values'][last_index])) * 100)

return (metric['Label'], last_value, last_ts.astimezone(timezone.utc).isoformat())

Expand Down Expand Up @@ -156,10 +158,8 @@ def get_ses_account_reputation_metrics(self, target_datetime=None, period=None,
Returns:
list (tuple): Returns a list of tuples, representing the reputation metrics.
label (str): Name of the metric, taken from the CloudWatch metric results data label.
value (float): The value of the metric, will already be in percentage form.
threshold (float): The threshold percentage.
metric_ts (str): ISO 8601 timestamp.
[(label, value, threshold, iso8601_timestamp), ...]
'''

if metric_timedelta is None:
Expand Down Expand Up @@ -277,10 +277,8 @@ def build_ses_account_reputation_metrics(self, metric_data):
Returns:
list (tuple): Returns a list of tuples, representing the reputation metrics.
label (str): Name of the metric, taken from the CloudWatch metric results data label.
value (float): The value of the metric, will already be in percentage form.
threshold (float): The threshold percentage.
metric_ts (str): ISO 8601 timestamp.
[(label, value, threshold, iso8601_timestamp), ...]
'''

thresholds = self.ses_thresholds
Expand Down
10 changes: 5 additions & 5 deletions test/services/test_cloudwatch_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def metric_data_results_response(end_datetime):
end_datetime
],
'Values': [
0.00001
0.0000001
]
}
],
Expand Down Expand Up @@ -100,7 +100,7 @@ def metric_data_results(current_datetime):
{'Id': 'complaint_rate',
'Label': 'Complaint Rate',
'Timestamps': [current_datetime],
'Values': [0.00001]}]
'Values': [0.0000001]}]


@pytest.fixture
Expand Down Expand Up @@ -136,10 +136,10 @@ def test_get_ses_account_reputation_metric_data_results(client,


def test_build_ses_account_reputation_metrics(service, build_metric_data_results):
metric_data_results = build_metric_data_results(5.0, 0.1)
metric_data_results = build_metric_data_results(0.05, 0.1)
result = service.build_ses_account_reputation_metrics(metric_data_results)

assert result.critical == [('Complaint Rate', 0.1, 0.04, '2018-06-17T02:11:25.787402+00:00')]
assert result.critical == [('Complaint Rate', 10.0, 0.04, '2018-06-17T02:11:25.787402+00:00')]
assert result.ok == []
assert result.warning == [('Bounce Rate', 5.0, 5.0, '2018-06-17T02:11:25.787402+00:00')]

Expand All @@ -158,6 +158,6 @@ def test_get_ses_account_reputation_metrics(client,
with stubber:
result = service.get_ses_account_reputation_metrics(target_datetime=end_datetime)
assert result.critical == []
assert result.ok == [('Bounce Rate', 0.03, 5.0, '2018-06-17T02:11:25.787402+00:00'),
assert result.ok == [('Bounce Rate', 3.0, 5.0, '2018-06-17T02:11:25.787402+00:00'),
('Complaint Rate', 0.00001, 0.01, '2018-06-17T02:11:25.787402+00:00')]
assert result.warning == []
6 changes: 3 additions & 3 deletions test/test_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def metric_data_results_response_critical(end_datetime):
end_datetime,
],
'Values': [
5.0
0.05
],
'StatusCode': 'Complete',
},
Expand All @@ -107,7 +107,7 @@ def metric_data_results_response_critical(end_datetime):
end_datetime
],
'Values': [
99.0
0.99
]
}
],
Expand All @@ -126,7 +126,7 @@ def metric_data_results_response_warning(end_datetime):
end_datetime,
],
'Values': [
5.23994
0.0523994
],
'StatusCode': 'Complete',
},
Expand Down

0 comments on commit 85d75c8

Please sign in to comment.