Skip to content

feat: Handle LaunchDarkly rate limiting#5501

Merged
khvn26 merged 10 commits intomainfrom
feat/handle-launch-darkly-rate-limiting
May 30, 2025
Merged

feat: Handle LaunchDarkly rate limiting#5501
khvn26 merged 10 commits intomainfrom
feat/handle-launch-darkly-rate-limiting

Conversation

@khvn26
Copy link
Copy Markdown
Member

@khvn26 khvn26 commented May 28, 2025

Thanks for submitting a PR! Please check the boxes below:

  • I have added information to docs/ if required so people know about the feature!
  • I have filled in the "Changes" section below?
  • I have filled in the "How did you test this code" section below?
  • I have used a Conventional Commit title for this Pull Request

Changes

Closes #5361.

This PR adds rate limiting handling for LaunchDarkly client.
If rate limiting persists after 5 tries, the whole import request is backed off using functionality added in Flagsmith/flagsmith-common#81.

How did you test this code?

Added a bunch of new unit tests.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 28, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs ⬜️ Ignored (Inspect) Visit Preview May 30, 2025 11:51am
flagsmith-frontend-preview ⬜️ Ignored (Inspect) Visit Preview May 30, 2025 11:51am
flagsmith-frontend-staging ⬜️ Ignored (Inspect) Visit Preview May 30, 2025 11:51am

@github-actions github-actions Bot added the api Issue related to the REST API label May 28, 2025
@khvn26 khvn26 force-pushed the feat/handle-launch-darkly-rate-limiting branch from da8c190 to 82ceeb5 Compare May 28, 2025 17:40
@github-actions github-actions Bot added the feature New feature or request label May 28, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 28, 2025

Uffizzi Ephemeral Environment Deploying

☁️ https://app.uffizzi.com/github.com/Flagsmith/flagsmith/pull/5501

⚙️ Updating now by workflow run 15307046164.

What is Uffizzi? Learn more!

@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels May 28, 2025
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels May 29, 2025
@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.66%. Comparing base (62c6ef5) to head (f8189ce).
Report is 7 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5501   +/-   ##
=======================================
  Coverage   97.65%   97.66%           
=======================================
  Files        1237     1239    +2     
  Lines       43580    43677   +97     
=======================================
+ Hits        42558    42657   +99     
+ Misses       1022     1020    -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels May 29, 2025
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels May 29, 2025
@khvn26 khvn26 marked this pull request as ready for review May 29, 2025 17:34
@khvn26 khvn26 requested a review from a team as a code owner May 29, 2025 17:34
@khvn26 khvn26 requested review from Zaimwa9 and removed request for a team May 29, 2025 17:34
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 29, 2025

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-e2e:pr-5501 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api-test:pr-5501 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-frontend:pr-5501 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-api:pr-5501 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-5501 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-5501 Finished ✅ Results

@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels May 29, 2025
Comment thread api/pyproject.toml Outdated
djangorestframework-dataclasses = "^1.3.1"
pyotp = "^2.9.0"
flagsmith-common = "^1.13.0"
flagsmith-common = { git = "https://github.com/flagsmith/flagsmith-common", branch = "feat/task-backoff" }
Copy link
Copy Markdown
Member Author

@khvn26 khvn26 May 29, 2025

Choose a reason for hiding this comment

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

Redirect back to PyPI after Flagsmith/flagsmith-common#81 is merged and released.

def _handle_giveup(
details: Details,
) -> None:
exc: RequestException = details["exception"] # type: ignore[typeddict-item]
Copy link
Copy Markdown
Member Author

@khvn26 khvn26 May 29, 2025

Choose a reason for hiding this comment

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

This type ignore is an annoying one, especially considering the (otherwise excellent) backoff library is not maintained anymore.

NB: consider switching all backoff usage to stamina.

@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels May 29, 2025
Copy link
Copy Markdown
Member

@gagantrivedi gagantrivedi left a comment

Choose a reason for hiding this comment

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

We don't have to add TASK_BACKOFF_DEFAULT_DELAY_SECONDS used here?

exc: RequestException = details["exception"] # type: ignore[typeddict-item]

if retry_after := _get_retry_after(exc):
raise LaunchDarklyRateLimitError(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It could be nice to log the project/org maybe if it's simple to access them here ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added in 949f7bf.

@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels May 30, 2025
@khvn26
Copy link
Copy Markdown
Member Author

khvn26 commented May 30, 2025

We don't have to add TASK_BACKOFF_DEFAULT_DELAY_SECONDS used here?

@gagantrivedi Added in 445ebb8.

@khvn26 khvn26 requested a review from Zaimwa9 May 30, 2025 10:39
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels May 30, 2025
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels May 30, 2025
@khvn26 khvn26 merged commit 3d11eb1 into main May 30, 2025
30 checks passed
@khvn26 khvn26 deleted the feat/handle-launch-darkly-rate-limiting branch May 30, 2025 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle rate limiting in LaunchDarkly importer

3 participants