Skip to content

Commit

Permalink
chore(routing-policy): [CHK-3671] improve ecommerce routing policies …
Browse files Browse the repository at this point in the history
…performance (#2763)

* refactor(routing-policy): [CHK-3671] change conditions from contains to startsWith to improve routing performance; add operationId to conditions to avoid potential ambiguity during routing;

* refactor(routing-policy): [CHK-3671] update ecommerce routing policies

replace local openapi paths and operationIds with APIM ones; revert conditions from startsWith to contains to prevent some urls from being excluded from routing correctly

* chore(routing-policy): change condition

* chore(routing-policy): change condition

* chore(routing-policy): change condition

* remove contains checking

* fix: docs

---------

Co-authored-by: CianoDanilo <[email protected]>
Co-authored-by: Simone Caminati <[email protected]>
Co-authored-by: Pietro Tota <[email protected]>
Co-authored-by: Gianluca Ciuffa <[email protected]>
Co-authored-by: ciuffagianluca <[email protected]>
Co-authored-by: Simone Infante <[email protected]>
  • Loading branch information
7 people authored Feb 13, 2025
1 parent 56a487c commit 6cdabe1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,22 @@
<set-header name="X-Client-Id" exists-action="override" >
<value>CHECKOUT</value>
</set-header>
<set-variable name="transactionsOperationId" value="newTransaction,getTransactionInfo,requestTransactionUserCancellation,requestTransactionAuthorization" />
<set-variable name="paymentMethodsOperationId" value="getAllPaymentMethods,getPaymentMethod,calculateFees,createSession,getSessionPaymentMethod" />
<set-variable name="paymentRequestsOperationId" value="getPaymentRequestInfo" />
<set-variable name="cartsOperationId" value="GetCarts,GetCartsRedirect" />
<choose>
<when condition="@( context.Request.Url.Path.Contains("transactions") )">
<when condition="@(Array.Exists(context.Variables.GetValueOrDefault("transactionsOperationId","").Split(','), operations => operations == context.Operation.Id))">
<set-backend-service base-url="@("https://${ecommerce_ingress_hostname}"+context.Variables["blueDeploymentPrefix"]+"/pagopa-ecommerce-transactions-service")"/>
</when>
<when condition="@( context.Request.Url.Path.Contains("payment-methods") )">
<when condition="@(Array.Exists(context.Variables.GetValueOrDefault("paymentMethodsOperationId","").Split(','), operations => operations == context.Operation.Id))">
<set-backend-service base-url="@("https://${ecommerce_ingress_hostname}"+context.Variables["blueDeploymentPrefix"]+"/pagopa-ecommerce-payment-methods-service")"/>
</when>
<when condition="@( context.Request.Url.Path.Contains("payment-requests") || context.Request.Url.Path.Contains("carts") )"> <!-- TODO use startWith -->
<when condition="@(
Array.Exists(context.Variables.GetValueOrDefault("paymentRequestsOperationId","").Split(','), operations => operations == context.Operation.Id)
||
Array.Exists(context.Variables.GetValueOrDefault("cartsOperationId","").Split(','), operations => operations == context.Operation.Id)
)">
<set-backend-service base-url="@("https://${ecommerce_ingress_hostname}"+context.Variables["blueDeploymentPrefix"]+"/pagopa-ecommerce-payment-requests-service")"/>
</when>
</choose>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@
<set-header name="X-Client-Id" exists-action="override" >
<value>CHECKOUT</value>
</set-header>
<set-variable name="transactionsV2OperationId" value="getTransactionInfo" />
<set-variable name="transactionsV21OperationId" value="newTransaction" />
<set-variable name="paymentMethodsOperationId" value="calculateFees" />
<choose>
<when condition="@( context.Request.Url.Path.Contains("transactions") && context.Operation.Id.Equals("newTransaction") )">
<when condition="@(Array.Exists(context.Variables.GetValueOrDefault("transactionsV21OperationId","").Split(','), operations => operations == context.Operation.Id))">
<set-backend-service base-url="@("https://${ecommerce_ingress_hostname}"+context.Variables["blueDeploymentPrefix"]+"/pagopa-ecommerce-transactions-service/v2.1")"/>
</when>
<when condition="@( context.Request.Url.Path.Contains("transactions") && context.Operation.Id.Equals("getTransactionInfo") )">
<when condition="@(Array.Exists(context.Variables.GetValueOrDefault("transactionsV2OperationId","").Split(','), operations => operations == context.Operation.Id))">
<set-backend-service base-url="@("https://${ecommerce_ingress_hostname}"+context.Variables["blueDeploymentPrefix"]+"/pagopa-ecommerce-transactions-service/v2")"/>
</when>
<when condition="@( context.Request.Url.Path.Contains("payment-methods") )">
<when condition="@(Array.Exists(context.Variables.GetValueOrDefault("paymentMethodsOperationId","").Split(','), operations => operations == context.Operation.Id))">
<set-backend-service base-url="@("https://${ecommerce_ingress_hostname}"+context.Variables["blueDeploymentPrefix"]+"/pagopa-ecommerce-payment-methods-service/v2")"/>
</when>
</choose>
Expand Down
19 changes: 12 additions & 7 deletions src/domains/ecommerce-app/api/ecommerce-io/v2/_base_policy.xml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<rate-limit-by-key calls="150" renewal-period="10" counter-key="@(context.Request.Headers.GetValueOrDefault("X-Forwarded-For"))" />
<!-- fragment to read user id from session token jwt claims. it return userId as sessionTokenUserId variable taken from jwt claims. if the session token
is an opaque token a "session-token-not-found" string is returned-->
is an opaque token a "session-token-not-found" string is returned-->
<include-fragment fragment-id="pay-wallet-user-id-from-session-token" />
<!-- Session eCommerce START-->
<choose>
Expand All @@ -30,7 +30,7 @@
</set-header>
<!-- Headers settings required for backend service END -->
</when>
<when condition="@("PM".Equals("{{ecommerce-for-io-pm-npg-ff}}") || ("NPGFF".Equals("{{ecommerce-for-io-pm-npg-ff}}") && !"{{pay-wallet-family-friends-user-ids}}".Contains(((string)context.Variables["sessionTokenUserId"]))))">
<when condition="@("PM".Equals("{{ecommerce-for-io-pm-npg-ff}}") || ("NPGFF".Equals("{{ecommerce-for-io-pm-npg-ff}}") && !"{{pay-wallet-family-friends-user-ids}}".Contains(((string)context.Variables["sessionTokenUserId"]))))">

