Commit 13902e40 authored by Pawel Chojnacki's avatar Pawel Chojnacki

Memoize only yaml loading method

parent 8b69523b
...@@ -23,11 +23,11 @@ module Gitlab ...@@ -23,11 +23,11 @@ module Gitlab
end end
def additional_metrics_raw def additional_metrics_raw
@additional_metrics_raw ||= load_yaml_file&.map(&:deep_symbolize_keys).freeze load_yaml_file&.map(&:deep_symbolize_keys).freeze
end end
def load_yaml_file def load_yaml_file
YAML.load_file(Rails.root.join('config/prometheus/additional_metrics.yml')) @loaded_yaml_file ||= YAML.load_file(Rails.root.join('config/prometheus/additional_metrics.yml'))
end end
end end
end end
......
...@@ -33,7 +33,6 @@ describe Gitlab::Prometheus::AdditionalMetricsParser, lib: true do ...@@ -33,7 +33,6 @@ describe Gitlab::Prometheus::AdditionalMetricsParser, lib: true do
end end
before do before do
described_class.instance_variable_set :@additional_metrics_raw, nil
allow(described_class).to receive(:load_yaml_file) { YAML.load(sample_yaml) } allow(described_class).to receive(:load_yaml_file) { YAML.load(sample_yaml) }
end end
...@@ -68,10 +67,6 @@ describe Gitlab::Prometheus::AdditionalMetricsParser, lib: true do ...@@ -68,10 +67,6 @@ describe Gitlab::Prometheus::AdditionalMetricsParser, lib: true do
end end
shared_examples 'required field' do |field_name| shared_examples 'required field' do |field_name|
before do
described_class.instance_variable_set :@additional_metrics_raw, nil
end
context "when #{field_name} is nil" do context "when #{field_name} is nil" do
before do before do
allow(described_class).to receive(:load_yaml_file) { YAML.load(field_missing) } allow(described_class).to receive(:load_yaml_file) { YAML.load(field_missing) }
......
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