-
Notifications
You must be signed in to change notification settings - Fork 660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Outreachy Round 27] Create ReferenceCounterApi class to hit new Reference Counter API #5565
Conversation
lib/reference_counter_api.rb
Outdated
log_error(e, update_service: @update_service, | ||
sentry_extra: { project_code: @project_code, | ||
language_code: @language_code, rev_id: }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did use the ApiErrorHandling
here because I'm rescuing a real error.
We may want to add a retry strategy here, as maybe the errors in TYPICAL_ERRORS
are frequent? Do you know if there is any common strategy that is used in the project?
@Aminehassou feel free to take a look at the PR when you have the chance! |
CI is failing, but I don't think those errors are related to my changes.
There is still an error related to the browser. I don't know if it's related to the new -
|
I think I've fixed all the unrelated spec failures. If you rebase this, hopefully it will be passing now. |
5f16bb7
to
25da718
Compare
@ragesoss you can take a look at this whenever you have the chance, CI is green now! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks solid overall!
lib/reference_counter_api.rb
Outdated
level: 'warning', extra: { project_code: @project_code, | ||
language_code: @language_code, rev_id:, | ||
status_code: response.status, content: parsed_response } | ||
return -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why return -1 (rather than nil
, for example)? This class is mainly dealing with integers that represent reference counts, so using an integer as an error/warning signal is likely to lead to confusion at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially, I considered using -1 as a means to distinguish (at the database level) between revisions where there was an error attempting to retrieve the number of references, and revisions for which we have not yet calculated that.
However, this approach was based on the assumption that the references
field in the database would be an integer, which is not the case (we'll be using the existing features
field). I believe I can find an alternative method to distinguish between these two cases after refactoring the revision score importer.
I changed this to return nil
instead in ca7a4b2
Edit: the good commit is c2bf974
… class makes requests to the new Toolforge Reference Counter API
… raising InvalidWikiError
ca7a4b2
to
c2bf974
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good. Good work!
rescue StandardError => e | ||
@errors << e | ||
return {} | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Followed the same approach as for the LiftWingApi
: errors are accumulated and logged at the batch level.
However, warnings related to responses not being 200 OK keep being logged individually. I think that makes sense for now, because the reference-counter API is under our own control, so we have to monitor this to be able to fix all the necessary bugs. If at some point we find benign frequent non-200 responses and we don't want to log all of them, we can easily change this.
What this PR does
This PR is part of the "Improve how Wiki Education Dashboard counts references added" project (read issue #5547).
The purpose of this PR is to add a
ReferenceCounterApi
class, which is in charge of making requests to the new Toolforge Reference Counter API.The
ReferenceCounterApi
is quite simple. It's intended to be used to retrieve the number of references in a given revision id, across every wiki (language/project) except forwikidata
(this is becausewikidata
works pretty different from other wikis, and there is a specific gem to get references from it).The main entry point for this class is
get_number_of_references_from_revision_id
method. It takes the revision id, and returns the number of references existing in the revision, or -1 if there was any problem hitting the API (as a side effect, it logs errors in Sentry).This PR also adds basic specs for
ReferenceCounterApi
.Open questions and concerns
For now,
ReferenceCounterApi
class processes one revision ID per request due to limitations in the Toolforge Reference Counter API, which doesn't support batching (querying more than one revision ID in a single request). If we we observe a decline in performance as a result of this approach, we will explore modifications to the Toolforge API to enable batch processing.