Create agent activity events
What does this MR do and why?
- Creates a model to store activity related to an Agent, which will be shown as a stream of recent events in the Agent UI.
- Records an event when a new token is created for an Agent.
Initially only one type of event is supported (creating a new token), for the full list of planned events see #277323 (closed). Several database columns are currently unused as they aren't relevant to token creation (eg. sha
), but they will be used in the future (eg. a GitOps sync event).
Migrations
Click to expand
== 20211110014701 CreateAgentActivityEvents: reverting ========================
-- drop_table(:agent_activity_events, {})
-> 0.0096s
== 20211110014701 CreateAgentActivityEvents: reverted (0.0131s) ===============
== 20211110014701 CreateAgentActivityEvents: migrating ========================
-- create_table(:agent_activity_events, {})
-- quote_column_name(:detail)
-> 0.0000s
-> 0.0521s
== 20211110014701 CreateAgentActivityEvents: migrated (0.0522s) ===============
== 20211110015252 AddAgentActivityEventsForeignKeys: reverting ================
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:agent_activity_events)
-> 0.0095s
-- remove_foreign_key(:agent_activity_events, {:column=>:agent_id})
-> 0.0080s
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:agent_activity_events)
-> 0.0033s
-- remove_foreign_key(:agent_activity_events, {:column=>:user_id})
-> 0.0054s
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:agent_activity_events)
-> 0.0036s
-- remove_foreign_key(:agent_activity_events, {:column=>:project_id})
-> 0.0050s
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:agent_activity_events)
-> 0.0033s
-- remove_foreign_key(:agent_activity_events, {:column=>:merge_request_id})
-> 0.0045s
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:agent_activity_events)
-> 0.0023s
-- remove_foreign_key(:agent_activity_events, {:column=>:agent_token_id})
-> 0.0037s
== 20211110015252 AddAgentActivityEventsForeignKeys: reverted (0.1101s) =======
== 20211110015252 AddAgentActivityEventsForeignKeys: migrating ================
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:agent_activity_events)
-> 0.0056s
-- transaction_open?()
-> 0.0000s
-- execute("ALTER TABLE agent_activity_events\nADD CONSTRAINT fk_c815368376\nFOREIGN KEY (agent_id)\nREFERENCES cluster_agents (id)\nON DELETE CASCADE\nNOT VALID;\n")
-> 0.0056s
-- execute("SET statement_timeout TO 0")
-> 0.0007s
-- execute("ALTER TABLE agent_activity_events VALIDATE CONSTRAINT fk_c815368376;")
-> 0.0088s
-- execute("RESET statement_timeout")
-> 0.0007s
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:agent_activity_events)
-> 0.0027s
-- transaction_open?()
-> 0.0000s
-- execute("ALTER TABLE agent_activity_events\nADD CONSTRAINT fk_d6f785c9fc\nFOREIGN KEY (user_id)\nREFERENCES users (id)\nON DELETE SET NULL\nNOT VALID;\n")
-> 0.0034s
-- execute("ALTER TABLE agent_activity_events VALIDATE CONSTRAINT fk_d6f785c9fc;")
-> 0.0155s
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:agent_activity_events)
-> 0.0031s
-- transaction_open?()
-> 0.0000s
-- execute("ALTER TABLE agent_activity_events\nADD CONSTRAINT fk_256c631779\nFOREIGN KEY (project_id)\nREFERENCES projects (id)\nON DELETE SET NULL\nNOT VALID;\n")
-> 0.0022s
-- execute("ALTER TABLE agent_activity_events VALIDATE CONSTRAINT fk_256c631779;")
-> 0.0089s
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:agent_activity_events)
-> 0.0027s
-- transaction_open?()
-> 0.0000s
-- execute("ALTER TABLE agent_activity_events\nADD CONSTRAINT fk_3af186389b\nFOREIGN KEY (merge_request_id)\nREFERENCES merge_requests (id)\nON DELETE SET NULL\nNOT VALID;\n")
-> 0.0024s
-- execute("ALTER TABLE agent_activity_events VALIDATE CONSTRAINT fk_3af186389b;")
-> 0.0181s
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:agent_activity_events)
-> 0.0028s
-- transaction_open?()
-> 0.0000s
-- execute("ALTER TABLE agent_activity_events\nADD CONSTRAINT fk_c8b006d40f\nFOREIGN KEY (agent_token_id)\nREFERENCES cluster_agent_tokens (id)\nON DELETE SET NULL\nNOT VALID;\n")
-> 0.0013s
-- execute("ALTER TABLE agent_activity_events VALIDATE CONSTRAINT fk_c8b006d40f;")
-> 0.0042s
== 20211110015252 AddAgentActivityEventsForeignKeys: migrated (0.1163s) =======
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #340364 (closed)
Edited by Tiger Watson