From 357b26a28d9ce0a1b2e9b8d5fa1197c4a946b489 Mon Sep 17 00:00:00 2001 From: Hinam Mehra Date: Mon, 1 Sep 2025 17:23:54 +1000 Subject: [PATCH] Add external_dependencies attr to controller actions --- app/controllers/application_controller.rb | 4 ++++ lib/gitlab/endpoint_attributes.rb | 8 ++++++++ lib/gitlab/endpoint_attributes/config.rb | 2 +- lib/gitlab/metrics/rails_slis.rb | 15 +++++++++++++-- spec/lib/gitlab/endpoint_attributes_spec.rb | 7 +++++++ spec/lib/gitlab/metrics/rails_slis_spec.rb | 16 +++++++++++----- 6 files changed, 44 insertions(+), 8 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a209aed131b678..5c42e41c854578 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -166,6 +166,10 @@ def urgency self.class.urgency_for_action(action_name) end + def has_external_dependencies + self.class.has_external_dependencies_for_action(action_name) + end + protected def workhorse_excluded_content_types diff --git a/lib/gitlab/endpoint_attributes.rb b/lib/gitlab/endpoint_attributes.rb index 19a212f3aa41c9..0b3119e22db826 100644 --- a/lib/gitlab/endpoint_attributes.rb +++ b/lib/gitlab/endpoint_attributes.rb @@ -30,6 +30,14 @@ def urgency_for_action(action) urgency || superclass_urgency_for_action(action) || DEFAULT_URGENCY end + def has_external_dependencies(actions = []) + endpoint_attributes.set(actions, has_external_dependencies: true) + end + + def has_external_dependencies_for_action(action) + endpoint_attributes.attribute_for_action(action, :has_external_dependencies) || false + end + private def endpoint_attributes diff --git a/lib/gitlab/endpoint_attributes/config.rb b/lib/gitlab/endpoint_attributes/config.rb index 2bdd4256238c5a..0fe2dfb415571a 100644 --- a/lib/gitlab/endpoint_attributes/config.rb +++ b/lib/gitlab/endpoint_attributes/config.rb @@ -10,7 +10,7 @@ class Config RequestUrgency.new(:default, 1), RequestUrgency.new(:low, 5) ].index_by(&:name).freeze - SUPPORTED_ATTRIBUTES = %i[feature_category urgency].freeze + SUPPORTED_ATTRIBUTES = %i[feature_category urgency has_external_dependencies].freeze def initialize @default_attributes = {} diff --git a/lib/gitlab/metrics/rails_slis.rb b/lib/gitlab/metrics/rails_slis.rb index 4b1dd37011be30..b18a692bb84170 100644 --- a/lib/gitlab/metrics/rails_slis.rb +++ b/lib/gitlab/metrics/rails_slis.rb @@ -4,6 +4,9 @@ module Gitlab module Metrics module RailsSlis class << self + TRUE_LABEL = "yes" + FALSE_LABEL = "no" + def initialize_request_slis! request_labels = possible_request_labels Gitlab::Metrics::Sli::Apdex.initialize_sli(:rails_request, request_labels) @@ -83,7 +86,8 @@ def all_api_labels { endpoint_id: endpoint_id, feature_category: feature_category, - request_urgency: request_urgency.name + request_urgency: request_urgency.name, + external_dependencies: FALSE_LABEL } end end @@ -93,7 +97,10 @@ def all_controller_labels { endpoint_id: controller.endpoint_id_for_action(action), feature_category: controller.feature_category_for_action(action), - request_urgency: controller.urgency_for_action(action).name + request_urgency: controller.urgency_for_action(action).name, + external_dependencies: bool_as_label( + controller.has_external_dependencies_for_action(action) + ) } end end @@ -126,6 +133,10 @@ def uninitialized_endpoints File.read(Rails.root.join("lib/gitlab/metrics/rails_slis_uninitialized_endpoints.yml")) )) end + + def bool_as_label(value) + value ? TRUE_LABEL : FALSE_LABEL + end end end end diff --git a/spec/lib/gitlab/endpoint_attributes_spec.rb b/spec/lib/gitlab/endpoint_attributes_spec.rb index 34f4221b86acda..ab2ea2c32e3120 100644 --- a/spec/lib/gitlab/endpoint_attributes_spec.rb +++ b/spec/lib/gitlab/endpoint_attributes_spec.rb @@ -17,6 +17,8 @@ urgency :high, %w[do_a] urgency :low, %w[do_b do_c] + + has_external_dependencies %w[destroy] end end @@ -128,4 +130,9 @@ end end.to raise_error(ArgumentError, "Urgency not supported: super_slow") end + + it 'returns expected has_external_dependencies boolean' do + expect(controller.has_external_dependencies_for_action("hello")).to be(false) + expect(controller.has_external_dependencies_for_action("destroy")).to be(true) + end end diff --git a/spec/lib/gitlab/metrics/rails_slis_spec.rb b/spec/lib/gitlab/metrics/rails_slis_spec.rb index ef524f40c49367..701124586d260a 100644 --- a/spec/lib/gitlab/metrics/rails_slis_spec.rb +++ b/spec/lib/gitlab/metrics/rails_slis_spec.rb @@ -13,7 +13,8 @@ [{ endpoint_id: "Admin::AbuseReportsController#index", feature_category: :insider_threat, - request_urgency: :default + request_urgency: :default, + external_dependencies: "no" }] end @@ -22,7 +23,8 @@ { endpoint_id: "ProjectsController#index", feature_category: :groups_and_projects, - request_urgency: :default + request_urgency: :default, + external_dependencies: "no" } ] end @@ -43,9 +45,12 @@ let(:api_uninitialized_labels) do [ - { endpoint_id: "DELETE /api/:version/admin/ci/variables/:key", + { + endpoint_id: "DELETE /api/:version/admin/ci/variables/:key", feature_category: :pipeline_composition, - request_urgency: :default } + request_urgency: :default, + external_dependencies: "no" + } ] end @@ -53,7 +58,8 @@ [{ endpoint_id: "GET /api/:version/version", feature_category: :not_owned, - request_urgency: :default + request_urgency: :default, + external_dependencies: "no" }] end -- GitLab