From ebede2b3ff1c2b089529c4f9d6268641580e280b Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Fri, 12 May 2017 15:19:27 +0200 Subject: Use etag caching for environments JSON For the index view, the environments can now be requested every 15 seconds. Any transition state of a projects environments will trigger a cache invalidation action. Fixes gitlab-org/gitlab-ce#31701 --- app/models/environment.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'app/models/environment.rb') diff --git a/app/models/environment.rb b/app/models/environment.rb index 61572d8d69a..07722d9a59e 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 @@ -196,6 +200,13 @@ class Environment < ActiveRecord::Base [external_url, public_path].join('/') end + def expire_etag_cache + Gitlab::EtagCaching::Store.new.tap do |store| + store.touch(Gitlab::Routing.url_helpers + .namespace_project_environments_path(project.namespace, project)) + end + end + private # Slugifying a name may remove the uniqueness guarantee afforded by it being -- cgit v1.2.1 From f4aa01053ed39a265ddfd9ee6e9618bd3406e59d Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Tue, 30 May 2017 23:56:26 +0200 Subject: Test etag cache key changing value --- app/models/environment.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'app/models/environment.rb') diff --git a/app/models/environment.rb b/app/models/environment.rb index 07722d9a59e..6211a5c1e63 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -202,11 +202,16 @@ class Environment < ActiveRecord::Base def expire_etag_cache Gitlab::EtagCaching::Store.new.tap do |store| - store.touch(Gitlab::Routing.url_helpers - .namespace_project_environments_path(project.namespace, project)) + 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 -- cgit v1.2.1 From ccf89acc7145bb129f5666108854daa71a022827 Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Tue, 6 Jun 2017 16:07:33 +0200 Subject: expand Namespaces:: and refactoring yaml parsing out of MetricGroup class --- app/models/environment.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models/environment.rb') diff --git a/app/models/environment.rb b/app/models/environment.rb index 7ab4a23ab16..8d98b02c05a 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -159,7 +159,7 @@ class Environment < ActiveRecord::Base def additional_metrics if has_additional_metrics? - project.monitoring_service.reactive_query(Gitlab::Prometheus::Queries::AdditionalMetricsQuery.name, self.id, &:itself) + project.monitoring_service.reactive_query(Gitlab::Prometheus::Queries::AdditionalMetricsEnvironmentQuery.name, self.id, &:itself) end end -- cgit v1.2.1 From a7e1205219387a6d24c8579994f73a33b3028010 Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Wed, 7 Jun 2017 02:36:59 +0200 Subject: Use explicit instance of prometheus service and add access methods to it --- app/models/environment.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'app/models/environment.rb') diff --git a/app/models/environment.rb b/app/models/environment.rb index 8d98b02c05a..9b7dc7f807e 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -149,20 +149,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::AdditionalMetricsEnvironmentQuery.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: -- cgit v1.2.1