diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-08 09:07:53 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-08 09:07:53 +0000 |
commit | a821bd6ad17e304ca93838a411410a44ee9cff9f (patch) | |
tree | 5444ab20a2f8b22db736a93c5c376928dde8e450 /app | |
parent | f6e985dba4d0f5b1ede95e9174d30dd6a8bedf0d (diff) | |
download | gitlab-ce-a821bd6ad17e304ca93838a411410a44ee9cff9f.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/contextual_sidebar.js | 17 | ||||
-rw-r--r-- | app/controllers/admin/application_settings_controller.rb | 67 | ||||
-rw-r--r-- | app/controllers/projects/prometheus/metrics_controller.rb | 2 | ||||
-rw-r--r-- | app/helpers/application_settings_helper.rb | 16 | ||||
-rw-r--r-- | app/models/deployment_metrics.rb | 12 | ||||
-rw-r--r-- | app/models/environment.rb | 4 | ||||
-rw-r--r-- | app/services/prometheus/adapter_service.rb | 30 |
7 files changed, 94 insertions, 54 deletions
diff --git a/app/assets/javascripts/contextual_sidebar.js b/app/assets/javascripts/contextual_sidebar.js index f43b6f3d777..51879f280e0 100644 --- a/app/assets/javascripts/contextual_sidebar.js +++ b/app/assets/javascripts/contextual_sidebar.js @@ -1,13 +1,9 @@ import $ from 'jquery'; import Cookies from 'js-cookie'; import _ from 'underscore'; -import bp from './breakpoints'; +import { GlBreakpointInstance as bp, breakpoints } from '@gitlab/ui/dist/utils'; import { parseBoolean } from '~/lib/utils/common_utils'; -// NOTE: at 1200px nav sidebar should not overlap the content -// https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/24555#note_134136110 -const NAV_SIDEBAR_BREAKPOINT = 1200; - export const SIDEBAR_COLLAPSED_CLASS = 'js-sidebar-collapsed'; export default class ContextualSidebar { @@ -50,9 +46,10 @@ export default class ContextualSidebar { $(window).on('resize', () => _.debounce(this.render(), 100)); } - // TODO: use the breakpoints from breakpoints.js once they have been updated for bootstrap 4 // See documentation: https://design.gitlab.com/regions/navigation#contextual-navigation - static isDesktopBreakpoint = () => bp.windowWidth() >= NAV_SIDEBAR_BREAKPOINT; + // NOTE: at 1200px nav sidebar should not overlap the content + // https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/24555#note_134136110 + static isDesktopBreakpoint = () => bp.windowWidth() >= breakpoints.xl; static setCollapsedCookie(value) { if (!ContextualSidebar.isDesktopBreakpoint()) { return; @@ -63,12 +60,13 @@ export default class ContextualSidebar { toggleSidebarNav(show) { const breakpoint = bp.getBreakpointSize(); const dbp = ContextualSidebar.isDesktopBreakpoint(); + const supportedSizes = ['xs', 'sm', 'md']; this.$sidebar.toggleClass(SIDEBAR_COLLAPSED_CLASS, !show); this.$sidebar.toggleClass('sidebar-expanded-mobile', !dbp ? show : false); this.$overlay.toggleClass( 'mobile-nav-open', - breakpoint === 'xs' || breakpoint === 'sm' ? show : false, + supportedSizes.includes(breakpoint) ? show : false, ); this.$sidebar.removeClass('sidebar-collapsed-desktop'); } @@ -76,13 +74,14 @@ export default class ContextualSidebar { toggleCollapsedSidebar(collapsed, saveCookie) { const breakpoint = bp.getBreakpointSize(); const dbp = ContextualSidebar.isDesktopBreakpoint(); + const supportedSizes = ['xs', 'sm', 'md']; if (this.$sidebar.length) { this.$sidebar.toggleClass(`sidebar-collapsed-desktop ${SIDEBAR_COLLAPSED_CLASS}`, collapsed); this.$sidebar.toggleClass('sidebar-expanded-mobile', !dbp ? !collapsed : false); this.$page.toggleClass( 'page-with-icon-sidebar', - breakpoint === 'xs' || breakpoint === 'sm' ? true : collapsed, + supportedSizes.includes(breakpoint) ? true : collapsed, ); } diff --git a/app/controllers/admin/application_settings_controller.rb b/app/controllers/admin/application_settings_controller.rb index 9d81d3fad07..58f088c6335 100644 --- a/app/controllers/admin/application_settings_controller.rb +++ b/app/controllers/admin/application_settings_controller.rb @@ -6,10 +6,21 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController before_action :set_application_setting before_action :whitelist_query_limiting, only: [:usage_data] + before_action do + push_frontend_feature_flag(:self_monitoring_project) + end + VALID_SETTING_PANELS = %w(general integrations repository ci_cd reporting metrics_and_profiling network preferences).freeze + # The current size of a sidekiq job's jid is 24 characters. The size of the + # jid is an internal detail of Sidekiq, and they do not guarantee that it'll + # stay the same. We chose 50 to give us room in case the size of the jid + # increases. The jid is alphanumeric, so 50 is very generous. There is a spec + # that ensures that the constant value is more than the size of an actual jid. + PARAM_JOB_ID_MAX_SIZE = 50 + VALID_SETTING_PANELS.each do |action| define_method(action) { perform_update if submitted? } end @@ -62,8 +73,64 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController redirect_to ::Gitlab::LetsEncrypt.terms_of_service_url end + def create_self_monitoring_project + return self_monitoring_project_not_implemented unless Feature.enabled?(:self_monitoring_project) + + job_id = SelfMonitoringProjectCreateWorker.perform_async + + render status: :accepted, json: { + job_id: job_id, + monitor_status: status_create_self_monitoring_project_admin_application_settings_path + } + end + + def status_create_self_monitoring_project + return self_monitoring_project_not_implemented unless Feature.enabled?(:self_monitoring_project) + + job_id = params[:job_id].to_s + + unless job_id.length <= PARAM_JOB_ID_MAX_SIZE + return render status: :bad_request, json: { + message: _('Parameter "job_id" cannot exceed length of %{job_id_max_size}' % + { job_id_max_size: PARAM_JOB_ID_MAX_SIZE }) + } + end + + if Gitlab::CurrentSettings.instance_administration_project_id.present? + render status: :ok, json: self_monitoring_data + + elsif SelfMonitoringProjectCreateWorker.in_progress?(job_id) + ::Gitlab::PollingInterval.set_header(response, interval: 3_000) + + render status: :accepted, json: { message: _('Job is in progress') } + + else + render status: :bad_request, json: { + message: _('Self-monitoring project does not exist. Please check logs ' \ + 'for any error messages') + } + end + end + private + def self_monitoring_data + { + project_id: Gitlab::CurrentSettings.instance_administration_project_id, + project_full_path: Gitlab::CurrentSettings.instance_administration_project&.full_path + } + end + + def self_monitoring_project_not_implemented + render( + status: :not_implemented, + json: { + message: _('Self-monitoring is not enabled on this GitLab server, contact your administrator.'), + documentation_url: help_page_path('administration/monitoring/gitlab_instance_administration_project/index') + } + ) + end + def set_application_setting @application_setting = ApplicationSetting.current_without_cache end diff --git a/app/controllers/projects/prometheus/metrics_controller.rb b/app/controllers/projects/prometheus/metrics_controller.rb index f212ae52ecc..c9c7ba1253f 100644 --- a/app/controllers/projects/prometheus/metrics_controller.rb +++ b/app/controllers/projects/prometheus/metrics_controller.rb @@ -23,7 +23,7 @@ module Projects private def prometheus_adapter - @prometheus_adapter ||= ::Prometheus::AdapterService.new(project, project.deployment_platform&.cluster).prometheus_adapter + @prometheus_adapter ||= ::Gitlab::Prometheus::Adapter.new(project, project.deployment_platform&.cluster).prometheus_adapter end def require_prometheus_metrics! diff --git a/app/helpers/application_settings_helper.rb b/app/helpers/application_settings_helper.rb index 71e4195c50f..d9a91f72dca 100644 --- a/app/helpers/application_settings_helper.rb +++ b/app/helpers/application_settings_helper.rb @@ -334,6 +334,22 @@ module ApplicationSettingsHelper def omnibus_protected_paths_throttle? Rack::Attack.throttles.key?('protected paths') end + + def self_monitoring_project_data + { + 'create_self_monitoring_project_path' => + create_self_monitoring_project_admin_application_settings_path, + + 'status_create_self_monitoring_project_path' => + status_create_self_monitoring_project_admin_application_settings_path, + + 'self_monitoring_project_exists' => + Gitlab::CurrentSettings.instance_administration_project.present?, + + 'self_monitoring_project_full_path' => + Gitlab::CurrentSettings.instance_administration_project&.full_path + } + end end ApplicationSettingsHelper.prepend_if_ee('EE::ApplicationSettingsHelper') # rubocop: disable Cop/InjectEnterpriseEditionModule diff --git a/app/models/deployment_metrics.rb b/app/models/deployment_metrics.rb index 20f0ec3e9b6..c5f8b03f25b 100644 --- a/app/models/deployment_metrics.rb +++ b/app/models/deployment_metrics.rb @@ -34,20 +34,10 @@ class DeploymentMetrics def prometheus_adapter strong_memoize(:prometheus_adapter) do - service = project.find_or_initialize_service('prometheus') - - if service.can_query? - service - else - cluster_prometheus - end + Gitlab::Prometheus::Adapter.new(project, cluster).prometheus_adapter end end - def cluster_prometheus - cluster.application_prometheus if cluster&.application_prometheus_available? - end - def has_metrics_and_can_query? has_metrics? && prometheus_adapter.can_query? end diff --git a/app/models/environment.rb b/app/models/environment.rb index d54050cd156..2d480345b5a 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -225,11 +225,9 @@ class Environment < ApplicationRecord prometheus_adapter.query(:additional_metrics_environment, self, *args.map(&:to_f)) end - # rubocop: disable CodeReuse/ServiceClass def prometheus_adapter - @prometheus_adapter ||= Prometheus::AdapterService.new(project, deployment_platform&.cluster).prometheus_adapter + @prometheus_adapter ||= Gitlab::Prometheus::Adapter.new(project, deployment_platform&.cluster).prometheus_adapter end - # rubocop: enable CodeReuse/ServiceClass def slug super.presence || generate_slug diff --git a/app/services/prometheus/adapter_service.rb b/app/services/prometheus/adapter_service.rb deleted file mode 100644 index 5e8357a83f6..00000000000 --- a/app/services/prometheus/adapter_service.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -module Prometheus - class AdapterService - attr_reader :project, :cluster - - def initialize(project, cluster) - @project = project - @cluster = cluster - end - - def prometheus_adapter - @prometheus_adapter ||= if service_prometheus_adapter.can_query? - service_prometheus_adapter - else - cluster_prometheus_adapter - end - end - - def service_prometheus_adapter - project.find_or_initialize_service('prometheus') - end - - def cluster_prometheus_adapter - application = cluster&.application_prometheus - - application if application&.available? - end - end -end |