CI Runners: Add token expiration field
What does this MR do and why?
This is the second MR of !71607 (closed), as per !71607 (comment 791611312). It adds a database field for a CI runner's token expiration time.
Database query plans
DESC
SELECT
"ci_runners".*
FROM
"ci_runners"
ORDER BY
"ci_runners"."token_expires_at" DESC,
"ci_runners"."id" DESC
Link: https://postgres.ai/console/gitlab/gitlab-production-tunnel-pg12/sessions/8040/commands/28677
Query plan
Index Scan using index_ci_runners_on_token_expires_at_desc_and_id_desc on public.ci_runners (cost=0.43..305360.08 rows=3277610 width=267) (actual time=0.159..5581.368 rows=3277610 loops=1)
Buffers: shared hit=2956781 read=12560
I/O Timings: read=328.674 write=0.000
ASC
SELECT
"ci_runners".*
FROM
"ci_runners"
ORDER BY
"ci_runners"."token_expires_at" ASC,
"ci_runners"."id" DESC
Link: https://postgres.ai/console/gitlab/gitlab-production-tunnel-pg12/sessions/8040/commands/28678
Query plan
Index Scan using index_ci_runners_on_token_expires_at_and_id_desc on public.ci_runners (cost=0.43..305360.08 rows=3277610 width=267) (actual time=0.088..4949.759 rows=3277610 loops=1)
Buffers: shared hit=2969341
I/O Timings: read=0.000 write=0.000
Migrations
Migration up
rails db:migrate:up VERSION=20220111154950
== 20220111154950 AddTokenExpiresAtToCiRunners: migrating =====================
-- add_column(:ci_runners, :token_expires_at, :datetime_with_timezone)
-> 0.0031s
== 20220111154950 AddTokenExpiresAtToCiRunners: migrated (0.0032s) ============
rails db:migrate:up VERSION=20220111154951
== 20220111154951 AddIndexToCiRunnersTokenExpiresAt: migrating ================
-- transaction_open?()
-> 0.0000s
-- index_exists?(:ci_runners, [:token_expires_at, :id], {:order=>{:token_expires_at=>:asc, :id=>:desc}, :name=>"index_ci_runners_on_token_expires_at_and_id_desc", :algorithm=>:concurrently})
-> 0.0053s
-- execute("SET statement_timeout TO 0")
-> 0.0010s
-- add_index(:ci_runners, [:token_expires_at, :id], {:order=>{:token_expires_at=>:asc, :id=>:desc}, :name=>"index_ci_runners_on_token_expires_at_and_id_desc", :algorithm=>:concurrently})
-> 0.0038s
-- execute("RESET statement_timeout")
-> 0.0010s
-- transaction_open?()
-> 0.0000s
-- index_exists?(:ci_runners, [:token_expires_at, :id], {:order=>{:token_expires_at=>:desc, :id=>:desc}, :name=>"index_ci_runners_on_token_expires_at_desc_and_id_desc", :algorithm=>:concurrently})
-> 0.0050s
-- add_index(:ci_runners, [:token_expires_at, :id], {:order=>{:token_expires_at=>:desc, :id=>:desc}, :name=>"index_ci_runners_on_token_expires_at_desc_and_id_desc", :algorithm=>:concurrently})
-> 0.0029s
== 20220111154951 AddIndexToCiRunnersTokenExpiresAt: migrated (0.0288s) =======
Migration down
rails db:migrate:down VERSION=20220111154951
== 20220111154951 AddIndexToCiRunnersTokenExpiresAt: reverting ================
-- transaction_open?()
-> 0.0000s
-- indexes(:ci_runners)
-> 0.0066s
-- execute("SET statement_timeout TO 0")
-> 0.0009s
-- remove_index(:ci_runners, {:algorithm=>:concurrently, :name=>"index_ci_runners_on_token_expires_at_desc_and_id_desc"})
-> 0.0036s
-- execute("RESET statement_timeout")
-> 0.0005s
-- transaction_open?()
-> 0.0000s
-- indexes(:ci_runners)
-> 0.0043s
-- remove_index(:ci_runners, {:algorithm=>:concurrently, :name=>"index_ci_runners_on_token_expires_at_and_id_desc"})
-> 0.0015s
== 20220111154951 AddIndexToCiRunnersTokenExpiresAt: reverted (0.0222s) =======
rails db:migrate:down VERSION=20220111154950
== 20220111154950 AddTokenExpiresAtToCiRunners: reverting =====================
-- remove_column(:ci_runners, :token_expires_at, :datetime_with_timezone)
-> 0.0027s
== 20220111154950 AddTokenExpiresAtToCiRunners: reverted (0.0071s) ============
Migration timing from production thin clone:
gitlabhq_dblab# ALTER TABLE ci_runners ADD COLUMN token_expires_at timestamptz;
ALTER TABLE
Time: 156.235 ms
gitlabhq_dblab# CREATE INDEX CONCURRENTLY index_ci_runners_on_token_expires_at_and_id_desc ON ci_runners USING btree (token_expires_at, id DESC);
CREATE INDEX
Time: 36241.776 ms (00:36.242)
gitlabhq_dblab# CREATE INDEX CONCURRENTLY index_ci_runners_on_token_expires_at_desc_and_id_desc ON ci_runners USING btree (token_expires_at DESC, id DESC);
CREATE INDEX
Time: 9022.139 ms (00:09.022)
Edited by Patrick Bair