# Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. import re import sys import time import itertools import collections import dateutil.parser from flatten_dict import flatten from collections import defaultdict cwlogs_query_limit = 4 def obtain_raw_logs(test_details, cloudwatch_logs): # query cw logs to get the raw logs during the period the step functions workflow was running # cw logs limits the number of concurrent queries, so the number of running queries always needs to be lower or equal cwlogs_query_limit # filter queries that are currently running (query metadata is added to the cwlogs_query in the test details once they are submitted) incomplete_query_results_iter = lambda: filter(lambda x: 'cwlogs_query' in x and ('cwlogs_query_result' not in x or x['cwlogs_query_result']['status'] == 'Running'), test_details) # print summary of running, completed, and failed queries output_statistics = lambda: print("query status:", dict(collections.Counter(map(lambda x: x['cwlogs_query_result']['status'] if 'cwlogs_query_result' in x else 'Pending', test_details)))) # populate queue with all queries that need to be executed queue = test_details.copy() cwlogs_query_capacity = cwlogs_query_limit output_statistics() # while there are queries to run and we can still run queries while len(queue)>0 or cwlogs_query_capacity