Commit dfd88084 authored by charlie ablett's avatar charlie ablett

Merge branch 'show-usage-data-download-only-if-cache-exists' into 'master'

Show usage data download only if cache exists

See merge request gitlab-org/gitlab!83490
parents 57c8d634 1e30c3fa
......@@ -53,6 +53,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
end
def service_usage_data
@service_ping_data_present = Rails.cache.exist?('usage_data')
end
def update
......
......@@ -7,10 +7,24 @@
%h3= name
%button.gl-button.btn.btn-default.js-payload-preview-trigger{ type: 'button', data: { payload_selector: ".#{payload_class}" } }
= gl_loading_icon(css_class: 'js-spinner gl-display-none gl-mr-2')
.js-text.gl-display-inline= _('Preview payload')
%button.gl-button.btn.btn-default.js-payload-download-trigger{ type: 'button', data: { endpoint: usage_data_admin_application_settings_path(format: :json) } }
= gl_loading_icon(css_class: 'js-spinner gl-display-none gl-mr-2')
.js-text.d-inline= _('Download payload')
%pre.js-syntax-highlight.code.highlight.gl-mt-2.gl-display-none{ class: payload_class, data: { endpoint: usage_data_admin_application_settings_path(format: :html) } }
- if @service_ping_data_present
%button.gl-button.btn.btn-default.js-payload-preview-trigger{ type: 'button', data: { payload_selector: ".#{payload_class}" } }
= gl_loading_icon(css_class: 'js-spinner gl-display-none gl-mr-2')
.js-text.gl-display-inline= _('Preview payload')
%button.gl-button.btn.btn-default.js-payload-download-trigger{ type: 'button', data: { endpoint: usage_data_admin_application_settings_path(format: :json) } }
= gl_loading_icon(css_class: 'js-spinner gl-display-none gl-mr-2')
.js-text.d-inline= _('Download payload')
%pre.js-syntax-highlight.code.highlight.gl-mt-2.gl-display-none{ class: payload_class, data: { endpoint: usage_data_admin_application_settings_path(format: :html) } }
- else
= render 'shared/global_alert',
variant: :warning,
dismissible: false,
title: 'Service Ping payload not found in the application cache' do
.gl-alert-body
- enable_service_ping_link_url = help_page_path('user/admin_area/settings/usage_statistics', anchor: 'enable-or-disable-usage-statistics')
- enable_service_ping_link = '<a href="%{url}">'.html_safe % { url: enable_service_ping_link_url }
- generate_manually_link_url = help_page_path('administration/troubleshooting/gitlab_rails_cheat_sheet', anchor: 'generate-service-ping')
- generate_manually_link = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: generate_manually_link_url }
= html_escape(s_('%{enable_service_ping_link_start}Enable%{link_end} or %{generate_manually_link_start}generate%{link_end} Service Ping to preview and download service usage data payload.')) % { enable_service_ping_link_start: enable_service_ping_link, generate_manually_link_start: generate_manually_link, link_end: '</a>'.html_safe }
......@@ -652,6 +652,9 @@ msgstr ""
msgid "%{emailPrefix}@company.com"
msgstr ""
msgid "%{enable_service_ping_link_start}Enable%{link_end} or %{generate_manually_link_start}generate%{link_end} Service Ping to preview and download service usage data payload."
msgstr ""
msgid "%{extra} more downstream pipelines"
msgstr ""
......
......@@ -854,31 +854,45 @@ RSpec.describe 'Admin updates settings' do
before do
stub_usage_data_connections
stub_database_flavor_check
visit service_usage_data_admin_application_settings_path
end
it 'loads usage ping payload on click', :js do
expected_payload_content = /(?=.*"uuid")(?=.*"hostname")/m
context 'when service data cached', :clean_gitlab_redis_cache do
before do
allow(Rails.cache).to receive(:exist?).with('usage_data').and_return(true)
expect(page).not_to have_content expected_payload_content
visit service_usage_data_admin_application_settings_path
end
it 'loads usage ping payload on click', :js do
expected_payload_content = /(?=.*"uuid")(?=.*"hostname")/m
click_button('Preview payload')
expect(page).not_to have_content expected_payload_content
wait_for_requests
click_button('Preview payload')
expect(page).to have_button 'Hide payload'
expect(page).to have_content expected_payload_content
end
wait_for_requests
it 'generates usage ping payload on button click', :js do
expect_next_instance_of(Admin::ApplicationSettingsController) do |instance|
expect(instance).to receive(:usage_data).and_call_original
expect(page).to have_button 'Hide payload'
expect(page).to have_content expected_payload_content
end
click_button('Download payload')
it 'generates usage ping payload on button click', :js do
expect_next_instance_of(Admin::ApplicationSettingsController) do |instance|
expect(instance).to receive(:usage_data).and_call_original
end
click_button('Download payload')
wait_for_requests
wait_for_requests
end
end
context 'when service data not cached' do
it 'renders missing cache information' do
visit service_usage_data_admin_application_settings_path
expect(page).to have_text('Service Ping payload not found in the application cache')
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