Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/reporting/cloudwatch_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,19 @@ def fetch_one(query:, start_time:, end_time:)
).query_id

wait_for_query_result(query_id)
rescue Aws::CloudWatchLogs::Errors::InvalidParameterException => err
# rubocop:disable Layout/LineLength, Rails/TimeZone
rescue Aws::CloudWatchLogs::Errors::InvalidParameterException, Aws::CloudWatchLogs::Errors::MalformedQueryException => err
if err.message.match?(/End time should not be before the service was generally available/)
# rubocop:disable Layout/LineLength, Rails/TimeZone
log(:warn, "query end_time=#{end_time} (#{Time.at(end_time)}) is before Cloudwatch Insights availability, skipping")
# rubocop:enable Layout/LineLength, Rails/TimeZone
Aws::CloudWatchLogs::Types::GetQueryResultsResponse.new(results: [])
elsif err.message.match?(/end date and time is either before the log groups creation time or exceeds the log groups log retention settings/)
log(:warn, "query end_time=#{end_time} (#{Time.at(end_time)}) is before the log groups creation time or exceeds the log groups log retention settings")
Aws::CloudWatchLogs::Types::GetQueryResultsResponse.new(results: [])
else
raise err
end
end
# rubocop:enable Layout/LineLength, Rails/TimeZone

def ensure_complete_logs?
@ensure_complete_logs
Expand Down
5 changes: 0 additions & 5 deletions lib/reporting/monthly_proofing_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ def proofing_report
end

csv
rescue Aws::CloudWatchLogs::Errors::MalformedQueryException => error
[
['Error', 'Message'],
[error.class.name, error.message],
]
end

def as_csv
Expand Down
23 changes: 23 additions & 0 deletions spec/lib/reporting/cloudwatch_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,5 +244,28 @@ def stub_single_page
expect(logger_io.string).to include('is before Cloudwatch Insights availability')
end
end

context 'when the query is outside the log retention range' do
before do
# rubocop:disable Layout/LineLength
Aws.config[:cloudwatchlogs] = {
stub_responses: {
start_query: Aws::CloudWatchLogs::Errors::MalformedQueryException.new(
nil,
'end date and time is either before the log groups creation time or exceeds the log groups log retention settings',
),
},
}
# rubocop:enable Layout/LineLength

allow(Time).to receive(:zone).and_return(nil)
end

it 'logs a warning and returns an empty array for that range' do
expect(fetch).to eq([])

expect(logger_io.string).to include('exceeds the log groups log retention settings')
end
end
end
end
22 changes: 0 additions & 22 deletions spec/lib/reporting/monthly_proofing_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,6 @@
end
end

describe '#proofing_report' do
context 'when the data is outside the log retention range' do
before do
allow(report.cloudwatch_client).to receive(:fetch).and_raise(
Aws::CloudWatchLogs::Errors::MalformedQueryException.new(
nil,
'exceeds the log groups log retention settings',
),
)
end

it 'handles the error and returns a table with information on the error' do
expect(report.proofing_report).to match(
[
['Error', 'Message'],
['Aws::CloudWatchLogs::Errors::MalformedQueryException', kind_of(String)],
],
)
end
end
end

describe '#data' do
it 'keeps unique users per event as a hash' do
expect(report.data).to eq(
Expand Down