wiki: Check if empty before querying files

What does this MR do and why?

Whenever the Repository home page is loaded, the ProjectPresenter will check if the project's Wiki has a home page. This is used to determine how the Wiki link should be rendered -- either as an "Add Wiki" link or a button to navigate to the existing Wiki.

This call will eventually reach the find_matched_files method and then result in a Gitaly call to the SearchFilesByName RPC.

If this happens on a project that has an empty Wiki repository (i.e. a project which does not have any Wiki pages), SearchFilesByName will fail. Internally, Gitaly will log a "fatal: Not a valid object name " error, where is the default branch of the Wiki repository. Rails however will simply swallow this error and return no results, allowing the ProjectPresenter to display the "Add Wiki" link.

The logs for gprd show that we're producing over one million of these superfluous error logs per week. On top of wasting disk space, the errors pollute real errors and make it difficult to monitor Gitaly in production.

Add a check to repository.has_visible_content? before making any search queries for individual files. has_visible_content? simply calls the HasLocalBranches Gitaly RPC, which will return false if the repository exists but is empty.

References

#420155 (closed)

Screenshots or screen recordings

Before After

How to set up and validate locally

  1. Check out this branch in your GDK tree, and start your GDK instance.
  2. Monitor Gitaly logs by running gdk tail gitaly | grep SearchFilesByName. This will allow you to filter Gitaly logs to the SearchFilesByName RPC.
  3. Create a new Project, i.e. http://gdk.test:3000/projects/new
  4. Observe that no log output is produced, indicating that we're not issuing any requests to the SearchFilesByName RPC due to the repository being empty.
  5. Create a Wiki for the Project, i.e. http://gdk.test:3000/root/wiki-test-5/-/wikis/home?view=create
  6. Observe that several logs are produced, but none of them are errors that contain the fatal: Not a valid object name <branch> message. This indicates the normal behaviour of the wiki controller as it issues a SearchFilesByName request for several files, after the wiki is initially created and each time it's accessed.
  7. Check out the master branch in your GDK tree, and gdk restart rails-web to clear any caches.
  8. Repeat steps 3 through 6 with a brand new Project.
  9. Observe that SearchFilesByName logs are displayed in both cases, and in both cases the fatal: Not a valid object name <branch> error message is present. This indicates that we were issuing several SearchFilesByName RPCs to Gitaly that are sure to fail.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by James Liu

Merge request reports

Loading