Commit 640a26ff authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'initialize-fewer-metrics' into 'master'

Only initialise metrics for the most common feature categories

See merge request gitlab-org/gitlab!46558
parents 152d17d6 3a300898
......@@ -18,6 +18,15 @@ module Gitlab
FEATURE_CATEGORY_HEADER = 'X-Gitlab-Feature-Category'
FEATURE_CATEGORY_DEFAULT = 'unknown'
# These were the top 5 categories at a point in time, chosen as a
# reasonable default. If we initialize every category we'll end up
# with an explosion in unused metric combinations, but we want the
# most common ones to be always present.
FEATURE_CATEGORIES_TO_INITIALIZE = ['authentication_and_authorization',
'code_review', 'continuous_integration',
'not_owned', 'source_code_management',
FEATURE_CATEGORY_DEFAULT].freeze
def initialize(app)
@app = app
end
......@@ -46,16 +55,10 @@ module Gitlab
#
# For example `rate(http_requests_total{status="500"}[1m])` would return
# no data until the first 500 error would occur.
# The list of feature categories is currently not needed by the application
# anywhere else. So no need to keep these in memory forever.
# Doing it here, means we're only reading the file on boot.
feature_categories = YAML.load_file(Rails.root.join('config', 'feature_categories.yml')).map(&:strip).uniq << FEATURE_CATEGORY_DEFAULT
HTTP_METHODS.each do |method, statuses|
http_request_duration_seconds.get({ method: method })
statuses.product(feature_categories) do |status, feature_category|
statuses.product(FEATURE_CATEGORIES_TO_INITIALIZE) do |status, feature_category|
http_requests_total.get({ method: method, status: status, feature_category: feature_category })
end
end
......
......@@ -129,12 +129,11 @@ RSpec.describe Gitlab::Metrics::RequestsRackMiddleware, :aggregate_failures do
describe '.initialize_metrics', :prometheus do
it "sets labels for http_requests_total" do
feature_categories = YAML.load_file(Rails.root.join('config', 'feature_categories.yml')).map(&:strip) << described_class::FEATURE_CATEGORY_DEFAULT
expected_labels = []
described_class::HTTP_METHODS.each do |method, statuses|
statuses.each do |status|
feature_categories.each do |feature_category|
described_class::FEATURE_CATEGORIES_TO_INITIALIZE.each do |feature_category|
expected_labels << { method: method.to_s, status: status.to_s, feature_category: feature_category.to_s }
end
end
......@@ -152,6 +151,13 @@ RSpec.describe Gitlab::Metrics::RequestsRackMiddleware, :aggregate_failures do
expect(described_class.http_request_duration_seconds.values.keys).to include(*expected_labels)
end
it 'has every label in config/feature_categories.yml' do
defaults = [described_class::FEATURE_CATEGORY_DEFAULT, 'not_owned']
feature_categories = YAML.load_file(Rails.root.join('config', 'feature_categories.yml')).map(&:strip) + defaults
expect(described_class::FEATURE_CATEGORIES_TO_INITIALIZE).to all(be_in(feature_categories))
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment