Page MenuHomePhabricator

[SPIKE] Send an image thumbnail to the logo detection service
Closed, ResolvedPublic

Description

In T363506: Pass image objects to the logo detection service we discussed options to prevent the service from downloading an uploaded image via a stash URL, which has limitations in terms of security (see T362749#9785333), privacy (see T362749#9785550, T362749#9786161), and likely performance.

The agreed solution is to send a thumbnail image object to the logo detection service: investigate its feasibility.

Steps

  • investigate if we can access Thumbor's results of stashed images from MediaWiki - SpecialUploadStash has an outputThumbFromStash method, which seems to indicate that it's possible
  • the thumbnail should be 224x224 pixels
  • decide the image serialization format, e.g., binary or i.e., base64
  • inform ML in T363506#9794241 T364551#9977031
  • set up an internal API endpoint in Upload Wizard that
    • accesses the stashed thumbnail
    • sends it to a LiftWing internal endpoint - the logo detection service isn't exposed yet, so it might be worth trying with an available one
    • includes a content length request header
  • let the endpoint accept a filekey parameter
  • let the endpoint accept a filename parameter as per T368624#9943707

Event Timeline

mfossati renamed this task from [SPIKE] Resize an image file to 224x224 pixels within Upload Wizard to [SPIKE] Send an image thumbnail to the logo detection service within Upload Wizard.May 14 2024, 2:20 PM
mfossati updated the task description. (Show Details)

Change #1036637 had a related patch set uploaded (by Matthias Mullie; author: Matthias Mullie):

[mediawiki/extensions/UploadWizard@master] [POC] API endpoint to submit stashed thumb to liftwing

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

Change #1036637 merged by jenkins-bot:

[mediawiki/extensions/UploadWizard@master] API endpoint to submit stashed thumb to liftwing

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

@matthiasmullie wrote:

Hi @kevinbazira; we finally have an API in production that is supposed to send data to the logo detection service at https://inference-staging.svc.codfw.wmnet:30443/v1/models/logo-detection:predict
It doesn’t fully seem to work, though - it looks like some servers are able to access that uri, while others are not.
E.g.:

curl -H 'X-Wikimedia-Debug: backend=mwdebug1001.eqiad.wmnet' https://commons.wikimedia.org/w/api.php\?action\=mediadetection\&format\=json\&formatversion\=2\&filekey\=1b2a8gxjr6m0.xox7qj.6750701.jpg
{"predictions":[{"filename":"1b2a8gxjr6m0.xox7qj.6750701.jpg","target":"logo","prediction":0.0035,"out_of_domain":0.9965}]}

but:

curl -H 'X-Wikimedia-Debug: backend=k8s-mwdebug' https://commons.wikimedia.org/w/api.php\?action\=mediadetection\&format\=json\&formatversion\=2\&filekey\=1b2a8gxjr6m0.xox7qj.6750701.jpg
{"error":{"code":"http-timed-out","info":"HTTP request timed out.","docref":"See https://commons.wikimedia.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/postorius/lists/mediawiki-api-announce.lists.wikimedia.org/> for notice of API deprecations and breaking changes."},"servedby":"mw-debug.eqiad.pinkunicorn-b74f6b749-d6pc6"}

We suspect that that internal endpoint is not available to mw k8s nodes - do you know how to make them accessible?

Great to see that the Media Detection API is now in production! @klausman , @isarantopoulos : the Structured Content team has been using the internal endpoint of the logo-detection isvc hosted on LiftWing staging. As indicated in the issue above, the mw k8s nodes are unable to access this endpoint. I have managed to reproduce this issue and also checked the model-server logs shared in P66409 . Would an internal endpoint on prod be accessible? Should we consider providing a prod external endpoint?

mfossati changed the task status from Open to In Progress.Jul 15 2024, 3:45 PM
mfossati updated Other Assignee, added: mfossati.
mfossati updated the task description. (Show Details)

Thanks @kevinbazira for the prompt action. @klausman @isarantopoulos , as we're now entering hypothesis work under time constraints, could you please give us an estimate to tackle this request?
The LiftWing endpoint being accessible is a hard requirement for T368624: [XL] Post-upload job to detect logos. CC @AUgolnikova-WMF .

In the past we have used the envoy proxy to access Lift Wing from mw. Here is the relevant piece of config used by the Ores Extension.
Here is the relevant piece of config in puppet that configures Lift Wing production (service is named as inference) and the one for ml-staging (named as inference-staging).

That means that we could try localhost:6031 for Lift Wing production and localhost:6205 for Lift Wing staging.
If it doen't work we'll have to ask around if there is anything we're missing from the puzzle.
I tested the above from mwdebug1002 and I'm able to access the prod one but I get a connection refused for staging Failed to connect to localhost port 6205: Connection refused

Also it is important to note that the internal endpoints on Lift Wing are not accessible from the beta cluster (only public endpoints can be accessed from there)

Change #1056450 had a related patch set uploaded (by Matthias Mullie; author: Matthias Mullie):

[mediawiki/extensions/UploadWizard@master] Add filename param for already-published files

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

@mfossati after our discussion I said I'll provide the links to the mediawiki code in ores extension that makes requests to Lift Wing:

Change #1056450 merged by jenkins-bot:

[mediawiki/extensions/UploadWizard@master] Add filename param for already-published files.

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

• AUgolnikova-WMF renamed this task from [SPIKE] Send an image thumbnail to the logo detection service within Upload Wizard to [SPIKE] Send an image thumbnail to the logo detection service.Jul 31 2024, 2:20 PM
• AUgolnikova-WMF updated the task description. (Show Details)
curl -H 'X-Wikimedia-Debug: backend=mwdebug1001.eqiad.wmnet' 'https://commons.wikimedia.org/w/api.php?action=mediadetection&format=json&formatversion=2&filename=Pinus_brutia_01.jpg'
{"predictions":[{"filename":"Pinus_brutia_01.jpg","target":"logo","prediction":0.0005,"out_of_domain":0.9995}]}

Looks good, closing.