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

Memoize only yaml loading method

parent 8b69523b
......@@ -23,11 +23,11 @@ module Gitlab
end
def additional_metrics_raw
@additional_metrics_raw ||= load_yaml_file&.map(&:deep_symbolize_keys).freeze
load_yaml_file&.map(&:deep_symbolize_keys).freeze
end
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
......
......@@ -33,7 +33,6 @@ describe Gitlab::Prometheus::AdditionalMetricsParser, lib: true do
end
before do
described_class.instance_variable_set :@additional_metrics_raw, nil
allow(described_class).to receive(:load_yaml_file) { YAML.load(sample_yaml) }
end
......@@ -68,10 +67,6 @@ describe Gitlab::Prometheus::AdditionalMetricsParser, lib: true do
end
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
before do
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