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/boot_time_tracker_spec.rb')
-rw-r--r--spec/lib/gitlab/metrics/boot_time_tracker_spec.rb84
1 files changed, 84 insertions, 0 deletions
diff --git a/spec/lib/gitlab/metrics/boot_time_tracker_spec.rb b/spec/lib/gitlab/metrics/boot_time_tracker_spec.rb
new file mode 100644
index 00000000000..8a17fa8dd2e
--- /dev/null
+++ b/spec/lib/gitlab/metrics/boot_time_tracker_spec.rb
@@ -0,0 +1,84 @@
+# frozen_string_literal: true
+
+require 'fast_spec_helper'
+
+RSpec.describe Gitlab::Metrics::BootTimeTracker do
+ let(:logger) { double('logger') }
+ let(:gauge) { double('gauge') }
+
+ subject(:tracker) { described_class.instance }
+
+ before do
+ described_class.instance.reset!
+
+ allow(logger).to receive(:info)
+ allow(gauge).to receive(:set)
+ allow(Gitlab::Metrics).to receive(:gauge).and_return(gauge)
+ end
+
+ describe '#track_boot_time!' do
+ described_class::SUPPORTED_RUNTIMES.each do |runtime|
+ context "when called on #{runtime} for the first time" do
+ before do
+ expect(Gitlab::Runtime).to receive(:safe_identify).and_return(runtime)
+ end
+
+ it 'set the startup_time' do
+ tracker.track_boot_time!(logger: logger)
+
+ expect(tracker.startup_time).to be > 0
+ end
+
+ it 'records the current process runtime' do
+ expect(Gitlab::Metrics::System).to receive(:process_runtime_elapsed_seconds).once
+
+ tracker.track_boot_time!(logger: logger)
+ end
+
+ it 'logs the application boot time' do
+ expect(Gitlab::Metrics::System).to receive(:process_runtime_elapsed_seconds).and_return(42)
+ expect(logger).to receive(:info).with(message: 'Application boot finished', runtime: runtime.to_s, duration_s: 42)
+
+ tracker.track_boot_time!(logger: logger)
+ end
+
+ it 'tracks boot time in a prometheus gauge' do
+ expect(Gitlab::Metrics::System).to receive(:process_runtime_elapsed_seconds).and_return(42)
+ expect(gauge).to receive(:set).with({}, 42)
+
+ tracker.track_boot_time!(logger: logger)
+ end
+
+ context 'on subsequent calls' do
+ it 'does nothing' do
+ tracker.track_boot_time!(logger: logger)
+
+ expect(Gitlab::Metrics::System).not_to receive(:process_runtime_elapsed_seconds)
+ expect(logger).not_to receive(:info)
+ expect(gauge).not_to receive(:set)
+
+ tracker.track_boot_time!(logger: logger)
+ end
+ end
+ end
+ end
+
+ context 'when called on other runtimes' do
+ it 'does nothing' do
+ tracker.track_boot_time!(logger: logger)
+
+ expect(Gitlab::Metrics::System).not_to receive(:process_runtime_elapsed_seconds)
+ expect(logger).not_to receive(:info)
+ expect(gauge).not_to receive(:set)
+
+ tracker.track_boot_time!(logger: logger)
+ end
+ end
+ end
+
+ describe '#startup_time' do
+ it 'returns 0 when boot time not tracked' do
+ expect(tracker.startup_time).to eq(0)
+ end
+ end
+end