Commit 1a0d4c64 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '119038-add-polling-headers-for-error-details' into 'master'

Resolve Consistent polling in error tracking pages - Backend

See merge request gitlab-org/gitlab!22070
parents 85cad651 e4cac8a3
# frozen_string_literal: true
class Projects::ErrorTracking::BaseController < Projects::ApplicationController
POLLING_INTERVAL = 1_000
def set_polling_interval
Gitlab::PollingInterval.set_header(response, interval: POLLING_INTERVAL)
end
end
......@@ -2,10 +2,10 @@
module Projects
module ErrorTracking
class StackTracesController < Projects::ApplicationController
class StackTracesController < Projects::ErrorTracking::BaseController
respond_to :json
before_action :authorize_read_sentry_issue!
before_action :authorize_read_sentry_issue!, :set_polling_interval
def index
result = fetch_latest_event_issue
......
# frozen_string_literal: true
class Projects::ErrorTrackingController < Projects::ApplicationController
class Projects::ErrorTrackingController < Projects::ErrorTracking::BaseController
before_action :authorize_read_sentry_issue!
before_action :set_issue_id, only: :details
POLLING_INTERVAL = 10_000
def index
respond_to do |format|
format.html
......@@ -20,6 +18,7 @@ class Projects::ErrorTrackingController < Projects::ApplicationController
respond_to do |format|
format.html
format.json do
set_polling_interval
render_issue_detail_json
end
end
......@@ -74,10 +73,6 @@ class Projects::ErrorTrackingController < Projects::ApplicationController
@issue_id = issue_details_params[:issue_id]
end
def set_polling_interval
Gitlab::PollingInterval.set_header(response, interval: POLLING_INTERVAL)
end
def serialize_errors(errors)
ErrorTracking::ErrorSerializer
.new(project: project, user: current_user)
......
......@@ -34,6 +34,8 @@ describe Projects::ErrorTracking::StackTracesController do
it 'responds with no data' do
expect(response).to have_gitlab_http_status(:no_content)
end
it_behaves_like 'sets the polling header'
end
context 'service result is successful' do
......@@ -53,6 +55,8 @@ describe Projects::ErrorTracking::StackTracesController do
Gitlab::ErrorTracking::StackTraceHighlightDecorator.decorate(error_event).as_json
)
end
it_behaves_like 'sets the polling header'
end
context 'service result is erroneous' do
......
......@@ -91,13 +91,13 @@ describe Projects::ErrorTrackingController do
.and_return(status: :success, issues: [error], pagination: {})
expect(list_issues_service).to receive(:external_url)
.and_return(external_url)
get :index, params: params
end
let(:error) { build(:error_tracking_error) }
it 'returns a list of errors' do
get :index, params: params
expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('error_tracking/index')
expect(json_response).to eq(
......@@ -106,6 +106,8 @@ describe Projects::ErrorTrackingController do
'external_url' => external_url
)
end
it_behaves_like 'sets the polling header'
end
end
......@@ -201,30 +203,33 @@ describe Projects::ErrorTrackingController do
before do
expect(issue_details_service).to receive(:execute)
.and_return(status: :error, http_status: :no_content)
get :details, params: issue_params(issue_id: issue_id, format: :json)
end
it 'returns no data' do
get :details, params: issue_params(issue_id: issue_id, format: :json)
expect(response).to have_gitlab_http_status(:no_content)
end
it_behaves_like 'sets the polling header'
end
context 'service result is successful' do
before do
expect(issue_details_service).to receive(:execute)
.and_return(status: :success, issue: error)
get :details, params: issue_params(issue_id: issue_id, format: :json)
end
let(:error) { build(:detailed_error_tracking_error) }
it 'returns an error' do
get :details, params: issue_params(issue_id: issue_id, format: :json)
expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('error_tracking/issue_detailed')
expect(json_response['error']).to eq(error.as_json)
end
it_behaves_like 'sets the polling header'
end
context 'service result is erroneous' do
......
# frozen_string_literal: true
shared_examples 'sets the polling header' do
subject { response.headers[Gitlab::PollingInterval::HEADER_NAME] }
it { is_expected.to eq '1000'}
end
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