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

  1. Change proxyable in app/services/prometheus/proxy_service.rb class to be an object that responds to .prometheus_client, rather than an object which responds to .prometheus_adapter. This is so that a PrometheusService or Clusters::Cluster object can be passed to ProxyService.

  2. Add a prometheus_adapter method to Project.

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

Optional: Intended side effects

Optional: Missing test coverage

Edited Jul 10, 2020 by Reuben Pereira
Assignee Loading
Time tracking Loading