summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrpereira2 <rpereira@gitlab.com>2019-04-03 00:06:13 +0530
committerPeter Leitzen <pleitzen@gitlab.com>2019-04-04 22:22:45 +0200
commitaa27c9491f58ec30e5e3afd035e1337694102a80 (patch)
tree38646070442b4e2e9307014099f094621db4a703
parent359d00cd5ded5ef7d3cf33b34c1e4869f1e5c9c5 (diff)
downloadgitlab-ce-aa27c9491f58ec30e5e3afd035e1337694102a80.tar.gz
Rename prometheus_owner to proxyable
- proxyable is a better name for any model object that has a prometheus server to which requests can be proxied.
-rw-r--r--app/services/prometheus/proxy_service.rb26
-rw-r--r--spec/services/prometheus/proxy_service_spec.rb4
2 files changed, 15 insertions, 15 deletions
diff --git a/app/services/prometheus/proxy_service.rb b/app/services/prometheus/proxy_service.rb
index 55888fedb04..4a0d1dcd83f 100644
--- a/app/services/prometheus/proxy_service.rb
+++ b/app/services/prometheus/proxy_service.rb
@@ -10,30 +10,30 @@ module Prometheus
self.reactive_cache_lifetime = 1.minute
self.reactive_cache_worker_finder = ->(_id, *args) { from_cache(*args) }
- attr_accessor :prometheus_owner, :method, :path, :params
+ attr_accessor :proxyable, :method, :path, :params
PROXY_SUPPORT = {
'query' => 'GET',
'query_range' => 'GET'
}.freeze
- def self.from_cache(prometheus_owner_class_name, prometheus_owner_id, method, path, params)
- prometheus_owner_class = begin
- prometheus_owner_class_name.constantize
+ def self.from_cache(proxyable_class_name, proxyable_id, method, path, params)
+ proxyable_class = begin
+ proxyable_class_name.constantize
rescue NameError
nil
end
- return unless prometheus_owner_class
+ return unless proxyable_class
- prometheus_owner = prometheus_owner_class.find(prometheus_owner_id)
+ proxyable = proxyable_class.find(proxyable_id)
- new(prometheus_owner, method, path, params)
+ new(proxyable, method, path, params)
end
- # prometheus_owner can be any model which responds to .prometheus_adapter
+ # proxyable can be any model which responds to .prometheus_adapter
# like Environment.
- def initialize(prometheus_owner, method, path, params)
- @prometheus_owner = prometheus_owner
+ def initialize(proxyable, method, path, params)
+ @proxyable = proxyable
@path = path
# Convert ActionController::Parameters to hash because reactive_cache_worker
# does not play nice with ActionController::Parameters.
@@ -54,7 +54,7 @@ module Prometheus
end
end
- def calculate_reactive_cache(prometheus_owner_class_name, prometheus_owner_id, method, path, params)
+ def calculate_reactive_cache(proxyable_class_name, proxyable_id, method, path, params)
return no_prometheus_response unless can_query?
response = prometheus_client_wrapper.proxy(path, params)
@@ -65,7 +65,7 @@ module Prometheus
end
def cache_key
- [@prometheus_owner.class.name, @prometheus_owner.id, @method, @path, @params]
+ [@proxyable.class.name, @proxyable.id, @method, @path, @params]
end
private
@@ -83,7 +83,7 @@ module Prometheus
end
def prometheus_adapter
- @prometheus_adapter ||= @prometheus_owner.prometheus_adapter
+ @prometheus_adapter ||= @proxyable.prometheus_adapter
end
def prometheus_client_wrapper
diff --git a/spec/services/prometheus/proxy_service_spec.rb b/spec/services/prometheus/proxy_service_spec.rb
index 1b98c68f99d..c271fc586c1 100644
--- a/spec/services/prometheus/proxy_service_spec.rb
+++ b/spec/services/prometheus/proxy_service_spec.rb
@@ -14,7 +14,7 @@ describe Prometheus::ProxyService do
it 'initializes attributes' do
result = described_class.new(environment, 'GET', 'query', { query: '1' })
- expect(result.prometheus_owner).to eq(environment)
+ expect(result.proxyable).to eq(environment)
expect(result.method).to eq('GET')
expect(result.path).to eq('query')
expect(result.params).to eq(query: '1')
@@ -175,7 +175,7 @@ describe Prometheus::ProxyService do
result = described_class.from_cache(environment.class.name, environment.id, 'GET', 'query', { query: '1' })
expect(result).to be_an_instance_of(described_class)
- expect(result.prometheus_owner).to eq(environment)
+ expect(result.proxyable).to eq(environment)
expect(result.method).to eq('GET')
expect(result.path).to eq('query')
expect(result.params).to eq(query: '1')