Commit e3577373 authored by Adrien Kohlbecker's avatar Adrien Kohlbecker

Rescue elasticsearch server error in pod logs

parent 10b04c00
---
title: Rescue elasticsearch server error in pod logs
merge_request: 25367
author:
type: fixed
...@@ -51,6 +51,14 @@ module PodLogs ...@@ -51,6 +51,14 @@ module PodLogs
) )
success(result) success(result)
rescue Elasticsearch::Transport::Transport::ServerError => e
::Gitlab::ErrorTracking.track_exception(e)
error(_('Elasticsearch returned status code: %{status_code}') % {
# ServerError is the parent class of exceptions named after HTTP status codes, eg: "Elasticsearch::Transport::Transport::Errors::NotFound"
# there is no method on the exception other than the class name to determine the type of error encountered.
status_code: e.class.name.split('::').last
})
end end
def etag_path def etag_path
......
...@@ -157,5 +157,19 @@ describe ::PodLogs::ElasticsearchService do ...@@ -157,5 +157,19 @@ describe ::PodLogs::ElasticsearchService do
expect(result[:status]).to eq(:error) expect(result[:status]).to eq(:error)
expect(result[:message]).to eq('Unable to connect to Elasticsearch') expect(result[:message]).to eq('Unable to connect to Elasticsearch')
end end
it 'handles server errors from elasticsearch' do
allow_any_instance_of(::Clusters::Applications::ElasticStack)
.to receive(:elasticsearch_client)
.and_return(Elasticsearch::Transport::Client.new)
allow_any_instance_of(::Gitlab::Elasticsearch::Logs)
.to receive(:pod_logs)
.and_raise(Elasticsearch::Transport::Transport::Errors::ServiceUnavailable.new)
result = subject.send(:pod_logs, result_arg)
expect(result[:status]).to eq(:error)
expect(result[:message]).to eq('Elasticsearch returned status code: ServiceUnavailable')
end
end end
end end
...@@ -7017,6 +7017,9 @@ msgstr "" ...@@ -7017,6 +7017,9 @@ msgstr ""
msgid "Elasticsearch integration. Elasticsearch AWS IAM." msgid "Elasticsearch integration. Elasticsearch AWS IAM."
msgstr "" msgstr ""
msgid "Elasticsearch returned status code: %{status_code}"
msgstr ""
msgid "Elastic|None. Select namespaces to index." msgid "Elastic|None. Select namespaces to index."
msgstr "" msgstr ""
......
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