diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a209aed131b67880fb37bb3c62eab78223c66768..5c42e41c8545783fb336e9d6765e88cb12ddaeca 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 19a212f3aa41c9203afc3755f39100a9a7c81fc5..0b3119e22db826c5912197caba1ef53e6886f322 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 2bdd4256238c5ad6c92faece173caccdcef79931..0fe2dfb415571a0bd1fa8961a2adeb102ba2efd8 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 4b1dd37011be305c956ff966d7e2b8e3ccdb4652..b18a692bb84170b121bb0fe227a24d9c4a0761fd 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 34f4221b86acdae23315612bbd55543ace229f00..ab2ea2c32e312010148377f045dbe608703f87e6 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 ef524f40c49367cda48eca849013d9acdbbc414a..701124586d260a53858eb0aa3c0b59a3eb615463 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