Fix how to calculate error_count
in flags['update_logs']
for courses
#5580
Labels
error_count
in flags['update_logs']
for courses
#5580
What is happening?
Some context
Courses have a
flags
field with some metadadata. In particular, theupdate_logs
flag has information about course updates. Theerror_count
flag inside theupdate_logs
counts how many errors occurs during the update process. SeeUpdateLogger.update_course
method to understand where that flag is updated.The
UpdateLogger.update_course
method gets called during theUpdateCourseStats.initialize
with the following hash as the new log parameter:That
error_count
value comes fromUpdateServiceErrorHelper.error_count
definition, which basically keeps a counter for the error count. That counter is incremented each timeupdate_error_stats
gets called, and currently that method is only invoked in theApiErrorHandling.log_error
method.The problem
The
LiftWingApi
class implements thelog_error_batch
method to log errors in Sentry at the batch level. That means, when you callget_revision_data
for a batch of revision ids, the errors for the individual calls are accumulated and, once we're done with the batch, we log all the errors (if any) in a single Sentry log. This is to prevent a systematic problem where every request is failing to saturate our Sentry event quota.The problem here is that the
error_count
counter gets incremented at the batch level too. Notice that if there are 30 errors from a batch of 50 revisions,log_error_batch
method will get invoked only once, meaning the same thing forApiErrorHandling.log_error
and thus forupdate_error_stats
. Because of that, theerror_counter
will be incremented by one, when there were 30 new errors.TLDR; one option could be to make
UpdateServiceErrorHelper.update_error_stats
method take in an optional argumentnew_errors_count
to increment the@error_count
by that number (and not always by 1).Notice that the
ApiErrorHandling.log_error
already has the actual "new errors count" value in thesentry_extra
parameter.To Reproduce
The "tracks update errors properly in LiftWing" spec in
spec/services/update_course_stats_spec.rb
shows that the 'error_count' flag correspond to the number of batches instead of to the number of individual errors.Expected behavior
flags['update_logs'][n]['error_count']
should be the real number of errors that occurred during the update process.The text was updated successfully, but these errors were encountered: