-
Notifications
You must be signed in to change notification settings - Fork 4
Add optional snapshot compression defaults and standby integration #149
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
Merged
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
55c44d2
Add configurable snapshot compression with async standby support
sjmiller609 a61b5da
Merge origin/main into codex/snapshot-compression-defaults
sjmiller609 47a3197
Add CH snapshot compression restore coverage
sjmiller609 0d4d7a0
Skip transient compression temp files during snapshot copy
sjmiller609 042d0c3
Clarify async snapshot compression restore behavior
sjmiller609 474bfed
Reduce snapshot compression test races
sjmiller609 0a9523f
Restore compression test parallelism
sjmiller609 47fd741
Unify snapshot restore cancellation behavior
sjmiller609 780fcd7
Apply suggestions from code review
sjmiller609 78a24d0
Add snapshot compression metrics
sjmiller609 bc2fd60
Fix snapshot compression review feedback
sjmiller609 e2d691e
Update Stainless model config
sjmiller609 3a12b9e
Serialize shared initrd rebuilds
sjmiller609 84113aa
Fix disabled snapshot defaults fallback
sjmiller609 e21be0c
Make snapshot compression fully opt-in
sjmiller609 e55214b
Fix snapshot compression restore races
sjmiller609 c78830a
Fix optional standby body handling
sjmiller609 d192ba1
Fix standby snapshot compression races
sjmiller609 19f4aec
Normalize standby snapshot compression copies
sjmiller609 2eef65d
Handle optional standby bodies outside generated code
sjmiller609 1c0eea1
Fix snapshot compression cleanup races
sjmiller609 da7f421
Clarify snapshot compression metrics state
sjmiller609 759eb3c
Return bad request for invalid standby input
sjmiller609 6b42cc5
Use native-first snapshot codecs with Go fallback
sjmiller609 cde775f
Normalize snapshot compression algorithms case-insensitively
sjmiller609 c17bec4
Tighten standby compression validation handling
sjmiller609 54df2a1
Merge origin/main into codex/snapshot-compression-defaults
sjmiller609 e78c657
Reduce compression levels in integration tests to avoid CI timeout
sjmiller609 2a9c9bc
Reduce compression integration test cycles to fit CI timeout
sjmiller609 393b80a
Address PR review feedback: add OpenAPI descriptions, fix dst.Close()…
sjmiller609 460c265
Address review feedback: add server-side compression validation, log …
sjmiller609 3b9264e
Fix snapshot compression review follow-ups
sjmiller609 fa7d99b
Merge origin/main into codex/snapshot-compression-defaults
sjmiller609 8638cce
Fix standby fork compression race
sjmiller609 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package api | ||
|
|
||
| import ( | ||
| "io" | ||
| "net/http" | ||
| "strings" | ||
| ) | ||
|
|
||
| // NormalizeOptionalStandbyBody rewrites empty standby POST bodies to "{}" | ||
| // so the generated strict handler can decode them without special casing. | ||
sjmiller609 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| func NormalizeOptionalStandbyBody(next http.Handler) http.Handler { | ||
| return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| if r.Method != http.MethodPost { | ||
| next.ServeHTTP(w, r) | ||
| return | ||
| } | ||
| if isStandbyRoutePath(r.URL.Path) && requestBodyIsEmpty(r) { | ||
| r.Body = io.NopCloser(strings.NewReader(`{}`)) | ||
| r.ContentLength = 2 | ||
| if r.Header.Get("Content-Type") == "" { | ||
| r.Header.Set("Content-Type", "application/json") | ||
| } | ||
| } | ||
|
|
||
| next.ServeHTTP(w, r) | ||
| }) | ||
| } | ||
|
|
||
| func isStandbyRoutePath(path string) bool { | ||
| if !strings.HasPrefix(path, "/instances/") || !strings.HasSuffix(path, "/standby") { | ||
| return false | ||
| } | ||
|
|
||
| instanceID := strings.TrimPrefix(path, "/instances/") | ||
| instanceID = strings.TrimSuffix(instanceID, "/standby") | ||
| return instanceID != "" && !strings.Contains(instanceID, "/") | ||
| } | ||
|
|
||
| func requestBodyIsEmpty(r *http.Request) bool { | ||
| if r == nil { | ||
| return true | ||
| } | ||
| if r.Body == nil || r.Body == http.NoBody { | ||
| return true | ||
| } | ||
| return r.ContentLength == 0 && len(r.TransferEncoding) == 0 | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| package api | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "io" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestNormalizeOptionalStandbyBody(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| t.Run("empty standby body becomes empty JSON object", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| var gotBody []byte | ||
| var gotContentType string | ||
| next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| var err error | ||
| gotBody, err = io.ReadAll(r.Body) | ||
| require.NoError(t, err) | ||
| gotContentType = r.Header.Get("Content-Type") | ||
| w.WriteHeader(http.StatusNoContent) | ||
| }) | ||
|
|
||
| req := httptest.NewRequest(http.MethodPost, "/instances/test/standby", nil) | ||
| rec := httptest.NewRecorder() | ||
|
|
||
| NormalizeOptionalStandbyBody(next).ServeHTTP(rec, req) | ||
|
|
||
| assert.Equal(t, http.StatusNoContent, rec.Code) | ||
| assert.Equal(t, []byte(`{}`), gotBody) | ||
| assert.Equal(t, "application/json", gotContentType) | ||
| }) | ||
|
|
||
| t.Run("existing standby body is preserved", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| var gotBody []byte | ||
| next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| var err error | ||
| gotBody, err = io.ReadAll(r.Body) | ||
| require.NoError(t, err) | ||
| w.WriteHeader(http.StatusNoContent) | ||
| }) | ||
|
|
||
| req := httptest.NewRequest(http.MethodPost, "/instances/test/standby", bytes.NewBufferString(`{"compression":{"enabled":true}}`)) | ||
| rec := httptest.NewRecorder() | ||
|
|
||
| NormalizeOptionalStandbyBody(next).ServeHTTP(rec, req) | ||
|
|
||
| assert.Equal(t, http.StatusNoContent, rec.Code) | ||
| assert.Equal(t, []byte(`{"compression":{"enabled":true}}`), gotBody) | ||
| }) | ||
|
|
||
| t.Run("non-standby route is untouched", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| var gotBody []byte | ||
| next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| var err error | ||
| gotBody, err = io.ReadAll(r.Body) | ||
| require.NoError(t, err) | ||
| w.WriteHeader(http.StatusNoContent) | ||
| }) | ||
|
|
||
| req := httptest.NewRequest(http.MethodPost, "/instances/test/start", nil) | ||
| rec := httptest.NewRecorder() | ||
|
|
||
| NormalizeOptionalStandbyBody(next).ServeHTTP(rec, req) | ||
|
|
||
| assert.Equal(t, http.StatusNoContent, rec.Code) | ||
| assert.Empty(t, gotBody) | ||
| }) | ||
|
|
||
| t.Run("non-post request skips standby normalization", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| var gotBody []byte | ||
| next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| var err error | ||
| gotBody, err = io.ReadAll(r.Body) | ||
| require.NoError(t, err) | ||
| w.WriteHeader(http.StatusNoContent) | ||
| }) | ||
|
|
||
| req := httptest.NewRequest(http.MethodGet, "/instances/test/standby", nil) | ||
| rec := httptest.NewRecorder() | ||
|
|
||
| NormalizeOptionalStandbyBody(next).ServeHTTP(rec, req) | ||
|
|
||
| assert.Equal(t, http.StatusNoContent, rec.Code) | ||
| assert.Empty(t, gotBody) | ||
| }) | ||
|
|
||
| t.Run("standby route matcher only accepts single path segment ids", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| assert.True(t, isStandbyRoutePath("/instances/test/standby")) | ||
| assert.False(t, isStandbyRoutePath("/instances/test/start")) | ||
| assert.False(t, isStandbyRoutePath("/instances/test/standby/extra")) | ||
| assert.False(t, isStandbyRoutePath("/instances/test/nested/standby")) | ||
| }) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.