Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-08-31 15:13:01 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-08-31 15:13:01 +0300
commit3034c7e6aa99d21c3d9fa1df01f60fdd3f32d914 (patch)
tree424f5a291abf1a93ff9870667ecb301b899972fc /lib/gitlab/metrics
parent6170bdc060501ecf6f817a530b3dc9f2e39ad4c3 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/metrics')
-rw-r--r--lib/gitlab/metrics/global_search_slis.rb101
1 files changed, 101 insertions, 0 deletions
diff --git a/lib/gitlab/metrics/global_search_slis.rb b/lib/gitlab/metrics/global_search_slis.rb
new file mode 100644
index 00000000000..c9e1700b253
--- /dev/null
+++ b/lib/gitlab/metrics/global_search_slis.rb
@@ -0,0 +1,101 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Metrics
+ module GlobalSearchSlis
+ class << self
+ # The following targets are the 99.95th percentile of code searches
+ # gathered on 24-08-2022
+ # from https://log.gprd.gitlab.net/goto/0c89cd80-23af-11ed-8656-f5f2137823ba (internal only)
+ BASIC_CONTENT_TARGET_S = 7.031
+ BASIC_CODE_TARGET_S = 21.903
+ ADVANCED_CONTENT_TARGET_S = 4.865
+ ADVANCED_CODE_TARGET_S = 13.546
+
+ def initialize_slis!
+ return unless Feature.enabled?(:global_search_custom_slis)
+
+ Gitlab::Metrics::Sli::Apdex.initialize_sli(:global_search, possible_labels)
+ end
+
+ def record_apdex(elapsed:, search_type:, search_level:, search_scope:)
+ return unless Feature.enabled?(:global_search_custom_slis)
+
+ Gitlab::Metrics::Sli::Apdex[:global_search].increment(
+ labels: labels(search_type: search_type, search_level: search_level, search_scope: search_scope),
+ success: elapsed < duration_target(search_type, search_scope)
+ )
+ end
+
+ private
+
+ def duration_target(search_type, search_scope)
+ if search_type == 'basic' && content_search?(search_scope)
+ BASIC_CONTENT_TARGET_S
+ elsif search_type == 'basic' && code_search?(search_scope)
+ BASIC_CODE_TARGET_S
+ elsif search_type == 'advanced' && content_search?(search_scope)
+ ADVANCED_CONTENT_TARGET_S
+ elsif search_type == 'advanced' && code_search?(search_scope)
+ ADVANCED_CODE_TARGET_S
+ end
+ end
+
+ def search_types
+ %w[basic advanced]
+ end
+
+ def search_levels
+ %w[project group global]
+ end
+
+ def search_scopes
+ Gitlab::Search::AbuseDetection::ALLOWED_SCOPES
+ end
+
+ def endpoint_ids
+ ['SearchController#show', 'GET /api/:version/search', 'GET /api/:version/projects/:id/(-/)search',
+ 'GET /api/:version/groups/:id/(-/)search']
+ end
+
+ def possible_labels
+ search_types.flat_map do |search_type|
+ search_levels.flat_map do |search_level|
+ search_scopes.flat_map do |search_scope|
+ endpoint_ids.flat_map do |endpoint_id|
+ {
+ search_type: search_type,
+ search_level: search_level,
+ search_scope: search_scope,
+ endpoint_id: endpoint_id
+ }
+ end
+ end
+ end
+ end
+ end
+
+ def labels(search_type:, search_level:, search_scope:)
+ {
+ search_type: search_type,
+ search_level: search_level,
+ search_scope: search_scope,
+ endpoint_id: endpoint_id
+ }
+ end
+
+ def endpoint_id
+ ::Gitlab::ApplicationContext.current_context_attribute(:caller_id)
+ end
+
+ def code_search?(search_scope)
+ search_scope == 'blobs'
+ end
+
+ def content_search?(search_scope)
+ !code_search?(search_scope)
+ end
+ end
+ end
+ end
+end