diff options
author | Jose Ivan Vargas Lopez <jvargas@gitlab.com> | 2017-06-07 23:31:06 +0000 |
---|---|---|
committer | Jose Ivan Vargas Lopez <jvargas@gitlab.com> | 2017-06-07 23:31:06 +0000 |
commit | fb80347dc00657ba36576f1f23bd42fdbcf9520a (patch) | |
tree | 2642ac39cda31e29ea80defdc71e00c89ac8979e /app/models/environment.rb | |
parent | 73924cc51495f5f497114ed9f9de02f8b9c4205b (diff) | |
parent | 6eb96b2019d392d906a64108dbe83b3ce7cce758 (diff) | |
download | gitlab-ce-additional-metrics-dashboard.tar.gz |
Merge branch '28717-additional-metrics-review-branch' into 'additional-metrics-dashboard'additional-metrics-dashboard
# Conflicts:
# app/assets/stylesheets/pages/environments.scss
Diffstat (limited to 'app/models/environment.rb')
-rw-r--r-- | app/models/environment.rb | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/app/models/environment.rb b/app/models/environment.rb index 7ab4a23ab16..94815f99e9f 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -57,6 +57,10 @@ class Environment < ActiveRecord::Base state :available state :stopped + + after_transition do |environment| + environment.expire_etag_cache + end end def predefined_variables @@ -149,20 +153,24 @@ 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 has_additional_metrics? + prometheus_service.present? && available? && last_deployment.present? + end + def additional_metrics if has_additional_metrics? - project.monitoring_service.reactive_query(Gitlab::Prometheus::Queries::AdditionalMetricsQuery.name, self.id, &:itself) + prometheus_service.additional_environment_metrics(self) end end + def prometheus_service + @prometheus_service ||= project.monitoring_services.reorder(nil).find_by(active: true, type: PrometheusService.name) + 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: @@ -206,6 +214,18 @@ class Environment < ActiveRecord::Base [external_url, public_path].join('/') end + def expire_etag_cache + Gitlab::EtagCaching::Store.new.tap do |store| + store.touch(etag_cache_key) + end + end + + def etag_cache_key + Gitlab::Routing.url_helpers.namespace_project_environments_path( + project.namespace, + project) + end + private # Slugifying a name may remove the uniqueness guarantee afforded by it being |