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:
Diffstat (limited to 'spec/lib/gitlab/metrics')
-rw-r--r--spec/lib/gitlab/metrics/dashboard/finder_spec.rb6
-rw-r--r--spec/lib/gitlab/metrics/dashboard/service_selector_spec.rb2
-rw-r--r--spec/lib/gitlab/metrics/dashboard/url_spec.rb2
-rw-r--r--spec/lib/gitlab/metrics/global_search_slis_spec.rb8
-rw-r--r--spec/lib/gitlab/metrics/loose_foreign_keys_slis_spec.rb81
-rw-r--r--spec/lib/gitlab/metrics/method_call_spec.rb47
-rw-r--r--spec/lib/gitlab/metrics/samplers/ruby_sampler_spec.rb20
-rw-r--r--spec/lib/gitlab/metrics/system_spec.rb25
8 files changed, 138 insertions, 53 deletions
diff --git a/spec/lib/gitlab/metrics/dashboard/finder_spec.rb b/spec/lib/gitlab/metrics/dashboard/finder_spec.rb
index 730a31346d7..f922eff2980 100644
--- a/spec/lib/gitlab/metrics/dashboard/finder_spec.rb
+++ b/spec/lib/gitlab/metrics/dashboard/finder_spec.rb
@@ -44,7 +44,7 @@ RSpec.describe Gitlab::Metrics::Dashboard::Finder, :use_clean_rails_memory_store
it_behaves_like 'valid dashboard service response'
end
- context 'when the self monitoring dashboard is specified' do
+ context 'when the self-monitoring dashboard is specified' do
let(:dashboard_path) { self_monitoring_dashboard_path }
it_behaves_like 'valid dashboard service response'
@@ -181,7 +181,7 @@ RSpec.describe Gitlab::Metrics::Dashboard::Finder, :use_clean_rails_memory_store
end
end
- context 'when the project is self monitoring' do
+ context 'when the project is self-monitoring' do
let(:self_monitoring_dashboard) do
{
path: self_monitoring_dashboard_path,
@@ -199,7 +199,7 @@ RSpec.describe Gitlab::Metrics::Dashboard::Finder, :use_clean_rails_memory_store
stub_application_setting(self_monitoring_project_id: project.id)
end
- it 'includes self monitoring and project dashboards' do
+ it 'includes self-monitoring and project dashboards' do
project_dashboard = {
path: dashboard_path,
display_name: 'test.yml',
diff --git a/spec/lib/gitlab/metrics/dashboard/service_selector_spec.rb b/spec/lib/gitlab/metrics/dashboard/service_selector_spec.rb
index f3c8209e0b6..b41b51f53c3 100644
--- a/spec/lib/gitlab/metrics/dashboard/service_selector_spec.rb
+++ b/spec/lib/gitlab/metrics/dashboard/service_selector_spec.rb
@@ -30,7 +30,7 @@ RSpec.describe Gitlab::Metrics::Dashboard::ServiceSelector do
end
end
- context 'when the path is for the self monitoring dashboard' do
+ context 'when the path is for the self-monitoring dashboard' do
let(:arguments) { { dashboard_path: self_monitoring_dashboard_path } }
it { is_expected.to be Metrics::Dashboard::SelfMonitoringDashboardService }
diff --git a/spec/lib/gitlab/metrics/dashboard/url_spec.rb b/spec/lib/gitlab/metrics/dashboard/url_spec.rb
index 830d43169a9..d49200f87cc 100644
--- a/spec/lib/gitlab/metrics/dashboard/url_spec.rb
+++ b/spec/lib/gitlab/metrics/dashboard/url_spec.rb
@@ -61,7 +61,7 @@ RSpec.describe Gitlab::Metrics::Dashboard::Url do
'url' => url,
'namespace' => 'namespace1',
'project' => 'project1',
- 'environment' => "#{environment_id}",
+ 'environment' => environment_id.to_s,
'query' => "?dashboard=config%2Fprometheus%2Fcommon_metrics.yml&environment=#{environment_id}&group=awesome+group&start=2019-08-02T05%3A43%3A09.000Z",
'anchor' => '#title'
}
diff --git a/spec/lib/gitlab/metrics/global_search_slis_spec.rb b/spec/lib/gitlab/metrics/global_search_slis_spec.rb
index 0c09cf6dd71..c10d83664ea 100644
--- a/spec/lib/gitlab/metrics/global_search_slis_spec.rb
+++ b/spec/lib/gitlab/metrics/global_search_slis_spec.rb
@@ -47,10 +47,10 @@ RSpec.describe Gitlab::Metrics::GlobalSearchSlis do
describe '#record_apdex' do
where(:search_type, :code_search, :duration_target) do
- 'basic' | false | 7.031
- 'basic' | true | 21.903
- 'advanced' | false | 4.865
- 'advanced' | true | 13.546
+ 'basic' | false | 8.812
+ 'basic' | true | 27.538
+ 'advanced' | false | 2.452
+ 'advanced' | true | 15.52
end
with_them do
diff --git a/spec/lib/gitlab/metrics/loose_foreign_keys_slis_spec.rb b/spec/lib/gitlab/metrics/loose_foreign_keys_slis_spec.rb
new file mode 100644
index 00000000000..58740278425
--- /dev/null
+++ b/spec/lib/gitlab/metrics/loose_foreign_keys_slis_spec.rb
@@ -0,0 +1,81 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe ::Gitlab::Metrics::LooseForeignKeysSlis do
+ # This needs to be dynamic because db_config_names depends on
+ # config/database.yml and the specs need to work for all configurations. That
+ # means this assertion is a copy of the implementation.
+ let(:possible_labels) do
+ ::Gitlab::Database.db_config_names.map do |db_config_name|
+ {
+ db_config_name: db_config_name,
+ feature_category: :database
+ }
+ end
+ end
+
+ describe '#initialize_slis!' do
+ it 'initializes Apdex and ErrorRate SLIs for loose_foreign_key_clean_ups' do
+ expect(::Gitlab::Metrics::Sli::Apdex).to receive(:initialize_sli).with(
+ :loose_foreign_key_clean_ups,
+ possible_labels
+ )
+
+ expect(::Gitlab::Metrics::Sli::ErrorRate).to receive(:initialize_sli).with(
+ :loose_foreign_key_clean_ups,
+ possible_labels
+ )
+
+ described_class.initialize_slis!
+ end
+ end
+
+ describe '#record_apdex' do
+ context 'with success: true' do
+ it 'increments the loose_foreign_key_clean_ups Apdex as a success' do
+ expect(Gitlab::Metrics::Sli::Apdex[:loose_foreign_key_clean_ups]).to receive(:increment).with(
+ labels: { feature_category: :database, db_config_name: 'main' },
+ success: true
+ )
+
+ described_class.record_apdex(success: true, db_config_name: 'main')
+ end
+ end
+
+ context 'with success: false' do
+ it 'increments the loose_foreign_key_clean_ups Apdex as not a success' do
+ expect(Gitlab::Metrics::Sli::Apdex[:loose_foreign_key_clean_ups]).to receive(:increment).with(
+ labels: { feature_category: :database, db_config_name: 'main' },
+ success: false
+ )
+
+ described_class.record_apdex(success: false, db_config_name: 'main')
+ end
+ end
+ end
+
+ describe '#record_error_rate' do
+ context 'with error: true' do
+ it 'increments the loose_foreign_key_clean_ups ErrorRate as an error' do
+ expect(Gitlab::Metrics::Sli::ErrorRate[:loose_foreign_key_clean_ups]).to receive(:increment).with(
+ labels: { feature_category: :database, db_config_name: 'main' },
+ error: true
+ )
+
+ described_class.record_error_rate(error: true, db_config_name: 'main')
+ end
+ end
+
+ context 'with error: false' do
+ it 'increments the loose_foreign_key_clean_ups ErrorRate as not an error' do
+ expect(Gitlab::Metrics::Sli::ErrorRate[:loose_foreign_key_clean_ups]).to receive(:increment).with(
+ labels: { feature_category: :database, db_config_name: 'main' },
+ error: false
+ )
+
+ described_class.record_error_rate(error: false, db_config_name: 'main')
+ end
+ end
+ end
+end
diff --git a/spec/lib/gitlab/metrics/method_call_spec.rb b/spec/lib/gitlab/metrics/method_call_spec.rb
index 6aa89c7cb05..091f35bfbcc 100644
--- a/spec/lib/gitlab/metrics/method_call_spec.rb
+++ b/spec/lib/gitlab/metrics/method_call_spec.rb
@@ -24,47 +24,22 @@ RSpec.describe Gitlab::Metrics::MethodCall do
allow(method_call).to receive(:above_threshold?).and_return(true)
end
- context 'prometheus instrumentation is enabled' do
- before do
- stub_feature_flags(prometheus_metrics_method_instrumentation: true)
- end
-
- around do |example|
- freeze_time do
- example.run
- end
- end
-
- it 'metric is not a NullMetric' do
- method_call.measure { 'foo' }
- expect(::Gitlab::Metrics::WebTransaction.prometheus_metric(:gitlab_method_call_duration_seconds, :histogram)).not_to be_instance_of(Gitlab::Metrics::NullMetric)
- end
-
- it 'observes the performance of the supplied block' do
- expect(transaction)
- .to receive(:observe).with(:gitlab_method_call_duration_seconds, be_a_kind_of(Numeric), { method: "#bar", module: :Foo })
-
- method_call.measure { 'foo' }
+ around do |example|
+ freeze_time do
+ example.run
end
end
- context 'prometheus instrumentation is disabled' do
- before do
- stub_feature_flags(prometheus_metrics_method_instrumentation: false)
- end
-
- it 'observes the performance of the supplied block' do
- expect(transaction)
- .to receive(:observe).with(:gitlab_method_call_duration_seconds, be_a_kind_of(Numeric), { method: "#bar", module: :Foo })
-
- method_call.measure { 'foo' }
- end
+ it 'metric is not a NullMetric' do
+ method_call.measure { 'foo' }
+ expect(::Gitlab::Metrics::WebTransaction.prometheus_metric(:gitlab_method_call_duration_seconds, :histogram)).not_to be_instance_of(Gitlab::Metrics::NullMetric)
+ end
- it 'observes using NullMetric' do
- method_call.measure { 'foo' }
+ it 'observes the performance of the supplied block' do
+ expect(transaction)
+ .to receive(:observe).with(:gitlab_method_call_duration_seconds, be_a_kind_of(Numeric), { method: "#bar", module: :Foo })
- expect(::Gitlab::Metrics::WebTransaction.prometheus_metric(:gitlab_method_call_duration_seconds, :histogram)).to be_instance_of(Gitlab::Metrics::NullMetric)
- end
+ method_call.measure { 'foo' }
end
end
diff --git a/spec/lib/gitlab/metrics/samplers/ruby_sampler_spec.rb b/spec/lib/gitlab/metrics/samplers/ruby_sampler_spec.rb
index b1566ffa7b4..8c46c881ef0 100644
--- a/spec/lib/gitlab/metrics/samplers/ruby_sampler_spec.rb
+++ b/spec/lib/gitlab/metrics/samplers/ruby_sampler_spec.rb
@@ -35,14 +35,30 @@ RSpec.describe Gitlab::Metrics::Samplers::RubySampler do
end
describe '#sample' do
- it 'adds a metric containing the process resident memory bytes' do
- expect(Gitlab::Metrics::System).to receive(:memory_usage_rss).and_return(9000)
+ it 'adds a metric containing the process total resident memory bytes' do
+ expect(Gitlab::Metrics::System).to receive(:memory_usage_rss).and_return({ total: 9000 })
expect(sampler.metrics[:process_resident_memory_bytes]).to receive(:set).with({}, 9000)
sampler.sample
end
+ it 'adds a metric containing the process anonymous resident memory bytes' do
+ expect(Gitlab::Metrics::System).to receive(:memory_usage_rss).and_return({ anon: 9000 })
+
+ expect(sampler.metrics[:process_resident_anon_memory_bytes]).to receive(:set).with({}, 9000)
+
+ sampler.sample
+ end
+
+ it 'adds a metric containing the process file backed resident memory bytes' do
+ expect(Gitlab::Metrics::System).to receive(:memory_usage_rss).and_return({ file: 9000 })
+
+ expect(sampler.metrics[:process_resident_file_memory_bytes]).to receive(:set).with({}, 9000)
+
+ sampler.sample
+ end
+
it 'adds a metric containing the process unique and proportional memory bytes' do
expect(Gitlab::Metrics::System).to receive(:memory_usage_uss_pss).and_return(uss: 9000, pss: 10_000)
diff --git a/spec/lib/gitlab/metrics/system_spec.rb b/spec/lib/gitlab/metrics/system_spec.rb
index b86469eacd1..e4f53ab3f49 100644
--- a/spec/lib/gitlab/metrics/system_spec.rb
+++ b/spec/lib/gitlab/metrics/system_spec.rb
@@ -20,6 +20,7 @@ RSpec.describe Gitlab::Metrics::System do
VmHWM: 2468 kB
VmRSS: 2468 kB
RssAnon: 260 kB
+ RssFile: 1024 kB
SNIP
end
@@ -132,18 +133,26 @@ RSpec.describe Gitlab::Metrics::System do
describe '.memory_usage_rss' do
context 'without PID' do
- it "returns the current process' resident set size (RSS) in bytes" do
+ it "returns a hash containing RSS metrics in bytes for current process" do
mock_existing_proc_file('/proc/self/status', proc_status)
- expect(described_class.memory_usage_rss).to eq(2527232)
+ expect(described_class.memory_usage_rss).to eq(
+ total: 2527232,
+ anon: 266240,
+ file: 1048576
+ )
end
end
context 'with PID' do
- it "returns the given process' resident set size (RSS) in bytes" do
+ it "returns a hash containing RSS metrics in bytes for given process" do
mock_existing_proc_file('/proc/7/status', proc_status)
- expect(described_class.memory_usage_rss(pid: 7)).to eq(2527232)
+ expect(described_class.memory_usage_rss(pid: 7)).to eq(
+ total: 2527232,
+ anon: 266240,
+ file: 1048576
+ )
end
end
end
@@ -241,8 +250,12 @@ RSpec.describe Gitlab::Metrics::System do
end
describe '.memory_usage_rss' do
- it 'returns 0' do
- expect(described_class.memory_usage_rss).to eq(0)
+ it 'returns 0 for all components' do
+ expect(described_class.memory_usage_rss).to eq(
+ total: 0,
+ anon: 0,
+ file: 0
+ )
end
end