Skip to content

Adds Okta rate limit headers#286

Merged
ggreer merged 1 commit intomainfrom
sb/okta-ratelimit
Jan 15, 2025
Merged

Adds Okta rate limit headers#286
ggreer merged 1 commit intomainfrom
sb/okta-ratelimit

Conversation

@santhosh-c1
Copy link
Contributor

@santhosh-c1 santhosh-c1 commented Jan 15, 2025

Summary by CodeRabbit

  • New Features
    • Enhanced rate limit header support with additional headers for improved API compatibility, specifically for Okta integration.

- This is a non-standard header that Okta uses
@santhosh-c1 santhosh-c1 requested a review from jirwin as a code owner January 15, 2025 05:19
@coderabbitai
Copy link

coderabbitai bot commented Jan 15, 2025

Walkthrough

The changes involve expanding the rate limit header handling capabilities in the HTTP rate limiting package. Specifically, three new non-standard headers have been added to support Okta's API rate limit reporting: "X-Rate-Limit-Limit", "X-Rate-Limit-Remaining", and "X-Rate-Limit-Reset". These additions enhance the package's flexibility in extracting rate limit information from various API responses without modifying the core logic of the rate limit extraction mechanism.

Changes

File Change Summary
pkg/ratelimit/http.go Added Okta-specific rate limit headers to limitHeaders, remainingHeaders, and resetAtHeaders variables

Poem

🐰 Hop, hop, headers dance with glee,
Rate limits now more free!
Okta's rhythm joins the song,
Headers stretching, headers strong!
A rabbit's code, forever bright! 🚀

Finishing Touches

  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
pkg/ratelimit/http.go (1)

16-30: Add test coverage for Okta rate limit headers.

While the implementation looks good, consider adding test cases to verify the behavior with Okta's rate limit headers. This would help ensure compatibility and prevent regressions.

Would you like me to help generate test cases for the Okta rate limit headers?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a6ca52a and bd84517.

📒 Files selected for processing (1)
  • pkg/ratelimit/http.go (1 hunks)
🔇 Additional comments (3)
pkg/ratelimit/http.go (3)

16-16: LGTM! Addition of Okta rate limit header.

The new header follows the existing pattern and is properly documented.


23-23: LGTM! Addition of Okta remaining requests header.

The header follows the established pattern and maintains consistency with other non-standard implementations.


30-30: Verify Okta reset time format compatibility.

While the header addition is correct, we should verify that Okta's reset time format is compatible with our parseTime function.

Let's check Okta's documentation for the reset time format:

✅ Verification successful

Time parsing implementation is compatible with Okta's format

The parseTime function is designed to handle multiple time formats including Unix timestamps, RFC850, and RFC3339, with special handling for both relative and absolute timestamps. This implementation is sufficiently robust to handle Okta's X-Rate-Limit-Reset header format.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for documentation or tests related to Okta's X-Rate-Limit-Reset format
# Expected results: Documentation or test cases showing Okta's reset time format

# Search for any existing tests or documentation mentioning Okta rate limits
rg -i "okta.*rate.*limit|rate.*limit.*okta" -g "*.{md,txt,go}"

# Search for test cases specifically handling Okta's reset time format
ast-grep --pattern 'func Test$_($_) {
  $$$
  "X-Rate-Limit-Reset"
  $$$
}'

Length of output: 410


Script:

#!/bin/bash
# Search for parseTime implementation and related test cases
ast-grep --pattern 'func parseTime($$$) {
  $$$
}'

# Search for test cases related to time parsing
ast-grep --pattern 'func Test$_(t *testing.T) {
  $$$
  parseTime($$$)
  $$$
}'

# Search for any time parsing related code
rg "parseTime|time\.Parse" -A 5 -B 5 pkg/ratelimit/

Length of output: 134


Script:

#!/bin/bash
# Get the complete implementation of http.go
cat pkg/ratelimit/http.go

# Search for rate limit related types and interfaces
rg "type.*Rate" -A 5 pkg/ratelimit/

Length of output: 4161

@@ -13,18 +13,21 @@ var limitHeaders = []string{
"X-Ratelimit-Limit",
"Ratelimit-Limit",
"X-RateLimit-Requests-Limit", // Linear uses a non-standard header
Copy link
Contributor

Choose a reason for hiding this comment

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

its weird to me we can't handle this via option parameters to uhttp or somehting. centralizing this is... well, gonna be hard, and future error prone.

Copy link
Contributor

Choose a reason for hiding this comment

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

We'll get 'em all eventually. Just one more http header and we'll have all of them covered. For sure this time. 😅

I agree that this setup is not ideal, but so far we only have two APIs that are wrong (Linear and Okta). If we have a 3rd one, then I think it's time to tweak this.

@ggreer ggreer merged commit fd1a57a into main Jan 15, 2025
4 checks passed
@ggreer ggreer deleted the sb/okta-ratelimit branch January 15, 2025 16:52
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.

4 participants