Improve the ElasticSearch settings autocomplete results
What does this MR do?
This MR changes the way we handle the autocomplete results in the ElasticSearch integration page in the Admin UI.
The old behavior was leveraging the GitLab namespaces
and projects
endpoints, which cause weird name clashes because these endpoints are meant to be paginated through.
The new approach ensure we are using a unique key to search (the Route.path
) of the entity we want to search for, then sorts the results such as a perfect match will always be on top.
Screenshots
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry -
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Database
Sample query this MR will generate:
SELECT "routes".*
FROM "routes"
WHERE "routes"."path" ILIKE '%mass\_insert%'
AND "routes"."source_type" = 'Project'
AND "routes"."source_id" IN (
SELECT "projects"."id"
FROM "projects"
WHERE (
EXISTS (
SELECT 1
FROM "project_authorizations"
WHERE "project_authorizations"."user_id" = 1
AND (project_authorizations.project_id = projects.id)
)
OR projects.visibility_level IN (0,10,20))
)
ORDER BY LENGTH("routes"."path") ASC
LIMIT 20
Migration output
~/g/g/g/gitlab ❯❯❯ bundle exec rake db:rollback
== 20200408133211 AddIndexOnRoutePathTrigram: reverting =======================
-- transaction_open?()
-> 0.0000s
-- indexes(:routes)
-> 0.0041s
-- execute("SET statement_timeout TO 0")
-> 0.0002s
-- remove_index(:routes, {:algorithm=>:concurrently, :name=>"index_routes_on_path_trigram"})
-> 0.0134s
-- execute("RESET ALL")
-> 0.0002s
== 20200408133211 AddIndexOnRoutePathTrigram: reverted (0.0188s) ==============
~/g/g/g/gitlab ❯❯❯ bundle exec rake db:migrate
== 20200408133211 AddIndexOnRoutePathTrigram: migrating =======================
-- transaction_open?()
-> 0.0000s
-- index_exists?(:routes, :path, {:name=>"index_routes_on_path_trigram", :using=>:gin, :opclass=>{:path=>:gin_trgm_ops}, :algorithm=>:concurrently})
-> 0.0024s
-- execute("SET statement_timeout TO 0")
-> 0.0002s
-- add_index(:routes, :path, {:name=>"index_routes_on_path_trigram", :using=>:gin, :opclass=>{:path=>:gin_trgm_ops}, :algorithm=>:concurrently})
-> 84.5393s
-- execute("RESET ALL")
-> 0.0002s
== 20200408133211 AddIndexOnRoutePathTrigram: migrated (84.5423s) =============
Security
There are two new autocomplete endpoints which both complies with the GitLab authorization model, such as:
-
/autocomplete/project_routes
: routes of all projects that are visible to the current user -
/autocomplete/namespace_routes
: routes of all the namespaces that are visible to the current user OR all routes for an admin
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
-
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