Expose Management API rate limit info via a client callback - #798
Draft
ProdigyTom wants to merge 2 commits into
Draft
Expose Management API rate limit info via a client callback#798ProdigyTom wants to merge 2 commits into
ProdigyTom wants to merge 2 commits into
Conversation
Wraps the RawClient#send return value in a RawResponse that delegates #code, #body, and header access to the underlying response (so the generated callers are unaffected) and adds a #rate_limit built from the x-ratelimit-* headers. - Add Auth0::Internal::Http::RateLimit (limit/remaining/reset; blank and non-numeric header values become nil rather than 0) - Add Auth0::Internal::Http::RawResponse wrapper - RawClient#send returns the wrapper (retry logic still operates on the raw response inside the loop; only the final response is wrapped) - Unit tests for RateLimit, RawResponse, and RawClient#send All changes live in fernignored files (lib/auth0/internal/**), so they survive regeneration. Refs auth0#606.
Adds an opt-in callback, invoked with the rate limit parsed from every Management API response, so callers can monitor how close they are to the limit. Chosen over changing endpoint return values because the response is dropped in generated endpoint code that a third-party change can't durably alter; the callback lives entirely in fernignored files. - Add Auth0::Internal::Http::RateLimit (limit/remaining/reset; blank and non-numeric header values become nil rather than 0) - RawClient gains a rate_limit_handler, invoked in #send after retries on every response; handler errors are swallowed so they can't break a request - Wire it through the custom client: Auth0::Client.new(management_rate_limit_handler:) attaches the handler to the management raw client - Unit tests for RateLimit, RawClient#send handler behavior, and client wiring Refs auth0#606.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
Exposes Auth0's rate-limit information (
x-ratelimit-limit/-remaining/-reset) from every Management API response, so callers can monitor how close they are to the limit (the ask in #606). It's delivered via an opt-in callback rather than a changed return value — see the note below on why.Auth0::Internal::Http::RateLimit— value object (limit,remainingas Integers;resetas a UTCTime). Blank/non-numeric header values becomenil(never a misleading0).RawClientgains an optionalrate_limit_handler, invoked in#sendafter retries on every response with the parsedRateLimit. Handler errors are swallowed so a monitoring callback can never break a request.#send's return value is unchanged, so the generated callers are unaffected.Auth0::Client.new(..., management_rate_limit_handler: ->(rl) { ... })attaches the handler to the management raw client.lib/auth0/internal/**,lib/auth0/mixins/**,lib/auth0/auth_client.rb), so they survive regeneration.RateLimit,RawClient#sendhandler behavior, and the client wiring.Why a callback instead of returning the rate limit (e.g.
with_raw_response)? The generated endpoint methods (Auth0::Users::Client#get, etc.) parse the body and discard the response, and they're regenerated, so a third-party change to what they return wouldn't survive. A callback invoked at the maintainedRawClientlayer is the part we can change durably while still delivering the data on every request. If you'd prefer to also expose it as a return value via a generatedwith_raw_response-style accessor, thisRateLimitobject slots right in.References
Testing
Unit tests under
test/unit/cover header parsing (0vs blank/non-numeric), the handler firing with the parsed rate limit while the response is returned unchanged, handler errors not breaking the request, and the client wiring. Fullrake testpasses locally with no failures.Checklist