diff options
author | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-05-10 12:25:30 +0300 |
---|---|---|
committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-05-25 16:05:56 +0300 |
commit | 2061414054ce43aa6d53d1be3f602114e5a336d2 (patch) | |
tree | c32e83fcd76cd279171117f3ff282ef54f5308a2 /app/models | |
parent | 78de1c059ac588df4ba1ef352b28e5b1c6102804 (diff) |
Additional metrics initial work, with working metrics listing, but without actoual metrics mesurements
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/environment.rb | 8 | ||||
-rw-r--r-- | app/models/project_services/prometheus_service.rb | 20 |
2 files changed, 23 insertions, 5 deletions
diff --git a/app/models/environment.rb b/app/models/environment.rb index 61572d8d69a..b4a4f74a8d5 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -149,10 +149,18 @@ class Environment < ActiveRecord::Base project.monitoring_service.present? && available? && last_deployment.present? end + def has_additional_metrics? + has_metrics? && project.monitoring_service&.respond_to?(:reactive_query) + end + def metrics project.monitoring_service.environment_metrics(self) if has_metrics? end + def additional_metrics + project.monitoring_service.reactive_query(Gitlab::Prometheus::Queries::AdditionalMetricsQuery, self.id) if has_additional_metrics? + end + # An environment name is not necessarily suitable for use in URLs, DNS # or other third-party contexts, so provide a slugified version. A slug has # the following properties: 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 |