Introduce Redis helpers. Rename BuildTraceChunkFlushToDbWorker to Ci::BuildTraceChunkFlushWorker.

This commit is contained in:
Shinya Maeda 2018-05-04 17:02:08 +09:00
parent 47c8e06cef
commit 812dd06d51
9 changed files with 51 additions and 30 deletions

View File

@ -99,7 +99,7 @@ module Ci
def schedule_to_db def schedule_to_db
return if db? return if db?
BuildTraceChunkFlushToDbWorker.perform_async(id) Ci::BuildTraceChunkFlushWorker.perform_async(id)
end end
def fullfilled? def fullfilled?

View File

@ -66,7 +66,7 @@
- pipeline_processing:pipeline_update - pipeline_processing:pipeline_update
- pipeline_processing:stage_update - pipeline_processing:stage_update
- pipeline_processing:update_head_pipeline_for_merge_request - pipeline_processing:update_head_pipeline_for_merge_request
- pipeline_processing:build_trace_chunk_flush_to_db - pipeline_processing:ci_build_trace_chunk_flush
- repository_check:repository_check_clear - repository_check:repository_check_clear
- repository_check:repository_check_single_repository - repository_check:repository_check_single_repository

View File

@ -1,12 +0,0 @@
class BuildTraceChunkFlushToDbWorker
include ApplicationWorker
include PipelineQueue
queue_namespace :pipeline_processing
def perform(build_trace_chunk_id)
Ci::BuildTraceChunk.find_by(id: build_trace_chunk_id).try do |build_trace_chunk|
build_trace_chunk.use_database!
end
end
end

View File

@ -0,0 +1,13 @@
module Ci
class BuildTraceChunkFlushWorker
include ApplicationWorker
queue_namespace :pipeline_processing
def perform(build_trace_chunk_id)
::Ci::BuildTraceChunk.find_by(id: build_trace_chunk_id).try do |build_trace_chunk|
build_trace_chunk.use_database!
end
end
end
end

View File

@ -75,7 +75,7 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
let(:value) { 'a' * described_class::CHUNK_SIZE } let(:value) { 'a' * described_class::CHUNK_SIZE }
it 'schedules stashing data' do it 'schedules stashing data' do
expect(BuildTraceChunkFlushToDbWorker).to receive(:perform_async).once expect(Ci::BuildTraceChunkFlushWorker).to receive(:perform_async).once
subject subject
end end
@ -112,7 +112,7 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
context 'when fullfilled chunk size' do context 'when fullfilled chunk size' do
it 'does not schedule stashing data' do it 'does not schedule stashing data' do
expect(BuildTraceChunkFlushToDbWorker).not_to receive(:perform_async) expect(Ci::BuildTraceChunkFlushWorker).not_to receive(:perform_async)
subject subject
end end

View File

@ -2,7 +2,7 @@ require 'spec_helper'
describe API::Runner, :clean_gitlab_redis_shared_state do describe API::Runner, :clean_gitlab_redis_shared_state do
include StubGitlabCalls include StubGitlabCalls
include ChunkedIOHelpers include RedisHelpers
let(:registration_token) { 'abcdefg123456' } let(:registration_token) { 'abcdefg123456' }
@ -873,8 +873,8 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
patch_the_trace patch_the_trace
expect(job.reload.trace.raw).to eq 'BUILD TRACE appended appended' expect(job.reload.trace.raw).to eq 'BUILD TRACE appended appended'
# GitLab-Rails enxounters an outage on Redis # GitLab-Rails encounters an outage on Redis
redis_shared_state_outage! redis_shared_state_cleanup!
expect(job.reload.trace.raw).to eq '' expect(job.reload.trace.raw).to eq ''
# GitLab-Runner patchs # GitLab-Runner patchs

View File

@ -86,6 +86,7 @@ RSpec.configure do |config|
config.include WaitForRequests, :js config.include WaitForRequests, :js
config.include LiveDebugger, :js config.include LiveDebugger, :js
config.include MigrationsHelpers, :migration config.include MigrationsHelpers, :migration
config.include RedisHelpers
if ENV['CI'] if ENV['CI']
# This includes the first try, i.e. tests will be run 4 times before failing. # This includes the first try, i.e. tests will be run 4 times before failing.
@ -146,21 +147,27 @@ RSpec.configure do |config|
end end
config.around(:each, :clean_gitlab_redis_cache) do |example| config.around(:each, :clean_gitlab_redis_cache) do |example|
Gitlab::Redis::Cache.with(&:flushall) redis_cache_cleanup!
example.run example.run
Gitlab::Redis::Cache.with(&:flushall) redis_cache_cleanup!
end end
config.around(:each, :clean_gitlab_redis_shared_state) do |example| config.around(:each, :clean_gitlab_redis_shared_state) do |example|
Gitlab::Redis::SharedState.with(&:flushall) redis_shared_state_cleanup!
Sidekiq.redis(&:flushall)
example.run example.run
Gitlab::Redis::SharedState.with(&:flushall) redis_shared_state_cleanup!
Sidekiq.redis(&:flushall) end
config.around(:each, :clean_gitlab_redis_queues) do |example|
redis_queues_cleanup!
example.run
redis_queues_cleanup!
end end
# The :each scope runs "inside" the example, so this hook ensures the DB is in the # The :each scope runs "inside" the example, so this hook ensures the DB is in the

View File

@ -8,9 +8,4 @@ module ChunkedIOHelpers
stub_const('Ci::BuildTraceChunk::CHUNK_SIZE', size) stub_const('Ci::BuildTraceChunk::CHUNK_SIZE', size)
stub_const('Gitlab::Ci::Trace::ChunkedIO::CHUNK_SIZE', size) stub_const('Gitlab::Ci::Trace::ChunkedIO::CHUNK_SIZE', size)
end end
def redis_shared_state_outage!
Gitlab::Redis::SharedState.with(&:flushall)
Sidekiq.redis(&:flushall)
end
end end

View File

@ -0,0 +1,18 @@
module RedisHelpers
# config/README.md
# Usage: performance enhancement
def redis_cache_cleanup!
Gitlab::Redis::Cache.with(&:flushall)
end
# Usage: SideKiq, Mailroom, CI Runner, Workhorse, push services
def redis_queues_cleanup!
Gitlab::Redis::Queues.with(&:flushall)
end
# Usage: session state, rate limiting
def redis_shared_state_cleanup!
Gitlab::Redis::SharedState.with(&:flushall)
end
end