Replace broken BBMs and add config validations
What does this MR do and why?
- Makes the changed BBMs a "no-op" due to a bug from using
to_jsonto convert jsonb columns:-
to_jsonwas called on the data before saving, causing it to be saved as a literal string (which is valid JSON) instead of an object.
-
- Creates new BBMs that are 1:1 copies of the older code, outside of the
.to_jsonchange. As suggested from Slack: https://gitlab.slack.com/archives/C3NBYFJ6N/p1743613558709539 - Adds a validation step to the model concern for
configbeing a hash
References
**Old original MRs: **
- !184058 (merged)
- !184039 (merged)
- !184035 (merged)
- !183044 (merged)
- !183043 (merged)
- !183042 (merged)
Screenshots or screen recordings
For checking the diffs between the current migration and the new migrations:
# 1. Amazon Instance
diff -u <(git show origin/master:ee/lib/ee/gitlab/background_migration/backfill_amazon_instance_audit_event_destinations.rb | grep -A 10 "def build_config") \
<(grep -A 10 "def build_config" ee/lib/ee/gitlab/background_migration/backfill_amazon_instance_audit_event_destinations_fixed.rb)
# 2. Amazon Group
diff -u <(git show origin/master:ee/lib/ee/gitlab/background_migration/backfill_amazon_group_audit_event_destinations.rb | grep -A 10 "def build_config") \
<(grep -A 10 "def build_config" ee/lib/ee/gitlab/background_migration/backfill_amazon_group_audit_event_destinations_fixed.rb)
# 3. External Instance
diff -u <(git show origin/master:ee/lib/ee/gitlab/background_migration/backfill_external_instance_audit_event_destinations.rb | grep -A 10 "def build_config") \
<(grep -A 10 "def build_config" ee/lib/ee/gitlab/background_migration/backfill_external_instance_audit_event_destinations_fixed.rb)
# 4. External Group
diff -u <(git show origin/master:ee/lib/ee/gitlab/background_migration/backfill_external_group_audit_event_destinations.rb | grep -A 10 "def build_config") \
<(grep -A 10 "def build_config" ee/lib/ee/gitlab/background_migration/backfill_external_group_audit_event_destinations_fixed.rb)
# 5. Google Instance
diff -u <(git show origin/master:ee/lib/ee/gitlab/background_migration/backfill_google_instance_audit_event_destinations.rb | grep -A 10 "def build_config") \
<(grep -A 10 "def build_config" ee/lib/ee/gitlab/background_migration/backfill_google_instance_audit_event_destinations_fixed.rb)
# 6. Google Group
diff -u <(git show origin/master:ee/lib/ee/gitlab/background_migration/backfill_google_group_audit_event_destinations.rb | grep -A 10 "def build_config") \
<(grep -A 10 "def build_config" ee/lib/ee/gitlab/background_migration/backfill_google_group_audit_event_destinations_fixed.rb)
How to set up and validate locally
Validating our config changes:
ActiveRecord::Base.logger = nil
normal_dest = AuditEvents::Group::ExternalStreamingDestination.new(
group_id: Group.first.id,
category: 'http',
config: { url: FFaker::Internet.unique.http_url },
secret_token: SecureRandom.hex(8)
)
normal_dest.valid?
normal_dest.config.class
normal_dest.save!
string_dest = AuditEvents::Group::ExternalStreamingDestination.new(
group_id: Group.first.id,
category: 'http',
config: '{"url":"https://test.example.com"}',
secret_token: SecureRandom.hex(8)
)
string_dest.valid?
string_dest.config.class
string_dest.save!
problematic = AuditEvents::Group::ExternalStreamingDestination.new(
group_id: Group.first.id,
category: 'http',
name: 'Test String Config',
secret_token: SecureRandom.hex(8)
)
problematic.send(:write_attribute, :config, '{"url":"https://example.com"}')
problematic.save(validate: false)
problematic_id = problematic.id
problematic = AuditEvents::Group::ExternalStreamingDestination.find(problematic_id)
puts "Config class: #{problematic.config.class}"
puts "Config URL: #{problematic.config['url']}"
problematic.name = "Updated Name"
puts "Valid after name change? #{problematic.valid?}"
problematic.save!
puts "Save successful? #{problematic.persisted? && !problematic.changed?}"
raw_value = problematic.attributes_before_type_cast["config"]
puts "Raw stored config type: #{raw_value.class}"
puts "Raw stored config: #{raw_value}"
problematic.config = { url: 'https://updated-example.com' }
puts "Valid after config update? #{problematic.valid?}"
problematic.save!
reloaded = AuditEvents::Group::ExternalStreamingDestination.find(problematic_id)
puts "Updated config URL: #{reloaded.config['url']}"
Edited by Brian Williams