debian-mirror-gitlab/lib/gitlab/metrics/rails_slis.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

117 lines
4.3 KiB
Ruby
Raw Normal View History

2021-11-18 22:05:49 +05:30
# frozen_string_literal: true
module Gitlab
module Metrics
module RailsSlis
class << self
2022-04-04 11:22:00 +05:30
def initialize_request_slis!
2023-04-23 21:23:45 +05:30
request_labels = possible_request_labels
Gitlab::Metrics::Sli::Apdex.initialize_sli(:rails_request, request_labels)
Gitlab::Metrics::Sli::ErrorRate.initialize_sli(:rails_request, request_labels)
2022-07-16 23:28:13 +05:30
Gitlab::Metrics::Sli::Apdex.initialize_sli(:graphql_query, possible_graphql_query_labels)
2021-11-18 22:05:49 +05:30
end
def request_apdex
2022-07-16 23:28:13 +05:30
Gitlab::Metrics::Sli::Apdex[:rails_request]
2021-11-18 22:05:49 +05:30
end
2023-03-04 22:38:38 +05:30
def request_error_rate
Gitlab::Metrics::Sli::ErrorRate[:rails_request]
end
2021-12-11 22:18:48 +05:30
def graphql_query_apdex
2022-07-16 23:28:13 +05:30
Gitlab::Metrics::Sli::Apdex[:graphql_query]
2021-12-11 22:18:48 +05:30
end
2021-11-18 22:05:49 +05:30
private
2021-12-11 22:18:48 +05:30
def possible_graphql_query_labels
2023-04-23 21:23:45 +05:30
return [] unless Gitlab::Metrics::Environment.api?
2021-12-11 22:18:48 +05:30
::Gitlab::Graphql::KnownOperations.default.operations.map do |op|
{
endpoint_id: op.to_caller_id,
# We'll be able to correlate feature_category with https://gitlab.com/gitlab-org/gitlab/-/issues/328535
feature_category: nil,
query_urgency: op.query_urgency.name
}
end
end
2021-11-18 22:05:49 +05:30
def possible_request_labels
possible_controller_labels + possible_api_labels
end
2023-04-23 21:23:45 +05:30
def possible_controller_labels
all_controller_labels.select do |labelset|
if known_git_endpoints.include?(labelset[:endpoint_id])
Gitlab::Metrics::Environment.git?
else
Gitlab::Metrics::Environment.web?
end
end
end
2021-11-18 22:05:49 +05:30
def possible_api_labels
2023-04-23 21:23:45 +05:30
all_api_labels.select do |labelset|
if known_git_endpoints.include?(labelset[:endpoint_id])
Gitlab::Metrics::Environment.git?
else
Gitlab::Metrics::Environment.api?
end
end
end
def all_api_labels
2021-11-18 22:05:49 +05:30
Gitlab::RequestEndpoints.all_api_endpoints.map do |route|
endpoint_id = API::Base.endpoint_id_for_route(route)
route_class = route.app.options[:for]
feature_category = route_class.feature_category_for_app(route.app)
2021-12-11 22:18:48 +05:30
request_urgency = route_class.urgency_for_app(route.app)
2021-11-18 22:05:49 +05:30
{
endpoint_id: endpoint_id,
2021-12-11 22:18:48 +05:30
feature_category: feature_category,
request_urgency: request_urgency.name
2021-11-18 22:05:49 +05:30
}
end
end
2023-04-23 21:23:45 +05:30
def all_controller_labels
2021-11-18 22:05:49 +05:30
Gitlab::RequestEndpoints.all_controller_actions.map do |controller, action|
{
endpoint_id: controller.endpoint_id_for_action(action),
2021-12-11 22:18:48 +05:30
feature_category: controller.feature_category_for_action(action),
request_urgency: controller.urgency_for_action(action).name
2021-11-18 22:05:49 +05:30
}
end
end
2023-03-04 22:38:38 +05:30
2023-04-23 21:23:45 +05:30
def known_git_endpoints
# This is a list of endpoints that endpoints that HAProxy redirects
# to the git fleet for GitLab.com. It is taken from
# https://thanos-query.ops.gitlab.net/graph?g0.expr=sum%20by%20(endpoint_id)(sli_aggregations%3Agitlab_sli_rails_request_total_rate6h%7Btype%3D%22git%22%2C%20env%3D%22gprd%22%7D%20%3E%200)&g0.tab=1&g0.stacked=0&g0.range_input=1h&g0.max_source_resolution=0s&g0.deduplicate=1&g0.partial_response=0&g0.store_matches=%5B%5D
[
"GET /api/:version/internal/authorized_keys",
"GET /api/:version/internal/discover",
"POST /api/:version/internal/allowed",
"POST /api/:version/internal/lfs_authenticate",
"POST /api/:version/internal/two_factor_recovery_codes",
"ProjectsController#show",
"Repositories::GitHttpController#git_receive_pack",
"Repositories::GitHttpController#git_upload_pack",
"Repositories::GitHttpController#info_refs",
"Repositories::LfsApiController#batch",
"Repositories::LfsLocksApiController#index",
"Repositories::LfsLocksApiController#verify",
"Repositories::LfsStorageController#download",
"Repositories::LfsStorageController#upload_authorize",
"Repositories::LfsStorageController#upload_finalize"
]
2023-03-04 22:38:38 +05:30
end
2021-11-18 22:05:49 +05:30
end
end
end
end