<!-- Check sessiontoken START-->
<set-variable name="sessionToken" value="@(context.Request.Headers.GetValueOrDefault("Authorization", "").Replace("Bearer ",""))" />
Expand Down Expand Up @@ -60,20 +60,25 @@
</choose>

<set-variable name="blueDeploymentPrefix" value="@(context.Request.Headers.GetValueOrDefault("deployment","").Contains("blue")?"/beta":"")" />
<set-variable name="transactionsOperationId" value="newTransactionForIO,getTransactionInfoForIO,requestTransactionUserCancellationForIO,requestTransactionAuthorizationForIO" />
<set-variable name="paymentMethodsOperationId" value="getAllPaymentMethodsForIO,calculateFeesForIO" />
<set-variable name="paymentRequestsOperationId" value="getPaymentRequestInfoForIO" />
<set-variable name="lastPaymentMethodUsedOperationId" value="getUserLastPaymentMethodUsed" />
<set-variable name="walletsOperationId" value="createWalletForTransactionsForIO,getWalletsByIdIOUser" />
<choose>
<when condition="@( context.Request.Url.Path.Contains("transactions") )">
<when condition="@(Array.Exists(context.Variables.GetValueOrDefault("transactionsOperationId","").Split(','), operations => operations == context.Operation.Id))">
<set-backend-service base-url="@("https://${ecommerce_ingress_hostname}"+context.Variables["blueDeploymentPrefix"]+"/pagopa-ecommerce-transactions-service")"/>
</when>
<when condition="@( context.Request.Url.Path.Contains("payment-methods") )">
<when condition="@(Array.Exists(context.Variables.GetValueOrDefault("paymentMethodsOperationId","").Split(','), operations => operations == context.Operation.Id))">
<set-backend-service base-url="@("https://${ecommerce_ingress_hostname}"+context.Variables["blueDeploymentPrefix"]+"/pagopa-ecommerce-payment-methods-service")"/>
</when>
<when condition="@( context.Request.Url.Path.Contains("payment-requests") )">
<when condition="@(Array.Exists(context.Variables.GetValueOrDefault("paymentRequestsOperationId","").Split(','), operations => operations == context.Operation.Id))">
<set-backend-service base-url="@("https://${ecommerce_ingress_hostname}"+context.Variables["blueDeploymentPrefix"]+"/pagopa-ecommerce-payment-requests-service")"/>
</when>
<when condition="@( context.Request.Url.Path.Contains("user/lastPaymentMethodUsed") )">
<when condition="@(Array.Exists(context.Variables.GetValueOrDefault("lastPaymentMethodUsedOperationId","").Split(','), operations => operations == context.Operation.Id))">
<set-backend-service base-url="@("https://${ecommerce_ingress_hostname}"+context.Variables["blueDeploymentPrefix"]+"/pagopa-ecommerce-user-stats-service")"/>
</when>
<when condition="@( context.Request.Url.Path.Contains("wallets") )">
<when condition="@(Array.Exists(context.Variables.GetValueOrDefault("walletsOperationId","").Split(','), operations => operations == context.Operation.Id))">
<set-backend-service base-url="@("https://${wallet_ingress_hostname}"+context.Variables["blueDeploymentPrefix"]+"/pagopa-wallet-service")"/>
</when>
</choose>
Expand Down

0 comments on commit 6cdabe1

Please sign in to comment.