Commit 8a81e6bf authored by Vitali Tatarintev's avatar Vitali Tatarintev

Merge branch 'pl-tracing-core-5-settings-haml' into 'master'

Move remaining parts of Tracing to Core [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!44574
parents cb6f250d a9518743
...@@ -301,7 +301,6 @@ module ProjectsHelper ...@@ -301,7 +301,6 @@ module ProjectsHelper
!disabled && !compact_mode !disabled && !compact_mode
end end
# overridden in EE
def settings_operations_available? def settings_operations_available?
can?(current_user, :read_environment, @project) can?(current_user, :read_environment, @project)
end end
...@@ -755,6 +754,7 @@ module ProjectsHelper ...@@ -755,6 +754,7 @@ module ProjectsHelper
logs logs
product_analytics product_analytics
metrics_dashboard metrics_dashboard
tracings
] ]
end end
......
...@@ -236,7 +236,7 @@ ...@@ -236,7 +236,7 @@
= _('Logs') = _('Logs')
- if project_nav_tab? :environments - if project_nav_tab? :environments
= render_if_exists "layouts/nav/sidebar/tracing_link" = render "layouts/nav/sidebar/tracing_link"
- if project_nav_tab?(:error_tracking) - if project_nav_tab?(:error_tracking)
= nav_link(controller: :error_tracking) do = nav_link(controller: :error_tracking) do
......
- return unless @project.feature_available?(:tracing, current_user) && can?(current_user, :read_environment, @project) - return unless can?(current_user, :read_environment, @project)
- if project_nav_tab? :settings - if project_nav_tab? :settings
= nav_link(controller: :tracings, action: [:show]) do = nav_link(controller: :tracings, action: [:show]) do
......
- return unless @project.feature_available?(:tracing, current_user)
- setting = tracing_setting - setting = tracing_setting
- has_jaeger_url = setting.external_url.present? - has_jaeger_url = setting.external_url.present?
...@@ -11,7 +9,7 @@ ...@@ -11,7 +9,7 @@
= _('Expand') = _('Expand')
%p %p
- if has_jaeger_url - if has_jaeger_url
- tracing_link = link_to sanitize(@project.tracing_external_url, scrubber: Rails::Html::TextOnlyScrubber.new), target: "_blank", rel: 'noopener noreferrer' do - tracing_link = link_to sanitize(setting.external_url, scrubber: Rails::Html::TextOnlyScrubber.new), target: "_blank", rel: 'noopener noreferrer' do
%span %span
= _('Tracing') = _('Tracing')
= sprite_icon('external-link', css_class: 'ml-1 vertical-align-middle') = sprite_icon('external-link', css_class: 'ml-1 vertical-align-middle')
......
...@@ -8,5 +8,5 @@ ...@@ -8,5 +8,5 @@
= render 'projects/settings/operations/prometheus', service: prometheus_service if Feature.enabled?(:settings_operations_prometheus_service) = render 'projects/settings/operations/prometheus', service: prometheus_service if Feature.enabled?(:settings_operations_prometheus_service)
= render 'projects/settings/operations/metrics_dashboard' = render 'projects/settings/operations/metrics_dashboard'
= render 'projects/settings/operations/grafana_integration' = render 'projects/settings/operations/grafana_integration'
= render_if_exists 'projects/settings/operations/tracing' = render 'projects/settings/operations/tracing'
= render_if_exists 'projects/settings/operations/status_page' = render_if_exists 'projects/settings/operations/status_page'
---
title: Move Tracing feature to Core
merge_request: 44574
author:
type: added
...@@ -20,7 +20,6 @@ module EE ...@@ -20,7 +20,6 @@ module EE
override :sidebar_operations_paths override :sidebar_operations_paths
def sidebar_operations_paths def sidebar_operations_paths
super + %w[ super + %w[
tracings
feature_flags feature_flags
] ]
end end
...@@ -272,12 +271,6 @@ module EE ...@@ -272,12 +271,6 @@ module EE
current_user.ab_feature_enabled?(:discover_security) current_user.ab_feature_enabled?(:discover_security)
end end
def settings_operations_available?
return true if super
@project.feature_available?(:tracing, current_user) && can?(current_user, :read_environment, @project)
end
override :can_import_members? override :can_import_members?
def can_import_members? def can_import_members?
super && !membership_locked? super && !membership_locked?
......
...@@ -150,7 +150,6 @@ class License < ApplicationRecord ...@@ -150,7 +150,6 @@ class License < ApplicationRecord
status_page status_page
subepics subepics
threat_monitoring threat_monitoring
tracing
quality_management quality_management
] ]
EEU_FEATURES.freeze EEU_FEATURES.freeze
......
...@@ -3,14 +3,12 @@ ...@@ -3,14 +3,12 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'layouts/nav/sidebar/_project' do RSpec.describe 'layouts/nav/sidebar/_project' do
let(:project) { create(:project, :repository) } let_it_be_with_refind(:project) { create(:project, :repository) }
before do before do
assign(:project, project) assign(:project, project)
assign(:repository, project.repository) assign(:repository, project.repository)
allow(view).to receive(:current_ref).and_return('master') allow(view).to receive(:current_ref).and_return('master')
stub_licensed_features(tracing: true)
end end
describe 'issue boards' do describe 'issue boards' do
...@@ -55,43 +53,6 @@ RSpec.describe 'layouts/nav/sidebar/_project' do ...@@ -55,43 +53,6 @@ RSpec.describe 'layouts/nav/sidebar/_project' do
end end
end end
describe 'Operations > Tracing' do
it 'is not visible when no valid license' do
allow(view).to receive(:can?).and_return(true)
stub_licensed_features(tracing: false)
render
expect(rendered).not_to have_text 'Tracing'
end
it 'is not visible to unauthorized user' do
render
expect(rendered).not_to have_text 'Tracing'
end
it 'links to Tracing page' do
allow(view).to receive(:can?).and_return(true)
render
expect(rendered).to have_link('Tracing', href: project_tracing_path(project))
end
context 'without project.tracing_external_url' do
before do
allow(view).to receive(:can?).and_return(true)
end
it 'links to Tracing page' do
render
expect(rendered).to have_link('Tracing', href: project_tracing_path(project))
end
end
end
describe 'Operations > Pod logs' do describe 'Operations > Pod logs' do
before do before do
allow(view).to receive(:can?).with(nil, :read_environment, project).and_return(can_read_environment) allow(view).to receive(:can?).with(nil, :read_environment, project).and_return(can_read_environment)
...@@ -222,7 +183,6 @@ RSpec.describe 'layouts/nav/sidebar/_project' do ...@@ -222,7 +183,6 @@ RSpec.describe 'layouts/nav/sidebar/_project' do
describe 'Settings > Operations' do describe 'Settings > Operations' do
it 'is not visible when no valid license' do it 'is not visible when no valid license' do
allow(view).to receive(:can?).and_return(true) allow(view).to receive(:can?).and_return(true)
stub_licensed_features(tracing: false)
render render
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'projects/settings/operations/show' do
let_it_be(:project, refind: true) { create(:project, :repository) }
let_it_be(:error_tracking_setting) { create(:project_error_tracking_setting, project: project) }
let(:operations_show_locals) do
{
prometheus_service: project.find_or_initialize_service('prometheus'),
alerts_service: project.find_or_initialize_service('alerts')
}
end
before do
assign(:project, project)
assign(:repository, project.repository)
allow(view).to receive(:current_ref).and_return('master')
allow(view).to receive(:error_tracking_setting).and_return(error_tracking_setting)
allow(view).to receive(:incident_management_available?) { false }
stub_licensed_features(tracing: true)
end
describe 'Operations > Tracing' do
context 'with project.tracing_external_url' do
let(:tracing_url) { 'https://tracing.url' }
let(:tracing_setting) { create(:project_tracing_setting, project: project, external_url: tracing_url) }
before do
allow(view).to receive(:can?).and_return(true)
allow(view).to receive(:tracing_setting).and_return(tracing_setting)
end
it 'links to project.tracing_external_url' do
render template: 'projects/settings/operations/show', locals: operations_show_locals
expect(rendered).to have_link('Tracing', href: tracing_url)
end
context 'with malicious external_url' do
let(:malicious_tracing_url) { "https://replaceme.com/'><script>alert(document.cookie)</script>" }
let(:cleaned_url) { "https://replaceme.com/'>" }
before do
tracing_setting.update_column(:external_url, malicious_tracing_url)
end
it 'sanitizes external_url' do
render template: 'projects/settings/operations/show', locals: operations_show_locals
expect(tracing_setting.external_url).to eq(malicious_tracing_url)
expect(rendered).to have_link('Tracing', href: cleaned_url)
end
end
end
context 'without project.tracing_external_url' do
let(:tracing_setting) { build(:project_tracing_setting, project: project) }
before do
allow(view).to receive(:can?).and_return(true)
allow(view).to receive(:tracing_setting).and_return(tracing_setting)
tracing_setting.external_url = nil
end
it 'links to Tracing page' do
render template: 'projects/settings/operations/show', locals: operations_show_locals
expect(rendered).to have_link('Tracing', href: project_tracing_path(project))
end
end
end
end
...@@ -43,31 +43,17 @@ RSpec.describe Projects::TracingsController do ...@@ -43,31 +43,17 @@ RSpec.describe Projects::TracingsController do
end end
end end
describe 'with valid license' do before do
before do sign_in(user)
stub_licensed_features(tracing: true)
sign_in(user)
end
context 'with maintainer role' do
it_behaves_like 'user with read access', :public
it_behaves_like 'user with read access', :internal
it_behaves_like 'user with read access', :private
end
context 'without maintainer role' do
it_behaves_like 'user without read access', :public
it_behaves_like 'user without read access', :internal
it_behaves_like 'user without read access', :private
end
end end
context 'with invalid license' do context 'with maintainer role' do
before do it_behaves_like 'user with read access', :public
stub_licensed_features(tracing: false) it_behaves_like 'user with read access', :internal
sign_in(user) it_behaves_like 'user with read access', :private
end end
context 'without maintainer role' do
it_behaves_like 'user without read access', :public it_behaves_like 'user without read access', :public
it_behaves_like 'user without read access', :internal it_behaves_like 'user without read access', :internal
it_behaves_like 'user without read access', :private it_behaves_like 'user without read access', :private
......
...@@ -3,13 +3,16 @@ ...@@ -3,13 +3,16 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'Tracings Content Security Policy' do RSpec.describe 'Tracings Content Security Policy' do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let(:project) { create(:project) }
subject { response_headers['Content-Security-Policy'] } subject { response_headers['Content-Security-Policy'] }
before do before_all do
project.add_maintainer(user) project.add_maintainer(user)
end
before do
sign_in(user) sign_in(user)
end end
......
...@@ -65,6 +65,7 @@ RSpec.shared_context 'project navbar structure' do ...@@ -65,6 +65,7 @@ RSpec.shared_context 'project navbar structure' do
nav_sub_items: [ nav_sub_items: [
_('Metrics'), _('Metrics'),
_('Logs'), _('Logs'),
_('Tracing'),
_('Error Tracking'), _('Error Tracking'),
_('Alerts'), _('Alerts'),
_('Incidents'), _('Incidents'),
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'layouts/nav/sidebar/_project' do RSpec.describe 'layouts/nav/sidebar/_project' do
let(:project) { create(:project, :repository) } let_it_be_with_reload(:project) { create(:project, :repository) }
before do before do
assign(:project, project) assign(:project, project)
...@@ -246,6 +246,30 @@ RSpec.describe 'layouts/nav/sidebar/_project' do ...@@ -246,6 +246,30 @@ RSpec.describe 'layouts/nav/sidebar/_project' do
end end
end end
describe 'Tracing' do
it 'is not visible to unauthorized user' do
allow(view).to receive(:can?).and_return(false)
render
expect(rendered).not_to have_text 'Tracing'
end
it 'links to Tracing page' do
render
expect(rendered).to have_link('Tracing', href: project_tracing_path(project))
end
context 'without project.tracing_external_url' do
it 'links to Tracing page' do
render
expect(rendered).to have_link('Tracing', href: project_tracing_path(project))
end
end
end
describe 'Alert Management' do describe 'Alert Management' do
it 'shows the Alerts sidebar entry' do it 'shows the Alerts sidebar entry' do
render render
......
...@@ -6,37 +6,85 @@ RSpec.describe 'projects/settings/operations/show' do ...@@ -6,37 +6,85 @@ RSpec.describe 'projects/settings/operations/show' do
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let_it_be(:error_tracking_setting) do
create(:project_error_tracking_setting, project: project)
end
let_it_be_with_reload(:tracing_setting) do
create(:project_tracing_setting, project: project)
end
let_it_be(:prometheus_service) { create(:prometheus_service, project: project) }
let_it_be(:alerts_service) { create(:alerts_service, project: project) }
let(:operations_show_locals) do let(:operations_show_locals) do
{ {
prometheus_service: project.find_or_initialize_service('prometheus'), prometheus_service: prometheus_service,
alerts_service: project.find_or_initialize_service('alerts') alerts_service: alerts_service
} }
end end
before_all do
project.add_reporter(user)
end
before do before do
assign :project, project assign :project, project
allow(view).to receive(:error_tracking_setting)
.and_return(error_tracking_setting)
allow(view).to receive(:tracing_setting)
.and_return(tracing_setting)
allow(view).to receive(:current_user).and_return(user)
end end
describe 'Operations > Error Tracking' do describe 'Operations > Error Tracking' do
before do context 'Settings page ' do
project.add_reporter(user) it 'renders the Operations Settings page' do
render template: 'projects/settings/operations/show', locals: operations_show_locals
allow(view).to receive(:error_tracking_setting) expect(rendered).to have_content _('Error tracking')
.and_return(error_tracking_setting) expect(rendered).to have_content _('To link Sentry to GitLab, enter your Sentry URL and Auth Token')
allow(view).to receive(:current_user).and_return(user) end
allow(view).to receive(:incident_management_available?) { false }
end end
end
let_it_be(:error_tracking_setting) do describe 'Operations > Tracing' do
create(:project_error_tracking_setting, project: project) context 'with project.tracing_external_url' do
it 'links to project.tracing_external_url' do
render template: 'projects/settings/operations/show', locals: operations_show_locals
expect(rendered).to have_link('Tracing', href: tracing_setting.external_url)
end
context 'with malicious external_url' do
let(:malicious_tracing_url) { "https://replaceme.com/'><script>alert(document.cookie)</script>" }
let(:cleaned_url) { "https://replaceme.com/'>" }
before do
tracing_setting.update_column(:external_url, malicious_tracing_url)
end
it 'sanitizes external_url' do
render template: 'projects/settings/operations/show', locals: operations_show_locals
expect(tracing_setting.external_url).to eq(malicious_tracing_url)
expect(rendered).to have_link('Tracing', href: cleaned_url)
end
end
end end
context 'Settings page ' do context 'without project.tracing_external_url' do
it 'renders the Operations Settings page' do let(:tracing_setting) { build(:project_tracing_setting, project: project) }
before do
tracing_setting.external_url = nil
end
it 'links to Tracing page' do
render template: 'projects/settings/operations/show', locals: operations_show_locals render template: 'projects/settings/operations/show', locals: operations_show_locals
expect(rendered).to have_content _('Error tracking') expect(rendered).to have_link('Tracing', href: project_tracing_path(project))
expect(rendered).to have_content _('To link Sentry to GitLab, enter your Sentry URL and Auth Token')
end end
end end
end 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