Commit 5dd6e752 authored by rpereira2's avatar rpereira2 Committed by Peter Leitzen

Some code improvements

- Use strong_memoize for prometheus_adapter since it can be nil in some
cases.
- Do not phrase spec descriptions with 'should'.
parent 833206ab
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
module Prometheus module Prometheus
class ProxyService < BaseService class ProxyService < BaseService
include ReactiveCaching include ReactiveCaching
include Gitlab::Utils::StrongMemoize
self.reactive_cache_key = ->(service) { service.cache_key } self.reactive_cache_key = ->(service) { service.cache_key }
self.reactive_cache_lease_timeout = 30.seconds self.reactive_cache_lease_timeout = 30.seconds
...@@ -91,7 +92,9 @@ module Prometheus ...@@ -91,7 +92,9 @@ module Prometheus
end end
def prometheus_adapter def prometheus_adapter
@prometheus_adapter ||= @proxyable.prometheus_adapter strong_memoize(:prometheus_adapter) do
@proxyable.prometheus_adapter
end
end end
def prometheus_client_wrapper def prometheus_client_wrapper
......
...@@ -48,7 +48,7 @@ describe Prometheus::ProxyService do ...@@ -48,7 +48,7 @@ describe Prometheus::ProxyService do
allow(environment).to receive(:prometheus_adapter).and_return(nil) allow(environment).to receive(:prometheus_adapter).and_return(nil)
end end
it 'should return error' do it 'returns error' do
expect(subject.execute).to eq( expect(subject.execute).to eq(
status: :error, status: :error,
message: 'No prometheus server found', message: 'No prometheus server found',
...@@ -63,7 +63,7 @@ describe Prometheus::ProxyService do ...@@ -63,7 +63,7 @@ describe Prometheus::ProxyService do
allow(prometheus_adapter).to receive(:can_query?).and_return(false) allow(prometheus_adapter).to receive(:can_query?).and_return(false)
end end
it 'should return error' do it 'returns error' do
expect(subject.execute).to eq( expect(subject.execute).to eq(
status: :error, status: :error,
message: 'No prometheus server found', message: 'No prometheus server found',
......
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