Commit aaa66e4e authored by Mario de la Ossa's avatar Mario de la Ossa

Ensure RepositoryLinkFilter handles Gitaly failures gracefully

We do this by setting all paths to `:blob` type if we get either
`GRPC::Unavailable` or `GRPC::DeadlineExceeded` when calling
`GitalyClient`. This is acceptable because all files existing in a
repository can be viewed in "blob" mode, although if Gitaly is down we
won't be able to fetch the object anyways.
parent 88a7dc21
---
title: Ensure RepositoryLinkFilter handles Gitaly failures gracefully
merge_request: 26531
author:
type: performance
...@@ -80,6 +80,13 @@ module Banzai ...@@ -80,6 +80,13 @@ module Banzai
end end
Gitlab::GitalyClient::BlobService.new(repository).get_blob_types(revision_paths, 1) Gitlab::GitalyClient::BlobService.new(repository).get_blob_types(revision_paths, 1)
rescue GRPC::Unavailable, GRPC::DeadlineExceeded => e
# Handle Gitaly connection issues gracefully
Gitlab::ErrorTracking.track_exception(e, project_id: project.id)
# Return all links as blob types
paths.collect do |path|
[path, :blob]
end
end end
def get_uri(html_attr) def get_uri(html_attr)
......
...@@ -149,6 +149,34 @@ describe Banzai::Filter::RepositoryLinkFilter do ...@@ -149,6 +149,34 @@ describe Banzai::Filter::RepositoryLinkFilter do
end end
shared_examples :valid_repository do shared_examples :valid_repository do
it 'handles Gitaly unavailable exceptions gracefully' do
allow_next_instance_of(Gitlab::GitalyClient::BlobService) do |blob_service|
allow(blob_service).to receive(:get_blob_types).and_raise(GRPC::Unavailable)
end
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(
an_instance_of(GRPC::Unavailable), project_id: project.id
)
doc = ""
expect { doc = filter(link('doc/api/README.md')) }.not_to raise_error
expect(doc.at_css('a')['href'])
.to eq "/#{project_path}/-/blob/#{ref}/doc/api/README.md"
end
it 'handles Gitaly timeout exceptions gracefully' do
allow_next_instance_of(Gitlab::GitalyClient::BlobService) do |blob_service|
allow(blob_service).to receive(:get_blob_types).and_raise(GRPC::DeadlineExceeded)
end
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(
an_instance_of(GRPC::DeadlineExceeded), project_id: project.id
)
doc = ""
expect { doc = filter(link('doc/api/README.md')) }.not_to raise_error
expect(doc.at_css('a')['href'])
.to eq "/#{project_path}/-/blob/#{ref}/doc/api/README.md"
end
it 'rebuilds absolute URL for a file in the repo' do it 'rebuilds absolute URL for a file in the repo' do
doc = filter(link('/doc/api/README.md')) doc = filter(link('/doc/api/README.md'))
expect(doc.at_css('a')['href']) expect(doc.at_css('a')['href'])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment