Commit 8ba3bc0e authored by Marin Jankovski's avatar Marin Jankovski

Merge branch 'reuse-logger' into 'master'

Re-use the default logger for performance metrics

See #64 for the discussion leading up to this.

See merge request !100
parents 3cba0e6e 1d68fefe
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
......
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
......
......@@ -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
......
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