Create ClickHouse Audit Events Model
Problem Statement
Currently, audit events are loaded into the dashboard using AuditEventFinder
https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/app/finders/audit_event_finder.rb
We want to avoid changing much of the existing finder code, for this, we will require a ClickHouse AuditEvent model which should provide all the filtering methods which are currently provided by audit_event.rb
so that we can reuse filtering logic and just pass on the Model to be filtered
Below scopes of AuditEvent are currently used in filtering:
scope :by_entity_type, ->(entity_type) { where(entity_type: entity_type) }
scope :by_entity_id, ->(entity_id) { where(entity_id: entity_id) }
scope :by_author_id, ->(author_id) { where(author_id: author_id) }
scope :by_entity_username, ->(username) { where(entity_id: find_user_id(username)) }
scope :by_author_username, ->(username) { where(author_id: find_user_id(username)) }
Requirements for the new model
- Our ClickHouse model should support these methods
- Should use
ClickHouse::QueryBuilder
to generate sql queries.
Proposed Solution
Option1
Define both class and instance methods for each of scopes so that they can support method chaining.
Option2
Build a scope method that uses metaprogramming to define these methods for you.
Edited by Harsimar Sandhu