Commit ff0eee65 authored by Rajendra Kadam's avatar Rajendra Kadam

This MR uses AppLogger in app/workers

This MR adds AppLogger in some files in
app/workers dir and also adds
changelog for the same

Replace Rails.logger with Gitlab::AppLogger in app/workers

Add changelog

Fix spec failures

Fix changelog type
parent b67a45cf
...@@ -27,6 +27,6 @@ module NewIssuable ...@@ -27,6 +27,6 @@ module NewIssuable
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
def log_error(record_class, record_id) def log_error(record_class, record_id)
Rails.logger.error("#{self.class}: couldn't find #{record_class} with ID=#{record_id}, skipping job") # rubocop:disable Gitlab/RailsLogger Gitlab::AppLogger.error("#{self.class}: couldn't find #{record_class} with ID=#{record_id}, skipping job")
end end
end end
...@@ -41,16 +41,14 @@ module ObjectStorage ...@@ -41,16 +41,14 @@ module ObjectStorage
end end
end end
# rubocop:disable Gitlab/RailsLogger
def report!(results) def report!(results)
success, failures = results.partition(&:success?) success, failures = results.partition(&:success?)
Rails.logger.info header(success, failures) Gitlab::AppLogger.info header(success, failures)
Rails.logger.warn failures(failures) Gitlab::AppLogger.warn failures(failures)
raise MigrationFailures.new(failures.map(&:error)) if failures.any? raise MigrationFailures.new(failures.map(&:error)) if failures.any?
end end
# rubocop:enable Gitlab/RailsLogger
def header(success, failures) def header(success, failures)
_("Migrated %{success_count}/%{total_count} files.") % { success_count: success.count, total_count: success.count + failures.count } _("Migrated %{success_count}/%{total_count} files.") % { success_count: success.count, total_count: success.count + failures.count }
...@@ -104,7 +102,7 @@ module ObjectStorage ...@@ -104,7 +102,7 @@ module ObjectStorage
report!(results) report!(results)
rescue SanityCheckError => e rescue SanityCheckError => e
# do not retry: the job is insane # do not retry: the job is insane
Rails.logger.warn "#{self.class}: Sanity check error (#{e.message})" # rubocop:disable Gitlab/RailsLogger Gitlab::AppLogger.warn "#{self.class}: Sanity check error (#{e.message})"
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
...@@ -34,7 +34,7 @@ class RepositoryForkWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -34,7 +34,7 @@ class RepositoryForkWorker # rubocop:disable Scalability/IdempotentWorker
def start_fork(project) def start_fork(project)
return true if start(project.import_state) return true if start(project.import_state)
Rails.logger.info("Project #{project.full_path} was in inconsistent state (#{project.import_status}) while forking.") # rubocop:disable Gitlab/RailsLogger Gitlab::AppLogger.info("Project #{project.full_path} was in inconsistent state (#{project.import_status}) while forking.")
false false
end end
......
...@@ -31,11 +31,10 @@ class RunPipelineScheduleWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -31,11 +31,10 @@ class RunPipelineScheduleWorker # rubocop:disable Scalability/IdempotentWorker
private private
# rubocop:disable Gitlab/RailsLogger
def error(schedule, error) def error(schedule, error)
failed_creation_counter.increment failed_creation_counter.increment
Rails.logger.error "Failed to create a scheduled pipeline. " \ Gitlab::AppLogger.error "Failed to create a scheduled pipeline. " \
"schedule_id: #{schedule.id} message: #{error.message}" "schedule_id: #{schedule.id} message: #{error.message}"
Gitlab::ErrorTracking Gitlab::ErrorTracking
...@@ -43,7 +42,6 @@ class RunPipelineScheduleWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -43,7 +42,6 @@ class RunPipelineScheduleWorker # rubocop:disable Scalability/IdempotentWorker
issue_url: 'https://gitlab.com/gitlab-org/gitlab-foss/issues/41231', issue_url: 'https://gitlab.com/gitlab-org/gitlab-foss/issues/41231',
schedule_id: schedule.id) schedule_id: schedule.id)
end end
# rubocop:enable Gitlab/RailsLogger
def failed_creation_counter def failed_creation_counter
@failed_creation_counter ||= @failed_creation_counter ||=
......
...@@ -17,7 +17,7 @@ class StuckCiJobsWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -17,7 +17,7 @@ class StuckCiJobsWorker # rubocop:disable Scalability/IdempotentWorker
def perform def perform
return unless try_obtain_lease return unless try_obtain_lease
Rails.logger.info "#{self.class}: Cleaning stuck builds" # rubocop:disable Gitlab/RailsLogger Gitlab::AppLogger.info "#{self.class}: Cleaning stuck builds" # rubocop:disable Gitlab/RailsLogger
drop :running, BUILD_RUNNING_OUTDATED_TIMEOUT, 'ci_builds.updated_at < ?', :stuck_or_timeout_failure drop :running, BUILD_RUNNING_OUTDATED_TIMEOUT, 'ci_builds.updated_at < ?', :stuck_or_timeout_failure
drop :pending, BUILD_PENDING_OUTDATED_TIMEOUT, 'ci_builds.updated_at < ?', :stuck_or_timeout_failure drop :pending, BUILD_PENDING_OUTDATED_TIMEOUT, 'ci_builds.updated_at < ?', :stuck_or_timeout_failure
...@@ -69,7 +69,7 @@ class StuckCiJobsWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -69,7 +69,7 @@ class StuckCiJobsWorker # rubocop:disable Scalability/IdempotentWorker
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
def drop_build(type, build, status, timeout, reason) def drop_build(type, build, status, timeout, reason)
Rails.logger.info "#{self.class}: Dropping #{type} build #{build.id} for runner #{build.runner_id} (status: #{status}, timeout: #{timeout}, reason: #{reason})" # rubocop:disable Gitlab/RailsLogger Gitlab::AppLogger.info "#{self.class}: Dropping #{type} build #{build.id} for runner #{build.runner_id} (status: #{status}, timeout: #{timeout}, reason: #{reason})"
Gitlab::OptimisticLocking.retry_lock(build, 3) do |b| Gitlab::OptimisticLocking.retry_lock(build, 3) do |b|
b.drop(reason) b.drop(reason)
end end
......
...@@ -7,7 +7,7 @@ class StuckMergeJobsWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -7,7 +7,7 @@ class StuckMergeJobsWorker # rubocop:disable Scalability/IdempotentWorker
feature_category :source_code_management feature_category :source_code_management
def self.logger def self.logger
Rails.logger # rubocop:disable Gitlab/RailsLogger Gitlab::AppLogger
end end
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
......
...@@ -11,7 +11,7 @@ class TrendingProjectsWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -11,7 +11,7 @@ class TrendingProjectsWorker # rubocop:disable Scalability/IdempotentWorker
feature_category :source_code_management feature_category :source_code_management
def perform def perform
Rails.logger.info('Refreshing trending projects') # rubocop:disable Gitlab/RailsLogger Gitlab::AppLogger.info('Refreshing trending projects')
TrendingProject.refresh! TrendingProject.refresh!
end end
......
...@@ -10,6 +10,6 @@ class UploadChecksumWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -10,6 +10,6 @@ class UploadChecksumWorker # rubocop:disable Scalability/IdempotentWorker
upload.calculate_checksum! upload.calculate_checksum!
upload.save! upload.save!
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
Rails.logger.error("UploadChecksumWorker: couldn't find upload #{upload_id}, skipping") # rubocop:disable Gitlab/RailsLogger Gitlab::AppLogger.error("UploadChecksumWorker: couldn't find upload #{upload_id}, skipping")
end end
end end
---
title: Use applogger in app/workers/*
merge_request: 41046
author: Rajendra Kadam
type: other
...@@ -14,7 +14,7 @@ RSpec.describe NewEpicWorker do ...@@ -14,7 +14,7 @@ RSpec.describe NewEpicWorker do
end end
it 'logs an error' do it 'logs an error' do
expect(Rails.logger).to receive(:error).with('NewEpicWorker: couldn\'t find Epic with ID=99, skipping job') expect(Gitlab::AppLogger).to receive(:error).with('NewEpicWorker: couldn\'t find Epic with ID=99, skipping job')
worker.perform(99, create(:user).id) worker.perform(99, create(:user).id)
end end
...@@ -28,7 +28,7 @@ RSpec.describe NewEpicWorker do ...@@ -28,7 +28,7 @@ RSpec.describe NewEpicWorker do
end end
it 'logs an error' do it 'logs an error' do
expect(Rails.logger).to receive(:error).with('NewEpicWorker: couldn\'t find User with ID=99, skipping job') expect(Gitlab::AppLogger).to receive(:error).with('NewEpicWorker: couldn\'t find User with ID=99, skipping job')
worker.perform(create(:epic).id, 99) worker.perform(create(:epic).id, 99)
end end
......
...@@ -63,7 +63,7 @@ RSpec.shared_examples 'uploads migration worker' do ...@@ -63,7 +63,7 @@ RSpec.shared_examples 'uploads migration worker' do
if success > 0 if success > 0
it 'outputs the reports' do it 'outputs the reports' do
expect(Rails.logger).to receive(:info).with(%r{Migrated #{success}/#{total} files}) expect(Gitlab::AppLogger).to receive(:info).with(%r{Migrated #{success}/#{total} files})
perform(uploads) perform(uploads)
end end
...@@ -71,7 +71,7 @@ RSpec.shared_examples 'uploads migration worker' do ...@@ -71,7 +71,7 @@ RSpec.shared_examples 'uploads migration worker' do
if failures > 0 if failures > 0
it 'outputs upload failures' do it 'outputs upload failures' do
expect(Rails.logger).to receive(:warn).with(/Error .* I am a teapot/) expect(Gitlab::AppLogger).to receive(:warn).with(/Error .* I am a teapot/)
perform(uploads) perform(uploads)
end end
......
...@@ -15,7 +15,7 @@ RSpec.describe NewIssueWorker do ...@@ -15,7 +15,7 @@ RSpec.describe NewIssueWorker do
end end
it 'logs an error' do it 'logs an error' do
expect(Rails.logger).to receive(:error).with('NewIssueWorker: couldn\'t find Issue with ID=99, skipping job') expect(Gitlab::AppLogger).to receive(:error).with('NewIssueWorker: couldn\'t find Issue with ID=99, skipping job')
worker.perform(99, create(:user).id) worker.perform(99, create(:user).id)
end end
...@@ -32,7 +32,7 @@ RSpec.describe NewIssueWorker do ...@@ -32,7 +32,7 @@ RSpec.describe NewIssueWorker do
it 'logs an error' do it 'logs an error' do
issue = create(:issue) issue = create(:issue)
expect(Rails.logger).to receive(:error).with('NewIssueWorker: couldn\'t find User with ID=99, skipping job') expect(Gitlab::AppLogger).to receive(:error).with('NewIssueWorker: couldn\'t find User with ID=99, skipping job')
worker.perform(issue.id, 99) worker.perform(issue.id, 99)
end end
......
...@@ -17,7 +17,7 @@ RSpec.describe NewMergeRequestWorker do ...@@ -17,7 +17,7 @@ RSpec.describe NewMergeRequestWorker do
it 'logs an error' do it 'logs an error' do
user = create(:user) user = create(:user)
expect(Rails.logger).to receive(:error).with('NewMergeRequestWorker: couldn\'t find MergeRequest with ID=99, skipping job') expect(Gitlab::AppLogger).to receive(:error).with('NewMergeRequestWorker: couldn\'t find MergeRequest with ID=99, skipping job')
worker.perform(99, user.id) worker.perform(99, user.id)
end end
...@@ -34,7 +34,7 @@ RSpec.describe NewMergeRequestWorker do ...@@ -34,7 +34,7 @@ RSpec.describe NewMergeRequestWorker do
it 'logs an error' do it 'logs an error' do
merge_request = create(:merge_request) merge_request = create(:merge_request)
expect(Rails.logger).to receive(:error).with('NewMergeRequestWorker: couldn\'t find User with ID=99, skipping job') expect(Gitlab::AppLogger).to receive(:error).with('NewMergeRequestWorker: couldn\'t find User with ID=99, skipping job')
worker.perform(merge_request.id, 99) worker.perform(merge_request.id, 99)
end end
......
...@@ -59,7 +59,7 @@ RSpec.describe RunPipelineScheduleWorker do ...@@ -59,7 +59,7 @@ RSpec.describe RunPipelineScheduleWorker do
end end
it 'logging a pipeline error' do it 'logging a pipeline error' do
expect(Rails.logger) expect(Gitlab::AppLogger)
.to receive(:error) .to receive(:error)
.with(a_string_matching('ActiveRecord::StatementInvalid')) .with(a_string_matching('ActiveRecord::StatementInvalid'))
.and_call_original .and_call_original
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment