summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2018-08-07 23:02:57 +0900
committerShinya Maeda <shinya@gitlab.com>2018-08-07 23:03:48 +0900
commit8fa361b2d9cce92595e5804b9c7f4a04b5df25fb (patch)
treec512713377d2612fb80ec38ee11b880aa6908ff8 /app
parent84f24dcef0d44e7447d3f3de4ec91668e5d9d3a3 (diff)
downloadgitlab-ce-8fa361b2d9cce92595e5804b9c7f4a04b5df25fb.tar.gz
Squashed commit of the following:
commit 610c02c305d9fb3c7d271883450a5fee8b0cf16f Merge: f2088edb260 84f24dcef0d Author: Shinya Maeda <shinya@gitlab.com> Date: Tue Aug 7 23:01:38 2018 +0900 Merge branch 'master-ce' into improve-junit-support-be commit f2088edb26008e5791b7be86fc02fc470c881143 Merge: c67e1d32cac 339f47abec1 Author: Shinya Maeda <shinya@gitlab.com> Date: Tue Aug 7 21:52:10 2018 +0900 Merge branch 'improve-junit-support-be' of gitlab.com:gitlab-org/gitlab-ce into improve-junit-support-be commit c67e1d32cac731b895e2f49a24ce0e1726b8196c Author: Shinya Maeda <shinya@gitlab.com> Date: Tue Aug 7 21:51:39 2018 +0900 Remove debuggable fixtures commit 339f47abec1d0ce815e6103a087902d71d8ff5be Merge: 7a33a9be724 96b748fbcc0 Author: Filipa Lacerda <filipa@gitlab.com> Date: Tue Aug 7 11:10:18 2018 +0100 Merge branch 'improve-junit-support-be' of https://gitlab.com/gitlab-org/gitlab-ce into improve-junit-support-be * 'improve-junit-support-be' of https://gitlab.com/gitlab-org/gitlab-ce: Add spec for latest Add spec for merge request Add spec for cache invalidation Add spec for pipeline Add spec Fix specs Support corrupted fixtures Add cache key to error message commit 7a33a9be724dbde79a24cec77658952ff2d2fa6c Author: Filipa Lacerda <filipa@gitlab.com> Date: Tue Aug 7 11:09:56 2018 +0100 Show resolved failures commit 96b748fbcc00a98a13aeb78f5d97de9cf25035b6 Author: Shinya Maeda <shinya@gitlab.com> Date: Tue Aug 7 18:50:05 2018 +0900 Add spec for latest commit 0e8b024169b4b0ac272331117ac2fa821c4052f7 Author: Shinya Maeda <shinya@gitlab.com> Date: Tue Aug 7 18:24:38 2018 +0900 Add spec for merge request commit 8690a699bc98394ad4deebdc91e6690758c5965e Author: Shinya Maeda <shinya@gitlab.com> Date: Tue Aug 7 18:18:55 2018 +0900 Add spec for cache invalidation commit 97678e1612826af409ca8a04b6c0dc830f7b66c6 Author: Shinya Maeda <shinya@gitlab.com> Date: Tue Aug 7 18:01:03 2018 +0900 Add spec for pipeline commit 96c2a698af049e4026c68e74b1f41a265464b2b2 Author: Shinya Maeda <shinya@gitlab.com> Date: Tue Aug 7 17:52:21 2018 +0900 Add spec commit 67bcbd25a3c13abb78ea43c0411f5aed417b87d0 Author: Shinya Maeda <shinya@gitlab.com> Date: Tue Aug 7 17:39:02 2018 +0900 Fix specs commit d7d49def2023f85c07d2718b83f35c8849f65f05 Author: Shinya Maeda <shinya@gitlab.com> Date: Tue Aug 7 13:11:07 2018 +0900 Support corrupted fixtures commit d58dbbc17a7d954db22082615f5331c148c1061b Author: Shinya Maeda <shinya@gitlab.com> Date: Tue Aug 7 13:10:47 2018 +0900 Add cache key to error message commit f6f976216dc36333b5e05e3f0acdfca689350483 Author: Shinya Maeda <shinya@gitlab.com> Date: Thu Aug 2 19:07:46 2018 +0900 bring back debaggable fixtures commit 48a7800e67a718145c0e88c324c0c1f9619e26a4 Merge: 2822b9e8a36 dd627072b3f Author: Shinya Maeda <shinya@gitlab.com> Date: Tue Aug 7 09:22:22 2018 +0900 Merge branch 'master-ce' into improve-junit-support-be commit 2822b9e8a369162d098a72a58803c8494b2343cd Author: Shinya Maeda <shinya@gitlab.com> Date: Mon Aug 6 22:54:47 2018 +0900 Move cache invalidation policy to outside of reactive cache commit b35efb1764ae61bb31dacbf79dbc022dcee3a203 Author: Shinya Maeda <shinya@gitlab.com> Date: Mon Aug 6 22:34:10 2018 +0900 ADd reactive cache an ability to invalite cache commit feafee6f8a50f4a32866d8ae768e99766b0b7c73 Author: Shinya Maeda <shinya@gitlab.com> Date: Mon Aug 6 19:25:22 2018 +0900 Pipeline has test reports if latest builds have any commit f302dbb73abe03c6c431e7d52d526e28a1586fee Author: Shinya Maeda <shinya@gitlab.com> Date: Mon Aug 6 19:18:56 2018 +0900 Invalidate test reports cache if it's outdated commit 83adaca01a1ee1cd64cac86b6fa3d10e2e4e2b98 Author: Shinya Maeda <shinya@gitlab.com> Date: Mon Aug 6 18:08:06 2018 +0900 Revert cache invalidation in expire pipeline cache worker commit ec3af5de4ca34e2e92ad6b97f29733d6c65062bc Author: Shinya Maeda <shinya@gitlab.com> Date: Mon Aug 6 15:13:47 2018 +0900 Fix feature spec commit 0db48805a1ba68763be0504eb57218bde2380e4b Author: Shinya Maeda <shinya@gitlab.com> Date: Mon Aug 6 14:07:46 2018 +0900 Change lifetime of test reports cache to 10 minutes commit 17f7e78bfe2188c349cda1ff90a3ea94d337461e Author: Shinya Maeda <shinya@gitlab.com> Date: Mon Aug 6 14:07:19 2018 +0900 Add changelog commit 89c87585ab7f5333a8139c02b330dd2caf0be31a Author: Shinya Maeda <shinya@gitlab.com> Date: Mon Aug 6 14:01:20 2018 +0900 Add feature spec commit 1120cfd7a9ab06105f2e763c375fab00922b7e0c Author: Shinya Maeda <shinya@gitlab.com> Date: Mon Aug 6 12:55:47 2018 +0900 Invalidate cache when pipeline status transits. Correct test reports from the latest builds
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects/merge_requests_controller.rb4
-rw-r--r--app/models/ci/pipeline.rb4
-rw-r--r--app/models/concerns/reactive_caching.rb28
-rw-r--r--app/models/merge_request.rb19
-rw-r--r--app/services/ci/compare_test_reports_service.rb43
5 files changed, 66 insertions, 32 deletions
diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb
index eaf4434f913..1b069fe507b 100644
--- a/app/controllers/projects/merge_requests_controller.rb
+++ b/app/controllers/projects/merge_requests_controller.rb
@@ -102,10 +102,10 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
def test_reports
result = @merge_request.compare_test_reports
- Gitlab::PollingInterval.set_header(response, interval: 10_000)
-
case result[:status]
when :parsing
+ Gitlab::PollingInterval.set_header(response, interval: 3000)
+
render json: '', status: :no_content
when :parsed
render json: result[:data].to_json, status: :ok
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index 75dfa00d12e..e4aed76f611 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -606,12 +606,12 @@ module Ci
end
def has_test_reports?
- complete? && builds.with_test_reports.any?
+ complete? && builds.latest.with_test_reports.any?
end
def test_reports
Gitlab::Ci::Reports::TestReports.new.tap do |test_reports|
- builds.with_test_reports.each do |build|
+ builds.latest.with_test_reports.each do |build|
build.collect_test_reports!(test_reports)
end
end
diff --git a/app/models/concerns/reactive_caching.rb b/app/models/concerns/reactive_caching.rb
index 9155d82d567..65cc7a751f9 100644
--- a/app/models/concerns/reactive_caching.rb
+++ b/app/models/concerns/reactive_caching.rb
@@ -42,6 +42,8 @@
module ReactiveCaching
extend ActiveSupport::Concern
+ InvalidateReactiveCache = Class.new(StandardError)
+
included do
class_attribute :reactive_cache_lease_timeout
@@ -63,15 +65,19 @@ module ReactiveCaching
end
def with_reactive_cache(*args, &blk)
- bootstrap = !within_reactive_cache_lifetime?(*args)
- Rails.cache.write(alive_reactive_cache_key(*args), true, expires_in: self.class.reactive_cache_lifetime)
+ unless within_reactive_cache_lifetime?(*args)
+ refresh_reactive_cache!(*args)
+ return nil
+ end
- if bootstrap
- ReactiveCachingWorker.perform_async(self.class, id, *args)
- nil
- else
+ keep_alive_reactive_cache!(*args)
+
+ begin
data = Rails.cache.read(full_reactive_cache_key(*args))
yield data if data.present?
+ rescue InvalidateReactiveCache
+ refresh_reactive_cache!(*args)
+ nil
end
end
@@ -96,6 +102,16 @@ module ReactiveCaching
private
+ def refresh_reactive_cache!(*args)
+ clear_reactive_cache!(*args)
+ keep_alive_reactive_cache!(*args)
+ ReactiveCachingWorker.perform_async(self.class, id, *args)
+ end
+
+ def keep_alive_reactive_cache!(*args)
+ Rails.cache.write(alive_reactive_cache_key(*args), true, expires_in: self.class.reactive_cache_lifetime)
+ end
+
def full_reactive_cache_key(*qualifiers)
prefix = self.class.reactive_cache_key
prefix = prefix.call(self) if prefix.respond_to?(:call)
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 9b3e2d4446d..396647a14ae 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -16,8 +16,8 @@ class MergeRequest < ActiveRecord::Base
include ReactiveCaching
self.reactive_cache_key = ->(model) { [model.project.id, model.iid] }
- self.reactive_cache_refresh_interval = 1.hour
- self.reactive_cache_lifetime = 1.hour
+ self.reactive_cache_refresh_interval = 10.minutes
+ self.reactive_cache_lifetime = 10.minutes
ignore_column :locked_at,
:ref_fetched,
@@ -1041,16 +1041,21 @@ class MergeRequest < ActiveRecord::Base
return { status: :error, status_reason: 'This merge request does not have test reports' }
end
- with_reactive_cache(
- :compare_test_results,
- base_pipeline&.iid,
- actual_head_pipeline.iid) { |data| data } || { status: :parsing }
+ with_reactive_cache(:compare_test_results) do |data|
+ unless Ci::CompareTestReportsService.new(project)
+ .latest?(base_pipeline, actual_head_pipeline, data)
+ raise InvalidateReactiveCache
+ end
+
+ data
+ end || { status: :parsing }
end
def calculate_reactive_cache(identifier, *args)
case identifier.to_sym
when :compare_test_results
- Ci::CompareTestReportsService.new(project).execute(*args)
+ Ci::CompareTestReportsService.new(project).execute(
+ base_pipeline, actual_head_pipeline)
else
raise NotImplementedError, "Unknown identifier: #{identifier}"
end
diff --git a/app/services/ci/compare_test_reports_service.rb b/app/services/ci/compare_test_reports_service.rb
index 7a112211d94..ec25e934a27 100644
--- a/app/services/ci/compare_test_reports_service.rb
+++ b/app/services/ci/compare_test_reports_service.rb
@@ -2,23 +2,36 @@
module Ci
class CompareTestReportsService < ::BaseService
- def execute(base_pipeline_iid, head_pipeline_iid)
- base_pipeline = project.pipelines.find_by_iid(base_pipeline_iid) if base_pipeline_iid
- head_pipeline = project.pipelines.find_by_iid(head_pipeline_iid)
+ def execute(base_pipeline, head_pipeline)
+ comparer = Gitlab::Ci::Reports::TestReportsComparer
+ .new(base_pipeline&.test_reports, head_pipeline.test_reports)
- begin
- comparer = Gitlab::Ci::Reports::TestReportsComparer
- .new(base_pipeline&.test_reports, head_pipeline.test_reports)
+ {
+ status: :parsed,
+ key: key(base_pipeline, head_pipeline),
+ data: TestReportsComparerSerializer
+ .new(project: project)
+ .represent(comparer).as_json
+ }
+ rescue => e
+ {
+ status: :error,
+ key: key(base_pipeline, head_pipeline),
+ status_reason: e.message
+ }
+ end
+
+ def latest?(base_pipeline, head_pipeline, data)
+ data&.fetch(:key, nil) == key(base_pipeline, head_pipeline)
+ end
+
+ private
- {
- status: :parsed,
- data: TestReportsComparerSerializer
- .new(project: project)
- .represent(comparer).as_json
- }
- rescue => e
- { status: :error, status_reason: e.message }
- end
+ def key(base_pipeline, head_pipeline)
+ [
+ base_pipeline&.id, base_pipeline&.updated_at,
+ head_pipeline&.id, head_pipeline&.updated_at
+ ]
end
end
end