Fix 500 error in global & group search for blob, wiki_blob and commit search
What does this MR do?
Fixes: #197908 (closed)
While working on this bug from Sentry, I noticed that the following endpoints are returning 500 error on GitLab.com
-
Global blob search
-
Global wiki blobs search
-
Global commit search
Sentry Error: https://sentry.gitlab.net/gitlab/gitlabcom/issues/1185387/events/
From my investigation this appears to be a case of the check for 'elastic search enabled?' going wrong
Problem:
The decision on whether or not to allow search for these entities is decided via: https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/ee/api/search.rb#L22
::Gitlab::CurrentSettings.elasticsearch_search?
and this appears to be true for Gitlab.com and hence the search goes thru.
However, in
https://gitlab.com/gitlab-org/gitlab/blob/master/ee/app/services/ee/search/global_service.rb#L12
the check to decide if the search should be carried out via ES is done using a different check, ie @https://gitlab.com/gitlab-org/gitlab/blob/master/ee/app/services/concerns/search/elasticsearchable.rb#L8
::Gitlab::CurrentSettings.search_using_elasticsearch?(scope: elasticsearchable_scope)
If we see the implementation of search_using_elasticsearch?
def search_using_elasticsearch?(scope: nil)
return false unless elasticsearch_indexing? && elasticsearch_search?
return true unless elasticsearch_limit_indexing?
case scope
when Namespace
elasticsearch_indexes_namespace?(scope)
when Project
elasticsearch_indexes_project?(scope)
else
false # Never use elasticsearch for the global scope when limiting is on
end
end
Our method is called with scope nil
and elasticsearch_limit_indexing?
on GitLab.com db is returning true
right now
gitlabhq_production=> select elasticsearch_limit_indexing from application_settings;
elasticsearch_limit_indexing
------------------------------
t
(1 row)
and hence this method finally returns false
leading to the API call failing.
I am raising the MR to fix this from returning a 500 error:
These searches will now raise a 400 with Scope not supported without Elasticsearch!
instead.
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
Security
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