diff options
author | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-05-10 11:25:30 +0200 |
---|---|---|
committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-05-25 15:05:56 +0200 |
commit | 2061414054ce43aa6d53d1be3f602114e5a336d2 (patch) | |
tree | c32e83fcd76cd279171117f3ff282ef54f5308a2 /app/models/project_services | |
parent | 78de1c059ac588df4ba1ef352b28e5b1c6102804 (diff) | |
download | gitlab-ce-2061414054ce43aa6d53d1be3f602114e5a336d2.tar.gz |
Additional metrics initial work, with working metrics listing, but without actoual metrics mesurements
Diffstat (limited to 'app/models/project_services')
-rw-r--r-- | app/models/project_services/prometheus_service.rb | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/app/models/project_services/prometheus_service.rb b/app/models/project_services/prometheus_service.rb index ec72cb6856d..674d485a03c 100644 --- a/app/models/project_services/prometheus_service.rb +++ b/app/models/project_services/prometheus_service.rb @@ -64,23 +64,26 @@ class PrometheusService < MonitoringService end def environment_metrics(environment) - with_reactive_cache(Gitlab::Prometheus::Queries::EnvironmentQuery.name, environment.id, &:itself) + with_reactive_cache(Gitlab::Prometheus::Queries::EnvironmentQuery.name, environment.id, &method(:rename_data_to_metrics)) end def deployment_metrics(deployment) - metrics = with_reactive_cache(Gitlab::Prometheus::Queries::DeploymentQuery.name, deployment.id, &:itself) + metrics = with_reactive_cache(Gitlab::Prometheus::Queries::DeploymentQuery.name, deployment.id, &method(:rename_data_to_metrics)) metrics&.merge(deployment_time: created_at.to_i) || {} end + def reactive_query(query_class, *args, &block) + calculate_reactive_cache(query_class, *args, &block) + end + # Cache metrics for specific environment def calculate_reactive_cache(query_class_name, *args) return unless active? && project && !project.pending_delete? - metrics = Kernel.const_get(query_class_name).new(client).query(*args) - + data = Kernel.const_get(query_class_name).new(client).query(*args) { success: true, - metrics: metrics, + data: data, last_update: Time.now.utc } rescue Gitlab::PrometheusError => err @@ -90,4 +93,11 @@ class PrometheusService < MonitoringService def client @prometheus ||= Gitlab::PrometheusClient.new(api_url: api_url) end + + private + + def rename_data_to_metrics(metrics) + metrics[:metrics] = metrics.delete :data + metrics + end end |