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
# rubocop: enable CodeReuse/ActiveRecord
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
......@@ -41,16 +41,14 @@ module ObjectStorage
end
end
# rubocop:disable Gitlab/RailsLogger
def report!(results)
success, failures = results.partition(&:success?)
Rails.logger.info header(success, failures)
Rails.logger.warn failures(failures)
Gitlab::AppLogger.info header(success, failures)
Gitlab::AppLogger.warn failures(failures)
raise MigrationFailures.new(failures.map(&:error)) if failures.any?
end
# rubocop:enable Gitlab/RailsLogger
def header(success, failures)
_("Migrated %{success_count}/%{total_count} files.") % { success_count: success.count, total_count: success.count + failures.count }
......@@ -104,7 +102,7 @@ module ObjectStorage
report!(results)
rescue SanityCheckError => e
# 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
# rubocop: enable CodeReuse/ActiveRecord
......
......@@ -34,7 +34,7 @@ class RepositoryForkWorker # rubocop:disable Scalability/IdempotentWorker
def start_fork(project)
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
end
......
......@@ -31,11 +31,10 @@ class RunPipelineScheduleWorker # rubocop:disable Scalability/IdempotentWorker
private
# rubocop:disable Gitlab/RailsLogger
def error(schedule, error)
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}"
Gitlab::ErrorTracking
......@@ -43,7 +42,6 @@ class RunPipelineScheduleWorker # rubocop:disable Scalability/IdempotentWorker
issue_url: 'https://gitlab.com/gitlab-org/gitlab-foss/issues/41231',
schedule_id: schedule.id)
end
# rubocop:enable Gitlab/RailsLogger
def failed_creation_counter
@failed_creation_counter ||=
......
......@@ -17,7 +17,7 @@ class StuckCiJobsWorker # rubocop:disable Scalability/IdempotentWorker
def perform
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 :pending, BUILD_PENDING_OUTDATED_TIMEOUT, 'ci_builds.updated_at < ?', :stuck_or_timeout_failure
......@@ -69,7 +69,7 @@ class StuckCiJobsWorker # rubocop:disable Scalability/IdempotentWorker
# rubocop: enable CodeReuse/ActiveRecord
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|
b.drop(reason)
end
......
......@@ -7,7 +7,7 @@ class StuckMergeJobsWorker # rubocop:disable Scalability/IdempotentWorker
feature_category :source_code_management
def self.logger
Rails.logger # rubocop:disable Gitlab/RailsLogger
Gitlab::AppLogger
end
# rubocop: disable CodeReuse/ActiveRecord
......
......@@ -11,7 +11,7 @@ class TrendingProjectsWorker # rubocop:disable Scalability/IdempotentWorker
feature_category :source_code_management
def perform
Rails.logger.info('Refreshing trending projects') # rubocop:disable Gitlab/RailsLogger
Gitlab::AppLogger.info('Refreshing trending projects')
TrendingProject.refresh!
end
......
......@@ -10,6 +10,6 @@ class UploadChecksumWorker # rubocop:disable Scalability/IdempotentWorker
upload.calculate_checksum!
upload.save!
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
---
title: Use applogger in app/workers/*
merge_request: 41046
author: Rajendra Kadam
type: other
......@@ -14,7 +14,7 @@ RSpec.describe NewEpicWorker do
end
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)
end
......@@ -28,7 +28,7 @@ RSpec.describe NewEpicWorker do
end
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)
end
......
......@@ -63,7 +63,7 @@ RSpec.shared_examples 'uploads migration worker' do
if success > 0
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)
end
......@@ -71,7 +71,7 @@ RSpec.shared_examples 'uploads migration worker' do
if failures > 0
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)
end
......
......@@ -15,7 +15,7 @@ RSpec.describe NewIssueWorker do
end
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)
end
......@@ -32,7 +32,7 @@ RSpec.describe NewIssueWorker do
it 'logs an error' do
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)
end
......
......@@ -17,7 +17,7 @@ RSpec.describe NewMergeRequestWorker do
it 'logs an error' do
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)
end
......@@ -34,7 +34,7 @@ RSpec.describe NewMergeRequestWorker do
it 'logs an error' do
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)
end
......
......@@ -59,7 +59,7 @@ RSpec.describe RunPipelineScheduleWorker do
end
it 'logging a pipeline error' do
expect(Rails.logger)
expect(Gitlab::AppLogger)
.to receive(:error)
.with(a_string_matching('ActiveRecord::StatementInvalid'))
.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