Skip to content

Database migration and models for instance event type filters

Hitesh Raghuvanshi requested to merge 411524-event-filter-migration-1 into master

What does this MR do and why?

We have added instance level external audit event destinations as part of issue #335175 (closed). Now we need to add audit event filters for these destinations which will allow users to add filters for the audit events for each external destination, restricting streaming of certain audit event types to a certain destination. These event filters are similar to the event filters for group level external audit event streaming destinations.

This MR does following:

  1. Adds a migration for creating table audit_events_streaming_event_type_filters.
  2. Adds a corresponding model InstanceEventTypeFilter for the table.
  3. Since some things are common between EventTypeFilter and InstanceEventTypeFilter, we have added a concern StreamableEventTypeFilter for having common validations and methods.

Note: GraphQL APIs for performing CRUD operations and changes related to destination model will be added in a subsequent MR.

Migration details:

up

RAILS_ENV=development bin/rails db:migrate:up:main VERSION=20230609115844
main: == [advisory_lock_connection] object_id: 227840, pg_backend_pid: 43679
main: == 20230609115844 CreateAuditEventsStreamingInstanceEventTypeFilters: migrating
main: -- create_table(:audit_events_streaming_instance_event_type_filters)
main: -- quote_column_name(:audit_event_type)
main:    -> 0.0000s
main:    -> 0.0069s
main: == 20230609115844 CreateAuditEventsStreamingInstanceEventTypeFilters: migrated (0.1260s)

main: == [advisory_lock_connection] object_id: 227840, pg_backend_pid: 43679

down

RAILS_ENV=development bin/rails db:migrate:down:main VERSION=20230609115844
main: == [advisory_lock_connection] object_id: 227900, pg_backend_pid: 43245
main: == 20230609115844 CreateAuditEventsStreamingInstanceEventTypeFilters: reverting
main: -- drop_table(:audit_events_streaming_instance_event_type_filters)
main:    -> 0.0068s
main: == 20230609115844 CreateAuditEventsStreamingInstanceEventTypeFilters: reverted (0.0931s)

Queries

Query for scope audit_event_type_in

SELECT 
  "audit_events_streaming_instance_event_type_filters".* 
FROM 
  "audit_events_streaming_instance_event_type_filters" 
WHERE 
  "audit_events_streaming_instance_event_type_filters"."audit_event_type" = 'audit-event-type-1'

How to set up and validate locally

Since there are no functional changes in this MR, there is nothing to validate apart from running the migration and checking the model in the rails console. There will be subsequent MRs related to APIs around the new table/model added.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #411524 (closed)

Edited by Hitesh Raghuvanshi

Merge request reports