Skip to content

Commit 94a7234

Browse files
authored
feat(dx_maint): sort output by start time of event (#38)
Previously the output was sorted by the date the event was published because AWS does not always provide a start time in events (I have no idea why). But for a series of maintenance events, sorting by the start time of the event makes more sense. In the event that AWS does not provide a start time, then we fallback to the time the event was published.
1 parent ef330e8 commit 94a7234

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/awsrun/commands/aws/dx_maint.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@
88
## Overview
99
1010
The dx_maint command displays a summary of Direct Connect maintenance events
11-
available from the AWS Health service sorted by the time AWS published the
12-
event, which is not necessarily the start of maintenance. Only recent events
13-
(past 7 days) and upcoming events are displayed by default.
11+
available from the AWS Health service sorted by the start time of the event.
12+
Only recent events (past 7 days) and upcoming events are displayed by default.
13+
The output includes the time the event was published (first date column), the
14+
start time of the event (second date column), and the end time of the event
15+
(last date column).
1416
1517
$ awsrun --account 111222333444 --account 222111444333 dx_maint --region us-east-1 --region us-west-2
1618
111222333444 us-east-1 2021-11-19 09:11 CST closed MAINTENANCE_CANCELLED 2021-11-23 02:11 CST -> 2021-11-23 06:11 CST dxcon-aaaaaaaa available
1719
111222333444 us-west-2 2021-12-07 05:12 CST closed MAINTENANCE_COMPLETE 2021-12-07 03:12 CST -> 2021-12-07 07:12 CST dxcon-bbbbbbbb available
1820
111222333444 us-east-1 2022-01-18 02:01 CST closed MAINTENANCE_COMPLETE 2022-01-17 22:01 CST -> 2022-01-18 02:01 CST dxcon-cccccccc available
19-
222111444333 us-east-1 2022-01-31 21:01 CST upcoming MAINTENANCE_SCHEDULED 2022-02-14 22:02 CST -> 2022-02-15 02:02 CST dxcon-dddddddd available
2021
111222333444 us-east-1 2022-02-01 21:02 CST upcoming MAINTENANCE_SCHEDULED 2022-02-08 22:02 CST -> 2022-02-09 02:02 CST dxcon-eeeeeeee available
22+
222111444333 us-east-1 2022-01-31 21:01 CST upcoming MAINTENANCE_SCHEDULED 2022-02-14 22:02 CST -> 2022-02-15 02:02 CST dxcon-dddddddd available
2123
2224
For non-emergency maintenance events that occurred in the past, the default
2325
output only shows the COMPLETED or CANCELLED event to minimize on noise. For
@@ -268,12 +270,15 @@ def regional_collect_results(self, acct, region, get_result):
268270
def post_hook(self):
269271
# The awsrun post hook is called once after all accounts have been
270272
# processed. At this point, we have collected everything we need in the
271-
# all_results instance variable. We sort this list by the last update
272-
# time as we want to display the maintenance events in the order they
273-
# were published by AWS. You might ask why don't we sort by the
274-
# maintenance start time? Because AWS sometimes does not publish a
275-
# start time for an event (I have no idea why).
276-
self.all_results.sort(key=lambda r: r[3]["lastUpdatedTime"])
273+
# all_results instance variable. We sort this list by start time when
274+
# possible, but the AWS API doesn't always send a startTime, so we
275+
# fallback to the lastUpdatedTime, which seems to always be present.
276+
self.all_results.sort(
277+
key=lambda r: (
278+
r[3].get("startTime", r[3]["lastUpdatedTime"]),
279+
r[3]["lastUpdatedTime"],
280+
)
281+
)
277282

278283
for acct, region, dx, event in self.all_results:
279284
for color, field in (

0 commit comments

Comments
 (0)