Refactor Prometheus::ProxyService to be more reusable
Summary
Currently, we pass an object that responds to prometheus_adapter to Prometheus::ProxyService. object.prometheus_adapter.prometheus_client is what Prometheus::ProxyService needs to communicate with a particular Prometheus server.
However, as we're decoupling metrics dashboard from environments, we need to determine which Prometheus server to communicate with based on the project object, not environment object.
We can either
-
Change
proxyableinapp/services/prometheus/proxy_service.rbclass to be an object that responds to.prometheus_client, rather than an object which responds to.prometheus_adapter. This is so that aPrometheusServiceorClusters::Clusterobject can be passed toProxyService. -
Add a
prometheus_adaptermethod toProject.
I prefer the first solution since Prometheus::ProxyService only requires a PrometheusClient. This solution also prepares us for #10615 (closed).
Not sure if we can directly provide a PrometheusClient to Prometheus::ProxyService. The object provided to Prometheus::ProxyService needs to be a database object or an object that can be serialized since Prometheus::ProxyService uses ReactiveCaching.
Improvements
By changing its parameters to be lower level, and only one level away from the object it needs (PrometheusClient), we make it easier to reuse Prometheus::ProxyService.
Risks
Involved components
- app/services/prometheus/proxy_service.rb
- app/controllers/concerns/metrics/dashboard/prometheus_api_proxy.rb