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