Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean Sidekiq metrics from multiproc dir on start
After moving the multiproc dir cleanup into `config.ru`:`warmup`, we stopped cleaning Sidekiq metrics dir which is not correct. This MR intended to fix that. More details: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/31668
- Loading branch information
Showing
4 changed files
with
82 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module Prometheus | ||
class CleanupMultiprocDirService | ||
include Gitlab::Utils::StrongMemoize | ||
|
||
def execute | ||
FileUtils.rm_rf(old_metrics) if old_metrics | ||
end | ||
|
||
private | ||
|
||
def old_metrics | ||
strong_memoize(:old_metrics) do | ||
Dir[File.join(multiprocess_files_dir, '*.db')] if multiprocess_files_dir | ||
end | ||
end | ||
|
||
def multiprocess_files_dir | ||
::Prometheus::Client.configuration.multiprocess_files_dir | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe Prometheus::CleanupMultiprocDirService do | ||
describe '.call' do | ||
subject { described_class.new.execute } | ||
|
||
let(:metrics_multiproc_dir) { Dir.mktmpdir } | ||
let(:metrics_file_path) { File.join(metrics_multiproc_dir, 'counter_puma_master-0.db') } | ||
|
||
before do | ||
FileUtils.touch(metrics_file_path) | ||
end | ||
|
||
after do | ||
FileUtils.rm_r(metrics_multiproc_dir) | ||
end | ||
|
||
context 'when `multiprocess_files_dir` is defined' do | ||
before do | ||
expect(Prometheus::Client.configuration) | ||
.to receive(:multiprocess_files_dir) | ||
.and_return(metrics_multiproc_dir) | ||
.at_least(:once) | ||
end | ||
|
||
it 'removes old metrics' do | ||
expect { subject } | ||
.to change { File.exist?(metrics_file_path) } | ||
.from(true) | ||
.to(false) | ||
end | ||
end | ||
|
||
context 'when `multiprocess_files_dir` is not defined' do | ||
before do | ||
expect(Prometheus::Client.configuration) | ||
.to receive(:multiprocess_files_dir) | ||
.and_return(nil) | ||
.at_least(:once) | ||
end | ||
|
||
it 'does not remove any files' do | ||
expect { subject } | ||
.not_to change { File.exist?(metrics_file_path) } | ||
.from(true) | ||
end | ||
end | ||
end | ||
end |