Skip to content

Implement search argument in RunnersResolver

What does this MR do?

This MR adds support for the search argument in the runners GraphQL query for admin users, to support the new Vue UI containing a text box. It allows searching in the description column and the token column (which will contain NULL if the runner token encryption is in effect).

It changes Ci::Runner.search to perform search on the full token instead of a partial ILIKE search, so we avoid creating a new index for that column.

Screenshots (strongly suggested)

image

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Database

NOTE: An index for created_at+id is being introduced in !62310 (merged)

Migrate up
$ rails db:migrate RAILS_ENV=development
== 20210602122233 AddRunnersDescriptionIndex: migrating =======================
-- transaction_open?()
   -> 0.0000s
-- index_exists?(:ci_runners, :description, {:name=>"index_ci_runners_on_description_trigram", :using=>:gin, :opclass=>{:description=>:gin_trgm_ops}, :algorithm=>:concurrently})
   -> 0.0088s
-- execute("SET statement_timeout TO 0")
   -> 0.0005s
-- add_index(:ci_runners, :description, {:name=>"index_ci_runners_on_description_trigram", :using=>:gin, :opclass=>{:description=>:gin_trgm_ops}, :algorithm=>:concurrently})
   -> 0.0214s
-- execute("RESET ALL")
   -> 0.0005s
== 20210602122233 AddRunnersDescriptionIndex: migrated (0.0323s) ==============

rails db:migrate RAILS_ENV=development  9.59s user 6.97s system 78% cpu 21.035 total
Migrate down
$ rails db:rollback STEP=1 RAILS_ENV=development
== 20210602122233 AddRunnersDescriptionIndex: reverting =======================
-- transaction_open?()
   -> 0.0000s
-- indexes(:ci_runners)
   -> 0.0041s
-- execute("SET statement_timeout TO 0")
   -> 0.0005s
-- remove_index(:ci_runners, {:algorithm=>:concurrently, :name=>"index_ci_runners_on_description_trigram"})
   -> 0.0031s
-- execute("RESET ALL")
   -> 0.0005s
== 20210602122233 AddRunnersDescriptionIndex: reverted (0.0091s) ==============

rails db:rollback STEP=1 RAILS_ENV=development  8.56s user 6.06s system 88% cpu 16.437 total

Generated SQL:

SELECT
    "ci_runners".*
FROM
    "ci_runners"
WHERE ("ci_runners"."token" = 'updated'
    OR "ci_runners"."description" ILIKE '%updated%')
Query plan

Link: https://gitlab.slack.com/archives/CLJMDRD8C/p1623076918487100

 Bitmap Heap Scan on public.ci_runners  (cost=28.00..142.45 rows=72 width=232) (actual time=5.059..7.492 rows=14 loops=1)
   Buffers: shared hit=27 read=17
   I/O Timings: read=6.950 write=0.000
   ->  BitmapOr  (cost=28.00..28.00 rows=72 width=0) (actual time=4.131..4.132 rows=0 loops=1)
         Buffers: shared hit=27 read=3
         I/O Timings: read=3.694 write=0.000
         ->  Bitmap Index Scan using index_ci_runners_on_token  (cost=0.00..1.94 rows=1 width=0) (actual time=3.756..3.757 rows=0 loops=1)
               Index Cond: ((ci_runners.token)::text = 'updated'::text)
               Buffers: shared read=3
               I/O Timings: read=3.694 write=0.000
         ->  Bitmap Index Scan using index_ci_runners_on_description_trigram  (cost=0.00..26.03 rows=71 width=0) (actual time=0.373..0.373 rows=14 loops=1)
               Index Cond: ((ci_runners.description)::text ~~* '%updated%'::text)
               Buffers: shared hit=27
               I/O Timings: read=0.000 write=0.000

Closes #331598 (closed)

Merge request reports