diff --git a/app/controllers/groups/observability_controller.rb b/app/controllers/groups/observability_controller.rb index 1253e86d3863679590a82834a6c84e575561ef34..5de4d563ca6a2fb3b5b742958e6130c69053510e 100644 --- a/app/controllers/groups/observability_controller.rb +++ b/app/controllers/groups/observability_controller.rb @@ -17,28 +17,13 @@ class ObservabilityController < Groups::ApplicationController p.frame_src(*frame_src_values) end - VALID_PATHS = %w[ - services - traces-explorer - logs/logs-explorer - metrics-explorer/summary - infrastructure-monitoring/hosts - dashboard - messaging-queues - api-monitoring/explorer - alerts - exceptions - service-map - settings - ].freeze + VALID_PATHS = Observability::ObservabilityPresenter::PATHS.keys.freeze def show - @o11y_url = group.observability_group_o11y_setting&.o11y_service_url - - @path = permitted_params[:id] - - return render_404 unless VALID_PATHS.include?(@path) + path = permitted_params[:id] + return render_404 unless VALID_PATHS.include?(path) + @data = Observability::ObservabilityPresenter.new(group, path) render end diff --git a/app/views/groups/observability/show.html.haml b/app/views/groups/observability/show.html.haml index 7be6e7400584ed7062c6f4dba6ee7c15fc45ef68..793e9a4aafead3d86479c087561a129116a0f6f8 100644 --- a/app/views/groups/observability/show.html.haml +++ b/app/views/groups/observability/show.html.haml @@ -3,6 +3,10 @@ .observability-container.gl-flex.gl-flex-col .gl-display-flex.gl-items-center.gl-mt-3.gl-mb-5 - %h1.gl-heading-1= _("Observability") + %h1.gl-heading-1= @data.title - #js-observability{ data: { o11y_url: @o11y_url, path: @path } } + - if @data&.auth_tokens.blank? + = render Pajamas::AlertComponent.new(dismissible: false, variant: :danger, title: _('Unable to authenticate with the observability service. Please check your configuration and try again.')) + + - else + #js-observability{ data: @data.to_h } diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 575f6e0b6da08225836979b0d0e7569907fd8abe..9bfef7c0463194be282eed5f2f5f391f02bc71f3 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -66468,6 +66468,9 @@ msgstr "" msgid "Unable to apply suggestions to a deleted line." msgstr "" +msgid "Unable to authenticate with the observability service. Please check your configuration and try again." +msgstr "" + msgid "Unable to build Slack link." msgstr "" diff --git a/spec/requests/groups/observability_controller_spec.rb b/spec/requests/groups/observability_controller_spec.rb index 86667126269cbcb2100e7fccc670a039f92c0b8f..e3794f01370700c9a52fa5bf90e180deb0bbc069 100644 --- a/spec/requests/groups/observability_controller_spec.rb +++ b/spec/requests/groups/observability_controller_spec.rb @@ -27,9 +27,10 @@ context 'when feature flag is enabled' do before do stub_feature_flags(observability_sass_features: group) + allow(Observability::O11yToken).to receive(:generate_tokens).and_return({ 'testToken' => 'value' }) end - context 'with incorrect permissons' do + context 'with incorrect permissions' do let(:user) { create(:user) } before do @@ -52,8 +53,9 @@ it 'sets the o11y url from group settings' do services_page expect(response).to render_template(:show) - expect(assigns(:path)).to eq('services') - expect(assigns(:o11y_url)).to eq('https://observability.example.com') + expect(assigns(:data)).to be_a(Observability::ObservabilityPresenter) + expect(assigns(:data).to_h[:path]).to eq('services') + expect(assigns(:data).to_h[:o11y_url]).to eq('https://observability.example.com') end end @@ -63,12 +65,17 @@ it 'sets the o11y url to nil' do services_page expect(response).to render_template(:show) - expect(assigns(:path)).to eq('services') - expect(assigns(:o11y_url)).to be_nil + expect(assigns(:data)).to be_a(Observability::ObservabilityPresenter) + expect(assigns(:data).to_h[:path]).to eq('services') + expect(assigns(:data).to_h[:o11y_url]).to be_nil end end context 'with a valid path parameter' do + let!(:observability_setting) do + create(:observability_group_o11y_setting, group: group, o11y_service_url: 'https://o11y.gitlab.com') + end + Groups::ObservabilityController::VALID_PATHS.each do |path| context "with path=#{path}" do subject(:observability_page) { get group_observability_path(group, path) } @@ -77,7 +84,12 @@ observability_page expect(response).to have_gitlab_http_status(:ok) - expect(assigns(:path)).to eq(path) + expect(assigns(:data)).to be_a(Observability::ObservabilityPresenter) + expect(assigns(:data).to_h[:path]).to eq(path) + expect(assigns(:data).to_h[:o11y_url]).to eq('https://o11y.gitlab.com') + expect(assigns(:data).title).to eq(Observability::ObservabilityPresenter::PATHS.fetch(path, + 'Observability')) + expect(assigns(:data).auth_tokens).to eq({ 'test_token' => 'value' }) end end end @@ -154,6 +166,7 @@ group_with_different_o11y.add_maintainer(user) stub_feature_flags(observability_sass_features: group_with_different_o11y) create(:observability_group_o11y_setting, group: group_with_different_o11y, o11y_service_url: o11y_url_2) + allow(Observability::O11yToken).to receive(:generate_tokens).and_return({ 'testToken' => 'value' }) get group_observability_path(group_with_different_o11y, 'services') end