Skip to content
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

Add EditionIdCAPIMapper #26830

Merged

Conversation

ioannakok
Copy link
Contributor

@ioannakok ioannakok commented Jan 19, 2024

Closes #9553

Paired with @arelra

What does this change?

Introduces a mapper that passes "EUROPE" instead of "EUR" and "INTERNATIONAL" instead of "INT" in the item queries to CAPI.

Why?

  1. We noticed that the MostPopularAgent queries CAPI using the wrong edition id for the Europe and International editions. It uses "EUR" and "INT" instead of "EUROPE" and "INTERNATIONAL" as expected by CAPI. As a result, the following endpoints called by DCR MostViewedFooterData return a 404:

The change we're making populates the agent with content for these two editions and fixes the above endpoints.

  1. We've confirmed with the CAPI team that all of CAPI's endpoints expect the long form id, i.e. europe, international?

Note

We think that the best solution for this problem is to rename the ids for the Europe and International edition but this
needs more analysis and we expect it to be a bigger change that will touch frontend, DCR and fastly-edge-cache.
See comment here. We've created a ticket.

Screenshots

Before After
image image
image image

Checklist

@@ -82,8 +81,8 @@ object Edition {
}

def apply(request: RequestHeader): Edition = {
val cookieValue = editionFromRequest(request)
Copy link
Contributor Author

@ioannakok ioannakok Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming because cookieValue is misleading. This method returns the edition from a parameter, a header or a cookie.

@@ -76,7 +76,7 @@ trait ApiQueryDefaults extends GuLogging {

def item(id: String): ItemQuery = CapiContentApiClient.item(id)

def item(id: String, edition: Edition): ItemQuery = item(id, edition.id)
def item(id: String, edition: Edition): ItemQuery = item(id, EditionIdCAPIMapper.mapEditionId(edition))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mapping looks good to me as Content-api's Conceirge reads us, uk, au, europe, international so it has to be this to give the content.
Mapping done in this PR should be fine. Still will get CoPip team to give review on this as well.

Just being curious, some que on this:

  1. Can we try changing Edition id from EUR to EUROPE?

  2. If not above, then can we try accessing networkfrontId here as that refers to europe, so can we try checking if edition.id != edition.networkfrontId (which is true in this case) so then access networkFrontId instead? (I know here priority should be edition.id but just curious to know if we can do these cases, then we might not need mapping.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much @Divs-B for the review! Re point 2, networkFrontId achieves indeed what we want without having to map. However, I would prefer to avoid this solution as it’s more subtle and it wouldn't be super clear from its name why we're passing the network id instead of the id. Whereas at least the EditionIdCAPIMapper is more descriptive. I agree though the ideal solution would be option 1, to change the id. Unfortunately this requires a big refactoring in at least 3 repos from what I can tell. Haven't done full analysis but here are some examples:

For these reasons we would prefer to go with the mapper for now but I have created a ticket to rename the IDs as this is the best approach:

And one question: Is Concierge the interface to all CAPI requests? Does that mean that all of CAPI's endpoints expect the long form id i.e. europe, international?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ioannakok for your answers.
Details about the work it requires to refactor in many places, I think it does help in justifying to go ahead with the mapping at the moment in this PR as a best solution.
Indeed we would want to keep a consistent name (example "EUROPE") as id across all Guardian repos hence #26851 would be a great idea. Thanks for that, Ioanna.
We are happy to approve this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding your query:
Is Concierge the interface to all CAPI requests? Does that mean that all of CAPI's endpoints expect the long form id i.e. europe, international?

Yes
(but I will confirm with my team as well) 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Team also has confirmed the same for Concierge 👍
As aforementioned, consistent name would be great idea to keep and as long as Concierge reading correct form of id it should return the content whether any long form in it. Thankyou.

Copy link
Member

@arelra arelra Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Divs-B thanks for your review!

Out of an abundance of caution we checked in Kibana whether any other requests (other than most-viewed) are made to CAPI from frontend using the short edition ids of EUR or INT. Using the query in the Content Platforms space and logstash-capi-* index we could see a variety of requests using EUR or INT

Here are few example queries to demonstrate the different frontend applications making requests to CAPI using the short form ids of either EUR or INT:

EUR form the facia app
INT from the article app
INT from applications
INT from applications-crosswords

Manually updating the edition id to the long form id returns the same response so we assume the edition parameter does not actually affect the query response.

Could you please confirm our understanding that the queries above do not use the edition parameter so updating the edition id to the long form should have no effect.

Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello. CAPI only becomes interested in the edition parameter if the query is for what looks like a network front (from days before the Fronts API existed IIRC) or an editionalised section, e.g. sport. In the examples you've linked, these appear to be mostly individual content item or tag searches, and those will ignore the edition. If you're curious about which sections are editionalised, you can go to content.guardianapis.com/sections and look for any with multiple editions listed. Hope this helps 🤞

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @JustinPinner and @Divs-B very helpful

We noticed that the `MostPopularAgent` queries CAPI using the wrong edition id for the Europe and International editions. It uses "EUR" and "INT" instead of "EUROPE" and "INTERNATIONAL" as expected by CAPI. We're introducing this mapper that will populate the agent with content for these two editions.

Co-authored-by: Ravi <[email protected]>
@ioannakok ioannakok force-pushed the fix-most-popular-capi-query-for-europe-and-int-edition branch from 730a4d7 to 31ddec2 Compare February 7, 2024 09:35
@ioannakok ioannakok marked this pull request as ready for review February 7, 2024 10:15
@ioannakok ioannakok requested a review from a team as a code owner February 7, 2024 10:15
Copy link
Contributor

@DanielCliftonGuardian DanielCliftonGuardian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

Copy link
Contributor

@mxdvl mxdvl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BIG BOLD CAPITALS

@ioannakok ioannakok merged commit 637b1f9 into main Feb 8, 2024
2 checks passed
@ioannakok ioannakok deleted the fix-most-popular-capi-query-for-europe-and-int-edition branch February 8, 2024 10:16
@ioannakok
Copy link
Contributor Author

BIG BOLD CAPITALS

ABSOLUTELY. I BELIEVE THAT'S THE WAY TO GO IN PR DESCRIPTIONS AS WELL

@prout-bot
Copy link
Collaborator

Seen on FRONTS-PROD (merged by @ioannakok 11 minutes and 14 seconds ago)

@prout-bot
Copy link
Collaborator

Seen on ADMIN-PROD (merged by @ioannakok 11 minutes and 25 seconds ago)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix most-read.json?_edition=EUR&dcr=true endpoint
7 participants