max date on the audit log fix up
fixes: CNVS-16213 Sets a max date on the audit log data fixup so it does not have to run records that were created after the bug was fixed. Set it to the 20th of August to give us a buffer and that was when the audit logs were reenabled. Test Plan: - Create a corrupted login event using the script below. - Run the fixup (Command in script below). - Should skip records after the 20th (see output from script ids to which is which). Setup test plan: target_user = User.find(...) target_pseudonym = target_user.pseudonyms.first event_type = 'login' # Records Before record1 = Auditors::Authentication::Record.generate(target_pseudonym, event_type) record1.attributes['created_at'] = Date.new(2014, 8, 20).to_time Auditors::Authentication::Stream.insert(record1) record2 = Auditors::Authentication::Record.generate(target_pseudonym, event_type) record2.attributes['id'] = record1.id record2.attributes['created_at'] = Date.new(2014, 8, 21).to_time Auditors::Authentication::Stream.insert(record2) # Records After record3= Auditors::Authentication::Record.generate(target_pseudonym, event_type) record3.attributes['created_at'] = Date.new(2014, 8, 21).to_time Auditors::Authentication::Stream.insert(record3) record4 = Auditors::Authentication::Record.generate(target_pseudonym, event_type) record4.attributes['id'] = record3.id record4.attributes['created_at'] = Date.new(2014, 8, 22).to_time Auditors::Authentication::Stream.insert(record4) puts "Id should be fixed: #{record1.id}." puts "Id should NOT be fixed: #{record3.id}." # Run Fixup DataFixup::FixAuditLogUuidIndexes::Migration::run Change-Id: Ic57fe4da0ecedba9f45670dca08e5b279b601086 Reviewed-on: https://gerrit.instructure.com/42605 Reviewed-by: Jacob Fugal <jacob@instructure.com> QA-Review: Jeremy Putnam <jeremyp@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> Product-Review: Nick Cloward <ncloward@instructure.com>
This commit is contained in:
parent
9c9d01dc95
commit
535046bc42
|
@ -169,6 +169,11 @@ module DataFixup
|
|||
@start_time ||= Time.new(2014, 6, 14)
|
||||
end
|
||||
|
||||
# The date the audit logs were enabled.
|
||||
def end_time
|
||||
@end_time ||= Time.new(2014, 8, 20)
|
||||
end
|
||||
|
||||
def index
|
||||
@index
|
||||
end
|
||||
|
@ -229,11 +234,12 @@ module DataFixup
|
|||
need_tombstone = []
|
||||
updates = []
|
||||
oldest_bucket = index.bucket_for_time(start_time)
|
||||
newest_bucket = index.bucket_for_time(end_time)
|
||||
|
||||
# Check each row to see if we need to update it or inspect it.
|
||||
rows.each do |row|
|
||||
row = format_row(row)
|
||||
next if row['bucket'] < oldest_bucket
|
||||
next if row['bucket'] < oldest_bucket || row['bucket'] > newest_bucket
|
||||
current_id, timestamp, key = extract_row_keys(index, row)
|
||||
actual_id = query_corrected_id(current_id, timestamp)
|
||||
if actual_id.nil?
|
||||
|
|
|
@ -51,6 +51,8 @@ describe DataFixup::FixAuditLogUuidIndexes do
|
|||
# Truncate the mapping and last batch tables.
|
||||
@database.execute("TRUNCATE #{DataFixup::FixAuditLogUuidIndexes::MAPPING_TABLE}")
|
||||
@database.execute("TRUNCATE #{DataFixup::FixAuditLogUuidIndexes::LAST_BATCH_TABLE}")
|
||||
|
||||
DataFixup::FixAuditLogUuidIndexes::IndexCleaner.any_instance.stubs(:end_time).returns(Time.now + 1.month)
|
||||
end
|
||||
|
||||
def check_event_stream(event_id, stream_table, expected_total)
|
||||
|
@ -245,4 +247,21 @@ describe DataFixup::FixAuditLogUuidIndexes do
|
|||
|
||||
expect(events.first.attributes['created_at'].to_i).to eq first_event_at
|
||||
end
|
||||
|
||||
it "should skip records after the bug fix was released" do
|
||||
# Create bad data
|
||||
stream_checks = {}
|
||||
stream_checks['grade_changes'] = corrupt_grade_changes
|
||||
stream_checks['courses'] = corrupt_course_changes
|
||||
stream_checks['authentications'] = corrupt_authentications
|
||||
|
||||
DataFixup::FixAuditLogUuidIndexes::IndexCleaner.any_instance.stubs(:end_time).returns(Time.now - 1.month)
|
||||
|
||||
DataFixup::FixAuditLogUuidIndexes::IndexCleaner.any_instance.expects(:create_tombstone).never
|
||||
DataFixup::FixAuditLogUuidIndexes::IndexCleaner.any_instance.expects(:create_index_entry).never
|
||||
DataFixup::FixAuditLogUuidIndexes::IndexCleaner.any_instance.expects(:delete_index_entry).never
|
||||
|
||||
# Run Fix
|
||||
DataFixup::FixAuditLogUuidIndexes::Migration.run
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue