diff options
-rw-r--r-- | CHANGELOG | 3 | ||||
-rw-r--r-- | lib/gitlab_metrics.rb | 5 | ||||
-rw-r--r-- | spec/gitlab_metrics_spec.rb | 12 |
3 files changed, 10 insertions, 10 deletions
@@ -1,3 +1,6 @@ +v3.6.6 + - Re-use the default logger when logging metrics data + v3.6.5 - Test against ruby 2.3 - Instrument GitLab Shell and log metrics data to a file diff --git a/lib/gitlab_metrics.rb b/lib/gitlab_metrics.rb index 7bf07a5..b974b8a 100644 --- a/lib/gitlab_metrics.rb +++ b/lib/gitlab_metrics.rb @@ -1,5 +1,6 @@ require 'logger' require_relative 'gitlab_config' +require_relative 'gitlab_logger' module GitlabMetrics module System @@ -25,7 +26,7 @@ module GitlabMetrics end def self.logger - @logger ||= Logger.new(GitlabConfig.new.metrics_log_file) + $logger end # Measures the execution time of a block. @@ -48,7 +49,7 @@ module GitlabMetrics real_time = System.monotonic_time - start_real cpu_time = System.cpu_time - start_cpu - logger.debug { "name=#{name.inspect} wall_time=#{real_time.inspect} cpu_time=#{cpu_time.inspect}" } + logger.debug("metrics: name=#{name.inspect} wall_time=#{real_time} cpu_time=#{cpu_time}") retval end diff --git a/spec/gitlab_metrics_spec.rb b/spec/gitlab_metrics_spec.rb index 885fa3b..07be670 100644 --- a/spec/gitlab_metrics_spec.rb +++ b/spec/gitlab_metrics_spec.rb @@ -2,22 +2,18 @@ require_relative 'spec_helper' require_relative '../lib/gitlab_metrics' describe GitlabMetrics do - describe '::measure' do + describe '.measure' do it 'returns the return value of the block' do val = described_class.measure('foo') { 10 } expect(val).to eq(10) end - it 'write in a file metrics data' do - result = nil - expect(described_class.logger).to receive(:debug) do |&b| - result = b.call - end + it 'writes the metrics data to a log file' do + expect(described_class.logger).to receive(:debug). + with(/metrics: name=\"foo\" wall_time=\d+ cpu_time=\d+/) described_class.measure('foo') { 10 } - - expect(result).to match(/name=\"foo\" wall_time=\d+ cpu_time=\d+/) end it 'calls proper measure methods' do |