diff options
| author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-20 18:08:30 +0000 |
|---|---|---|
| committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-20 18:08:30 +0000 |
| commit | 4faa270685797bd689d2035efe7c7e724950eb82 (patch) | |
| tree | 880f35cfcb4ef5dad3c82f701937d27d5cc85389 /lib | |
| parent | da23c5d563d68bfa5271b216209a7715c7ce3073 (diff) | |
| download | gitlab-ce-4faa270685797bd689d2035efe7c7e724950eb82.tar.gz | |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/api/terraform/state.rb | 19 | ||||
| -rw-r--r-- | lib/banzai/reference_parser/user_parser.rb | 2 | ||||
| -rw-r--r-- | lib/gitlab/metrics/sidekiq_slis.rb | 39 | ||||
| -rw-r--r-- | lib/gitlab/sidekiq_middleware/server_metrics.rb | 13 | ||||
| -rw-r--r-- | lib/gitlab/workhorse.rb | 9 | ||||
| -rw-r--r-- | lib/sidebars/menu_item.rb | 3 | ||||
| -rw-r--r-- | lib/sidebars/projects/menus/issues_menu.rb | 1 | ||||
| -rw-r--r-- | lib/sidebars/projects/menus/repository_menu.rb | 4 |
8 files changed, 84 insertions, 6 deletions
diff --git a/lib/api/terraform/state.rb b/lib/api/terraform/state.rb index 8017a195f28..184690f9979 100644 --- a/lib/api/terraform/state.rb +++ b/lib/api/terraform/state.rb @@ -55,6 +55,17 @@ module API def remote_state_handler ::Terraform::RemoteStateHandler.new(user_project, current_user, name: params[:name], lock_id: params[:ID]) end + + def not_found_for_dots? + Feature.disabled?(:allow_dots_on_tf_state_names) && params[:name].include?(".") + end + + # Change the state name to behave like before, https://gitlab.com/gitlab-org/gitlab/-/merge_requests/105674 + # has been introduced. This behavior can be controlled via `allow_dots_on_tf_state_names` FF. + # See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/106861 + def legacy_state_name! + params[:name] = params[:name].split('.').first + end end desc 'Get a Terraform state by its name' do @@ -72,6 +83,8 @@ module API end route_setting :authentication, basic_auth_personal_access_token: true, job_token_allowed: :basic_auth get do + legacy_state_name! if not_found_for_dots? + remote_state_handler.find_with_lock do |state| no_content! unless state.latest_file && state.latest_file.exists? @@ -96,6 +109,7 @@ module API route_setting :authentication, basic_auth_personal_access_token: true, job_token_allowed: :basic_auth post do authorize! :admin_terraform_state, user_project + legacy_state_name! if not_found_for_dots? data = request.body.read no_content! if data.empty? @@ -124,6 +138,7 @@ module API route_setting :authentication, basic_auth_personal_access_token: true, job_token_allowed: :basic_auth delete do authorize! :admin_terraform_state, user_project + legacy_state_name! if not_found_for_dots? remote_state_handler.find_with_lock do |state| ::Terraform::States::TriggerDestroyService.new(state, current_user: current_user).execute @@ -155,6 +170,8 @@ module API requires :Path, type: String, desc: 'Terraform path' end post '/lock' do + not_found! if not_found_for_dots? + authorize! :admin_terraform_state, user_project status_code = :ok @@ -198,6 +215,8 @@ module API optional :ID, type: String, limit: 255, desc: 'Terraform state lock ID' end delete '/lock' do + not_found! if not_found_for_dots? + authorize! :admin_terraform_state, user_project remote_state_handler.unlock! diff --git a/lib/banzai/reference_parser/user_parser.rb b/lib/banzai/reference_parser/user_parser.rb index c40ca9dc7cd..48e2bcc9a11 100644 --- a/lib/banzai/reference_parser/user_parser.rb +++ b/lib/banzai/reference_parser/user_parser.rb @@ -81,7 +81,7 @@ module Banzai project = projects[node] user = users[node] - project && user ? project.team.member?(user) : false + project&.member?(user) else true end diff --git a/lib/gitlab/metrics/sidekiq_slis.rb b/lib/gitlab/metrics/sidekiq_slis.rb new file mode 100644 index 00000000000..f28cf4ac967 --- /dev/null +++ b/lib/gitlab/metrics/sidekiq_slis.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +module Gitlab + module Metrics + module SidekiqSlis + EXECUTION_URGENCY_DURATIONS = { + "high" => 10, + "low" => 300, + "throttled" => 300 + }.freeze + # workers without urgency attribute have "low" urgency by default in + # WorkerAttributes.get_urgency, just mirroring it here + DEFAULT_EXECUTION_URGENCY_DURATION = EXECUTION_URGENCY_DURATIONS["low"] + + class << self + def initialize_slis!(possible_labels) + Gitlab::Metrics::Sli::Apdex.initialize_sli(:sidekiq_execution, possible_labels) + Gitlab::Metrics::Sli::ErrorRate.initialize_sli(:sidekiq_execution, possible_labels) + end + + def record_execution_apdex(labels, job_completion_duration) + urgency_requirement = execution_duration_for_urgency(labels[:urgency]) + Gitlab::Metrics::Sli::Apdex[:sidekiq_execution].increment( + labels: labels, + success: job_completion_duration < urgency_requirement + ) + end + + def record_execution_error(labels, error) + Gitlab::Metrics::Sli::ErrorRate[:sidekiq_execution].increment(labels: labels, error: error) + end + + def execution_duration_for_urgency(urgency) + EXECUTION_URGENCY_DURATIONS.fetch(urgency, DEFAULT_EXECUTION_URGENCY_DURATION) + end + end + end + end +end diff --git a/lib/gitlab/sidekiq_middleware/server_metrics.rb b/lib/gitlab/sidekiq_middleware/server_metrics.rb index e36f61be3b3..b3c3c94a0a3 100644 --- a/lib/gitlab/sidekiq_middleware/server_metrics.rb +++ b/lib/gitlab/sidekiq_middleware/server_metrics.rb @@ -17,6 +17,9 @@ module Gitlab SIDEKIQ_JOB_DURATION_BUCKETS = [10, 300].freeze SIDEKIQ_QUEUE_DURATION_BUCKETS = [10, 60].freeze + # These labels from Gitlab::SidekiqMiddleware::MetricsHelper are included in SLI metrics + SIDEKIQ_SLI_LABELS = [:worker, :feature_category, :urgency].freeze + class << self include ::Gitlab::SidekiqMiddleware::MetricsHelper @@ -47,17 +50,21 @@ module Gitlab return unless ::Feature.enabled?(:sidekiq_job_completion_metric_initialize) + possible_sli_labels = [] ::Gitlab::SidekiqConfig.current_worker_queue_mappings.each do |worker, queue| worker_class = worker.safe_constantize next unless worker_class base_labels = create_labels(worker_class, queue, {}) + possible_sli_labels << base_labels.slice(*SIDEKIQ_SLI_LABELS) %w[done fail].each do |status| metrics[:sidekiq_jobs_completion_seconds].get(base_labels.merge(job_status: status)) end end + + Gitlab::Metrics::SidekiqSlis.initialize_slis!(possible_sli_labels) if ::Feature.enabled?(:sidekiq_execution_application_slis) end end @@ -134,6 +141,12 @@ module Gitlab @metrics[:sidekiq_load_balancing_count].increment(labels.merge(load_balancing_labels), 1) end + + if ::Feature.enabled?(:sidekiq_execution_application_slis) + sli_labels = labels.slice(*SIDEKIQ_SLI_LABELS) + Gitlab::Metrics::SidekiqSlis.record_execution_apdex(sli_labels, monotonic_time) if job_succeeded + Gitlab::Metrics::SidekiqSlis.record_execution_error(sli_labels, !job_succeeded) + end end end diff --git a/lib/gitlab/workhorse.rb b/lib/gitlab/workhorse.rb index 02418c45e73..79131404465 100644 --- a/lib/gitlab/workhorse.rb +++ b/lib/gitlab/workhorse.rb @@ -156,11 +156,14 @@ module Gitlab ] end - def send_url(url, allow_redirects: false) + def send_url(url, allow_redirects: false, method: 'GET', body: nil, headers: nil) params = { 'URL' => url, - 'AllowRedirects' => allow_redirects - } + 'AllowRedirects' => allow_redirects, + 'Body' => body.to_s, + 'Header' => headers, + 'Method' => method + }.compact [ SEND_DATA_HEADER, diff --git a/lib/sidebars/menu_item.rb b/lib/sidebars/menu_item.rb index bc10c4fb257..227a6970b2c 100644 --- a/lib/sidebars/menu_item.rb +++ b/lib/sidebars/menu_item.rb @@ -38,7 +38,8 @@ module Sidebars icon: sprite_icon, link: link, active_routes: active_routes, - pill_count: has_pill ? pill_count : nil + pill_count: has_pill ? pill_count : nil, + link_classes: container_html_options[:class] # Check whether support is needed for the following properties, # in order to get feature parity with the HAML renderer # https://gitlab.com/gitlab-org/gitlab/-/issues/391864 diff --git a/lib/sidebars/projects/menus/issues_menu.rb b/lib/sidebars/projects/menus/issues_menu.rb index 38eab0e3b68..dd5d4458fbb 100644 --- a/lib/sidebars/projects/menus/issues_menu.rb +++ b/lib/sidebars/projects/menus/issues_menu.rb @@ -113,6 +113,7 @@ module Sidebars link: project_boards_path(context.project), super_sidebar_parent: ::Sidebars::Projects::SuperSidebarMenus::PlanMenu, active_routes: { controller: :boards }, + container_html_options: { class: 'shortcuts-issue-boards' }, item_id: :boards ) end diff --git a/lib/sidebars/projects/menus/repository_menu.rb b/lib/sidebars/projects/menus/repository_menu.rb index 157dd379ed7..22f7b553884 100644 --- a/lib/sidebars/projects/menus/repository_menu.rb +++ b/lib/sidebars/projects/menus/repository_menu.rb @@ -57,6 +57,7 @@ module Sidebars link: project_tree_path(context.project, context.current_ref), super_sidebar_parent: ::Sidebars::Projects::SuperSidebarMenus::CodeMenu, active_routes: { controller: %w[tree blob blame edit_tree new_tree find_file] }, + container_html_options: { class: 'shortcuts-tree' }, item_id: :files ) end @@ -70,7 +71,7 @@ module Sidebars super_sidebar_parent: ::Sidebars::Projects::SuperSidebarMenus::CodeMenu, active_routes: { controller: %w(commit commits) }, item_id: :commits, - container_html_options: { id: 'js-onboarding-commits-link' } + container_html_options: { id: 'js-onboarding-commits-link', class: 'shortcuts-commits' } ) end @@ -117,6 +118,7 @@ module Sidebars link: link, super_sidebar_parent: ::Sidebars::Projects::SuperSidebarMenus::CodeMenu, active_routes: { controller: :network }, + container_html_options: { class: 'shortcuts-network' }, item_id: :graphs ) end |
