Page MenuHomePhabricator

recommendation-api /api/v1/translation/page-collections throws 500 when cache is empty
Closed, ResolvedPublic2 Estimated Story PointsBUG REPORT

Description

Remove .cache folder and run the server. Hit /api/v1/translation/page-collections

Following error is observed.

/api/v1/translation/page-collections" 500 Internal Server Error <ResponseValidationError: 1 validation errors:
  {'type': 'list_type', 'loc': ('response',), 'msg': 'Input should be a valid list', 'input': None}
>

This is random because of Modulo 4 check in the lifespan event for the process Id.

Event Timeline

Problematic code:

# TODO: Use env variable for number of workers
number_of_workers = 4
if worker_id % number_of_workers == 0:  # we are using 4

Change #1097181 had a related patch set uploaded (by Santhosh; author: Santhosh):

[research/recommendation-api@master] Make sure application is started with initialized cache

https://gerrit.wikimedia.org/r/1097181

Change #1097181 had a related patch set uploaded (by Santhosh; author: Santhosh):

[research/recommendation-api@master] Make sure application is started with initialized cache

https://gerrit.wikimedia.org/r/1097181

In this patch, I addressed only one isse - The empty cache when application startup.

It seperates the cache filling when application is starting up from periodic updates. Periodic updates can be addressed in a diffrerent patch. If we address the TODO part in the code, it should be fixed.
However, it is very important to have cache filled before the apis start working. So make sure cache is initialized before server startup.

santhosh changed the task status from Open to In Progress.Nov 25 2024, 7:19 AM
santhosh triaged this task as High priority.

Change #1097181 merged by jenkins-bot:

[research/recommendation-api@master] Make sure application is started with initialized cache

https://gerrit.wikimedia.org/r/1097181

Nikerabbit set the point value for this task to 2.Nov 26 2024, 8:14 AM

+ Recommendation-API (please add project tags so other people who don't know or don't care about team tags can also find tasks. Thanks!)

Change #1098495 had a related patch set uploaded (by KartikMistry; author: KartikMistry):

[operations/deployment-charts@master] Update recommendation-api to 2024-11-27-065850-production

https://gerrit.wikimedia.org/r/1098495

Change #1098495 merged by jenkins-bot:

[operations/deployment-charts@master] Update recommendation-api to 2024-11-27-065850-production

https://gerrit.wikimedia.org/r/1098495

SBisson subscribed.

This was deployed. We can now see that the api returns an empty list when no collections exist in the cache (it's the case at the time of writing this).

https://api.wikimedia.org/service/lw/recommendation/api/v1/translation/page-collections

SBisson claimed this task.

The cache has been empty and the recommendation api collections endpoint has been returning [] for the best part of last week. I'm boldly closing this.