Merge branch 'sh-memoize-logger' into 'master'

Memoize GitLab logger to reduce open file descriptors

Closes gitlab-ee#3664

See merge request gitlab-org/gitlab-ce!15007
This commit is contained in:
Nick Thomas 2017-10-24 12:43:30 +00:00
commit bf4e97fc83
3 changed files with 27 additions and 2 deletions

View File

@ -0,0 +1,5 @@
---
title: Memoize GitLab logger to reduce open file descriptors
merge_request:
author:
type: fixed

View File

@ -13,7 +13,7 @@ module Gitlab
end
def self.read_latest
path = Rails.root.join("log", file_name)
path = self.full_log_path
return [] unless File.readable?(path)
@ -22,7 +22,15 @@ module Gitlab
end
def self.build
new(Rails.root.join("log", file_name))
RequestStore[self.cache_key] ||= new(self.full_log_path)
end
def self.full_log_path
Rails.root.join("log", file_name)
end
def self.cache_key
'logger:'.freeze + self.full_log_path.to_s
end
end
end

View File

@ -0,0 +1,12 @@
require 'spec_helper'
describe Gitlab::AppLogger, :request_store do
subject { described_class }
it 'builds a logger once' do
expect(::Logger).to receive(:new).and_call_original
subject.info('hello world')
subject.error('hello again')
end
end