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

[Integration][Terraform-Cloud] Add Rate Limiting Improvements #1110

Merged

Conversation

phalbert
Copy link
Contributor

@phalbert phalbert commented Oct 30, 2024

What - This PR implements comprehensive rate limiting and concurrency control for the Terraform Cloud integration to prevent rate limit exhaustion and ensure reliable data synchronization.

Why - The integration was experiencing cascading failures during resyncs due to excessive API requests, leading to:

  • Multiple 429 Too Many Requests errors
  • Failed deletion phases hence stale data in Port
  • Incomplete state synchronisation

How - Implemented a multi-layered approach to rate limiting:

  • Added aiolimiter to control overall request rate with 25 requests/second (buffer below Terraform's 30/sec limit)
  • Added request tracking via response headers (x-ratelimit-*)
  • Basic retry logic for rate-limited requests
  • client.py: Rate limiting implementation

All tests should be run against the port production environment(using a testing org).

Core testing checklist

  • Integration able to create all default resources from scratch
  • Resync finishes successfully
  • Resync able to create entities
  • Resync able to update entities
  • Resync able to detect and delete entities
  • Scheduled resync able to abort existing resync and start a new one
  • Tested with at least 2 integrations from scratch
  • Tested with Kafka and Polling event listeners
  • Tested deletion of entities that don't pass the selector

Integration testing checklist

  • Integration able to create all default resources from scratch
  • Resync able to create entities
  • Resync able to update entities
  • Resync able to detect and delete entities
  • Resync finishes successfully
  • If new resource kind is added or updated in the integration, add example raw data, mapping and expected result to the examples folder in the integration directory.
  • If resource kind is updated, run the integration with the example data and check if the expected result is achieved
  • If new resource kind is added or updated, validate that live-events for that resource are working as expected
  • Docs PR link here

Preflight checklist

  • Handled rate limiting
  • Handled pagination
  • Implemented the code in async
  • Support Multi account

Screenshots

[Include screenshots of logs showing reduced 429 warnings, if available]

API Documentation

@phalbert phalbert self-assigned this Oct 30, 2024
@phalbert phalbert requested a review from a team as a code owner October 30, 2024 23:51
@phalbert phalbert mentioned this pull request Oct 30, 2024
23 tasks
@phalbert phalbert requested a review from mk-armah October 31, 2024 16:08
Copy link
Contributor

@Tankilevitch Tankilevitch left a comment

Choose a reason for hiding this comment

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

missing changelog

integrations/terraform-cloud/main.py Outdated Show resolved Hide resolved
@phalbert phalbert requested a review from Tankilevitch November 4, 2024 18:19
@github-actions github-actions bot added size/L and removed size/M labels Nov 22, 2024
integrations/terraform-cloud/client.py Outdated Show resolved Hide resolved
integrations/terraform-cloud/client.py Outdated Show resolved Hide resolved
@github-actions github-actions bot added size/M and removed size/L labels Nov 25, 2024
@@ -17,12 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## 0.1.81 (2024-11-25)


### Improvements
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this is removed?

@Tankilevitch Tankilevitch merged commit eded7ec into main Nov 26, 2024
18 checks passed
@Tankilevitch Tankilevitch deleted the PORT-10857-adhere-to-terraform-cloud-api-rate-limits branch November 26, 2024 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants