Commit cc55bd02 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Track exceptions for namespace statistics

This tracks exceptions for updating namespace statistics in Sentry
instead of logs.
parent 2665e40c
...@@ -16,13 +16,7 @@ module Namespaces ...@@ -16,13 +16,7 @@ module Namespaces
namespace.aggregation_schedule.destroy namespace.aggregation_schedule.destroy
rescue ::Namespaces::StatisticsRefresherService::RefresherError, ActiveRecord::RecordNotFound => ex rescue ::Namespaces::StatisticsRefresherService::RefresherError, ActiveRecord::RecordNotFound => ex
log_error(namespace.full_path, ex.message) if namespace Gitlab::ErrorTracking.track_exception(ex, namespace_id: namespace_id, namespace: namespace&.full_path)
end
private
def log_error(namespace_path, error_message)
Gitlab::SidekiqLogger.error("Namespace statistics can't be updated for #{namespace_path}: #{error_message}")
end end
end end
end end
...@@ -16,8 +16,8 @@ module Namespaces ...@@ -16,8 +16,8 @@ module Namespaces
return if root_ancestor.aggregation_scheduled? return if root_ancestor.aggregation_scheduled?
Namespace::AggregationSchedule.safe_find_or_create_by!(namespace_id: root_ancestor.id) Namespace::AggregationSchedule.safe_find_or_create_by!(namespace_id: root_ancestor.id)
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound => ex
log_error(namespace_id) Gitlab::ErrorTracking.track_exception(ex, namespace_id: namespace_id)
end end
private private
...@@ -34,9 +34,5 @@ module Namespaces ...@@ -34,9 +34,5 @@ module Namespaces
Namespace::AggregationSchedule.table_exists? Namespace::AggregationSchedule.table_exists?
end end
def log_error(root_ancestor_id)
Gitlab::SidekiqLogger.error("Namespace can't be scheduled for aggregation: #{root_ancestor_id} does not exist")
end
end end
end end
...@@ -42,7 +42,7 @@ describe Namespaces::RootStatisticsWorker, '#perform' do ...@@ -42,7 +42,7 @@ describe Namespaces::RootStatisticsWorker, '#perform' do
allow_any_instance_of(Namespace::AggregationSchedule) allow_any_instance_of(Namespace::AggregationSchedule)
.to receive(:schedule_root_storage_statistics).and_return(nil) .to receive(:schedule_root_storage_statistics).and_return(nil)
expect(Gitlab::SidekiqLogger).to receive(:error).once expect(Gitlab::ErrorTracking).to receive(:track_exception).once
worker.perform(group.id) worker.perform(group.id)
end end
......
...@@ -48,7 +48,7 @@ describe Namespaces::ScheduleAggregationWorker, '#perform', :clean_gitlab_redis_ ...@@ -48,7 +48,7 @@ describe Namespaces::ScheduleAggregationWorker, '#perform', :clean_gitlab_redis_
context 'when namespace does not exist' do context 'when namespace does not exist' do
it 'logs the error' do it 'logs the error' do
expect(Gitlab::SidekiqLogger).to receive(:error).once expect(Gitlab::ErrorTracking).to receive(:track_exception).once
worker.perform(12345) worker.perform(12345)
end end
......
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