fix(planetscale): set the deploy request throttler on the endpoint the API serves - #962
Draft
aparajon wants to merge 1 commit into
Draft
fix(planetscale): set the deploy request throttler on the endpoint the API serves#962aparajon wants to merge 1 commit into
aparajon wants to merge 1 commit into
Conversation
…e API serves
Volume on PlanetScale PUT /deploy-requests/{n}/throttle with a fractional
throttle_ratio. The API serves PATCH /deploy-requests/{n}/throttler with a whole
percentage, so every volume command 404'd: the operator saw an accepted request
and the deploy request kept running at its original speed.
The wire format converts inside the client, so volume mapping and LocalScale keep
carrying the ratio as a fraction. LocalScale registers the corrected route and
body, so the emulator exercises the same contract as the API instead of masking
a mismatch.
A failing call now carries a bounded, sanitized excerpt of the response body:
the status line alone cannot distinguish a moved endpoint from a deleted deploy
request. The excerpt is log-safe only and must not be rendered into PR markdown.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes PlanetScale deploy request throttling by aligning SchemaBot’s client and LocalScale emulator with the API contract the server actually serves (method/path + request body), and adds targeted tests to lock the contract in.
Changes:
- Switch PlanetScale throttling from
PUT .../throttlewith fractionalthrottle_ratiotoPATCH .../throttlerwith integerratiopercent, converting units inside the client. - Update LocalScale’s route registration and handler to accept the new
ratiopercent contract while preserving internal fractional storage/behavior. - Add unit tests covering wire contract, ratio conversion, and error excerpt sanitation.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
pkg/psclient/client.go |
Updates the throttling HTTP call to the served endpoint/body, adds ratio conversion + bounded response excerpt sanitization. |
pkg/psclient/client_test.go |
Adds tests for the throttler endpoint contract, percent conversion, and error excerpt behavior. |
pkg/localscale/server.go |
Registers the emulator route as PATCH .../throttler. |
pkg/localscale/handlers_actions.go |
Updates the emulator handler to decode integer percent ratio and convert to internal fractional throttle ratio. |
pkg/engine/planetscale/volume.go |
Clarifies the meaning of PreviousVolume in the PlanetScale volume result. |
Suppressed comments (1)
pkg/psclient/client.go:257
sanitizeResponseExcerptclaims the excerpt “cannot break log or table formatting downstream”, but it doesn’t neutralize Markdown table delimiters like|. Since this excerpt can be rendered into PR markdown via existing error plumbing, replacing|with a space (or another safe rune) would better match the safety intent.
// sanitizeResponseExcerpt reads a bounded prefix of an error response body and
// makes it safe to embed in an error string: newlines collapse to spaces and
// non-printable runes are dropped, so the excerpt cannot break log or table
// formatting downstream.
func sanitizeResponseExcerpt(body io.Reader) string {
raw, err := io.ReadAll(io.LimitReader(body, maxResponseExcerptLen*4))
if err != nil {
return "<response body unreadable>"
}
cleaned := strings.Map(func(r rune) rune {
if r == '\n' || r == '\r' || r == '\t' {
return ' '
}
if !unicode.IsPrint(r) {
return -1
}
return r
}, string(raw))
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+228
to
+234
| // throttleRatioPercent converts SchemaBot's fractional throttle ratio to the | ||
| // whole percentage the PlanetScale API expects. Out-of-range values are passed | ||
| // through so the API's own validation reports them rather than being silently | ||
| // clamped into a ratio the caller did not ask for. | ||
| func throttleRatioPercent(ratio float64) int { | ||
| return int(math.Round(ratio * 100)) | ||
| } |
Comment on lines
217
to
+223
| if resp.StatusCode != http.StatusOK { | ||
| return fmt.Errorf("throttle request failed: %s", resp.Status) | ||
| // The status alone does not say why — a 404 on a moved path and a 404 on | ||
| // a deleted deploy request read identically. Carry a bounded, sanitized | ||
| // excerpt of the body so the cause survives to the logs. Callers must not | ||
| // render this into PR markdown. | ||
| return fmt.Errorf("throttle deploy request %d (%s/%s) failed: %s: %s", | ||
| req.Number, req.Organization, req.Database, resp.Status, sanitizeResponseExcerpt(resp.Body)) |
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.
Why this matters
Every
schemabot volumecommand against a PlanetScale deploy request 404'd. SchemaBot sentPUT /deploy-requests/{n}/throttlewith a fractional ratio; the API servesPATCH /deploy-requests/{n}/throttlerwith a whole percentage. The operator saw an accepted request and the deploy request kept running at its original speed — the worst shape for a throttle control, since it is reached for precisely when something needs to slow down.What it does
🤖 Generated with Claude Code