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

[IOPAE-1711] Api rate limit 250 for io novità e aggiornamenti service #1390

Merged
merged 3 commits into from
Jan 29, 2025

Conversation

StefanoDoc
Copy link
Contributor

@StefanoDoc StefanoDoc commented Jan 24, 2025

Motivation and Context

Api rate limit 250 for io novità e aggiornamenti service

Major Changes

in short the azure-deployc49a service will have to send 20,000,000 messages and a request has arrived to apply a ratelimit250 only for that service temporarily, the solution that seemed simplest and quick was to apply a policy on the IO-SERVICE-API product, we did some tests using another service via the portal and it worked

Dependencies

Testing

Documentation

Other Considerations

Copy link
Contributor

@rodoviti rodoviti left a comment

Choose a reason for hiding this comment

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

lgtm

@StefanoDoc StefanoDoc marked this pull request as ready for review January 27, 2025 15:07
@StefanoDoc StefanoDoc requested a review from a team as a code owner January 27, 2025 15:07
@StefanoDoc StefanoDoc enabled auto-merge January 29, 2025 08:29
@StefanoDoc
Copy link
Contributor Author

StefanoDoc commented Jan 29, 2025

@pagopa/engineering-team-cloud-eng i need a review by today thanks

Copy link

📖 Terraform Plan ('src/legacy-apim/prod') - success

Terraform Plan
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # module.apim_itn_product_services.azurerm_api_management_product_policy.this[0] will be updated in-place
  ~ resource "azurerm_api_management_product_policy" "this" {
        id                  = "/subscriptions/ec285037-c673-4f58-b594-d7c480da4e8b/resourceGroups/io-p-itn-common-rg-01/providers/Microsoft.ApiManagement/service/io-p-itn-apim-01/products/io-services-api"
      ~ xml_content         = <<-EOT
          - <policies>
          - 	<inbound>
          - 		<base />
          - 		<choose>
          - 			<when condition="@(context.User.Groups.Select(g => g.Name).Contains("ApiNoRateLimit"))">
          - 				<!-- ApiNoRateLimit for internal/special users -->
          - 			</when>
          - 			<when condition="@(context.User.Groups.Select(g => g.Name).Contains("ApiRateLimit250"))">
          - 				<!-- ApiRateLimit 250 requests/5seconds for fast premium users -->
          - 				<rate-limit-by-key calls="250" renewal-period="5" counter-key="@(context.User.Id)" retry-after-header-name="x-rate-limit-retry-after" remaining-calls-header-name="x-rate-limit-remaining" />
          - 			</when>
          - 			<otherwise>
          - 				<!-- ApiRateLimit 150 requests/5seconds for fast standard users -->
          - 				<rate-limit-by-key calls="150" renewal-period="5" counter-key="@(context.User.Id)" retry-after-header-name="x-rate-limit-retry-after" remaining-calls-header-name="x-rate-limit-remaining" />
          - 			</otherwise>
          - 		</choose>
          - 	</inbound>
          - 	<backend>
          - 		<base />
          - 	</backend>
          - 	<outbound>
          - 		<base />
          - 	</outbound>
          - 	<on-error>
          - 		<base />
          - 	</on-error>
          + <policies>
          +     <inbound>
          +         <base />
          +         <choose>
          +             <when condition="@(context.Subscription.Id.Equals("azure-deployc49a"))">
          +                 <!-- ApiRateLimit 250 for IO Novita e aggiornamenti service -->
          +                 <rate-limit-by-key calls="250" renewal-period="5" counter-key="@(context.Subscription.Id + "-" + context.User.Id)" retry-after-header-name="x-rate-limit-retry-after" remaining-calls-header-name="x-rate-limit-remaining" />
          +             </when>
          +             <when condition="@(context.User.Groups.Select(g => g.Name).Contains("ApiNoRateLimit"))">
          +                 <!-- ApiNoRateLimit for internal/special users -->
          +             </when>
          +             <when condition="@(context.User.Groups.Select(g => g.Name).Contains("ApiRateLimit250"))">
          +                 <!-- ApiRateLimit 250 requests/5seconds for fast premium users -->
          +                 <rate-limit-by-key calls="250" renewal-period="5" counter-key="@(context.User.Id)" retry-after-header-name="x-rate-limit-retry-after" remaining-calls-header-name="x-rate-limit-remaining" />
          +             </when>
          +             <otherwise>
          +                 <!-- ApiRateLimit 150 requests/5seconds for fast standard users -->
          +                 <rate-limit-by-key calls="150" renewal-period="5" counter-key="@(context.User.Id)" retry-after-header-name="x-rate-limit-retry-after" remaining-calls-header-name="x-rate-limit-remaining" />
          +             </otherwise>
          +         </choose>
          +     </inbound>
          +     <backend>
          +         <base />
          +     </backend>
          +     <outbound>
          +         <base />
          +     </outbound>
          +     <on-error>
          +         <base />
          +     </on-error>
            </policies>
        EOT
        # (3 unchanged attributes hidden)
    }

  # module.apim_v2_product_services.azurerm_api_management_product_policy.this[0] will be updated in-place
  ~ resource "azurerm_api_management_product_policy" "this" {
        id                  = "/subscriptions/ec285037-c673-4f58-b594-d7c480da4e8b/resourceGroups/io-p-rg-internal/providers/Microsoft.ApiManagement/service/io-p-apim-v2-api/products/io-services-api"
      ~ xml_content         = <<-EOT
          - <policies>
          - 	<inbound>
          - 		<base />
          - 		<choose>
          - 			<when condition="@(context.User.Groups.Select(g => g.Name).Contains("ApiNoRateLimit"))">
          - 				<!-- ApiNoRateLimit for internal/special users -->
          - 			</when>
          - 			<when condition="@(context.User.Groups.Select(g => g.Name).Contains("ApiRateLimit250"))">
          - 				<!-- ApiRateLimit 250 requests/5seconds for fast premium users -->
          - 				<rate-limit-by-key calls="250" renewal-period="5" counter-key="@(context.User.Id)" retry-after-header-name="x-rate-limit-retry-after" remaining-calls-header-name="x-rate-limit-remaining" />
          - 			</when>
          - 			<otherwise>
          - 				<!-- ApiRateLimit 150 requests/5seconds for fast standard users -->
          - 				<rate-limit-by-key calls="150" renewal-period="5" counter-key="@(context.User.Id)" retry-after-header-name="x-rate-limit-retry-after" remaining-calls-header-name="x-rate-limit-remaining" />
          - 			</otherwise>
          - 		</choose>
          - 	</inbound>
          - 	<backend>
          - 		<base />
          - 	</backend>
          - 	<outbound>
          - 		<base />
          - 	</outbound>
          - 	<on-error>
          - 		<base />
          - 	</on-error>
          + <policies>
          +     <inbound>
          +         <base />
          +         <choose>
          +             <when condition="@(context.Subscription.Id.Equals("azure-deployc49a"))">
          +                 <!-- ApiRateLimit 250 for IO Novita e aggiornamenti service -->
          +                 <rate-limit-by-key calls="250" renewal-period="5" counter-key="@(context.Subscription.Id + "-" + context.User.Id)" retry-after-header-name="x-rate-limit-retry-after" remaining-calls-header-name="x-rate-limit-remaining" />
          +             </when>
          +             <when condition="@(context.User.Groups.Select(g => g.Name).Contains("ApiNoRateLimit"))">
          +                 <!-- ApiNoRateLimit for internal/special users -->
          +             </when>
          +             <when condition="@(context.User.Groups.Select(g => g.Name).Contains("ApiRateLimit250"))">
          +                 <!-- ApiRateLimit 250 requests/5seconds for fast premium users -->
          +                 <rate-limit-by-key calls="250" renewal-period="5" counter-key="@(context.User.Id)" retry-after-header-name="x-rate-limit-retry-after" remaining-calls-header-name="x-rate-limit-remaining" />
          +             </when>
          +             <otherwise>
          +                 <!-- ApiRateLimit 150 requests/5seconds for fast standard users -->
          +                 <rate-limit-by-key calls="150" renewal-period="5" counter-key="@(context.User.Id)" retry-after-header-name="x-rate-limit-retry-after" remaining-calls-header-name="x-rate-limit-remaining" />
          +             </otherwise>
          +         </choose>
          +     </inbound>
          +     <backend>
          +         <base />
          +     </backend>
          +     <outbound>
          +         <base />
          +     </outbound>
          +     <on-error>
          +         <base />
          +     </on-error>
            </policies>
        EOT
        # (3 unchanged attributes hidden)
    }

Plan: 0 to add, 2 to change, 0 to destroy.

─────────────────────────────────────────────────────────────────────────────

Note: You didn't use the -out option to save this plan, so Terraform can't
guarantee to take exactly these actions if you run "terraform apply" now.

@StefanoDoc StefanoDoc added this pull request to the merge queue Jan 29, 2025
Merged via the queue into main with commit f3c15b7 Jan 29, 2025
7 checks passed
@StefanoDoc StefanoDoc deleted the iopae-1711-RateLimit-for-IO-Novita-e-aggiornamenti branch January 29, 2025 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants