summaryrefslogtreecommitdiff
path: root/app/models/environment.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/environment.rb')
-rw-r--r--app/models/environment.rb30
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