-
Notifications
You must be signed in to change notification settings - Fork 914
feat: use proto streams to increase maximum module files payload #18268
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
52 commits
Select commit
Hold shift + click to select a range
e6b4635
feat: provisioners to stream over modules >4mb limit
Emyrk d115c5a
make gen
Emyrk dea4895
add chunk piece in response
Emyrk b5fceda
rename hash field
Emyrk 99d4d54
remove upload type from the chunk
Emyrk e8d8b98
feat: handle uploading data files in runner
Emyrk fbfa08b
chore: implement first part of file streaming
Emyrk 73151d1
test adding a stream on the server
Emyrk b61faaf
add completejob stream
Emyrk f547103
change upload behavior
Emyrk bcbf6ca
make gen
Emyrk 1bd6b69
upload files independently
Emyrk 931ac95
make gen
Emyrk fb8c284
select file by hash
Emyrk 6b645d6
fix permissions
Emyrk 9dc81db
add log for uploaded files
Emyrk 124d366
remove dead file
Emyrk 857e88c
ability to omit module file downloads
Emyrk 5cf9beb
linting
Emyrk 58b2371
linting
Emyrk e880894
make gen
Emyrk 31d8e62
fixups
Emyrk bb2000a
linting
Emyrk 6633548
linting
Emyrk b070e5a
linting
Emyrk 1a70429
add unit tests and fuzz test
Emyrk 0f056e8
unit testing
Emyrk 1a8c658
comments
Emyrk 4ec22d8
fixup test
Emyrk 1c9df09
fixup dbmem to return unique files error
Emyrk c30607e
linting
Emyrk 0484777
fmt
Emyrk a3cf121
linting
Emyrk 3f7707a
linting
Emyrk 0ec5d1b
Merge remote-tracking branch 'origin/main' into stevenmasley/4mb
Emyrk e50c8c3
update proto to reuse
Emyrk 8cf7f5c
make gen
Emyrk 28f83a2
fixup
Emyrk bb3d4ef
test fixup types
Emyrk 74073cf
Merge remote-tracking branch 'origin/main' into stevenmasley/4mb
Emyrk c9575c5
add full_hash to complete job
Emyrk 6b7e56e
Revert "add full_hash to complete job"
Emyrk 24d6227
Reapply "add full_hash to complete job"
Emyrk 4f343e6
chore: add hash check of uploaded file after planComplete
Emyrk 539755b
bump provider version
Emyrk e4f49ab
linting
Emyrk 363498a
nil bytes fail on the typescript
Emyrk 02d8563
handle empty slices
Emyrk f1ce0ac
move module max to a constant
Emyrk f6bdf96
add 0 byte file test
Emyrk 4f387ec
Merge branch 'main' into stevenmasley/4mb
Emyrk f3525c3
Merge branch 'main' into stevenmasley/4mb
Emyrk 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
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,191 @@ | ||
package provisionerdserver_test | ||
|
||
import ( | ||
"context" | ||
crand "crypto/rand" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/google/uuid" | ||
"github.com/stretchr/testify/require" | ||
"golang.org/x/xerrors" | ||
"storj.io/drpc" | ||
|
||
"github.com/coder/coder/v2/coderd/database" | ||
"github.com/coder/coder/v2/coderd/externalauth" | ||
"github.com/coder/coder/v2/codersdk/drpcsdk" | ||
proto "github.com/coder/coder/v2/provisionerd/proto" | ||
sdkproto "github.com/coder/coder/v2/provisionersdk/proto" | ||
"github.com/coder/coder/v2/testutil" | ||
) | ||
|
||
// TestUploadFileLargeModuleFiles tests the UploadFile RPC with large module files | ||
func TestUploadFileLargeModuleFiles(t *testing.T) { | ||
t.Parallel() | ||
|
||
ctx := testutil.Context(t, testutil.WaitMedium) | ||
|
||
// Create server | ||
server, db, _, _ := setup(t, false, &overrides{ | ||
externalAuthConfigs: []*externalauth.Config{{}}, | ||
}) | ||
|
||
testSizes := []int{ | ||
0, // Empty file | ||
512, // A small file | ||
drpcsdk.MaxMessageSize + 1024, // Just over the limit | ||
drpcsdk.MaxMessageSize * 2, // 2x the limit | ||
sdkproto.ChunkSize*3 + 512, // Multiple chunks with partial last | ||
} | ||
|
||
for _, size := range testSizes { | ||
t.Run(fmt.Sprintf("size_%d_bytes", size), func(t *testing.T) { | ||
t.Parallel() | ||
|
||
// Generate test module files data | ||
moduleData := make([]byte, size) | ||
_, err := crand.Read(moduleData) | ||
require.NoError(t, err) | ||
|
||
// Convert to upload format | ||
upload, chunks := sdkproto.BytesToDataUpload(sdkproto.DataUploadType_UPLOAD_TYPE_MODULE_FILES, moduleData) | ||
|
||
stream := newMockUploadStream(upload, chunks...) | ||
|
||
// Execute upload | ||
err = server.UploadFile(stream) | ||
require.NoError(t, err) | ||
|
||
// Upload should be done | ||
require.True(t, stream.isDone(), "stream should be done after upload") | ||
|
||
// Verify file was stored in database | ||
hashString := fmt.Sprintf("%x", upload.DataHash) | ||
file, err := db.GetFileByHashAndCreator(ctx, database.GetFileByHashAndCreatorParams{ | ||
Hash: hashString, | ||
CreatedBy: uuid.Nil, // Provisionerd creates with Nil UUID | ||
}) | ||
require.NoError(t, err) | ||
require.Equal(t, hashString, file.Hash) | ||
require.Equal(t, moduleData, file.Data) | ||
require.Equal(t, "application/x-tar", file.Mimetype) | ||
|
||
// Try to upload it again, and it should still be successful | ||
stream = newMockUploadStream(upload, chunks...) | ||
err = server.UploadFile(stream) | ||
require.NoError(t, err, "re-upload should succeed without error") | ||
require.True(t, stream.isDone(), "stream should be done after re-upload") | ||
}) | ||
} | ||
} | ||
|
||
// TestUploadFileErrorScenarios tests various error conditions in file upload | ||
func TestUploadFileErrorScenarios(t *testing.T) { | ||
t.Parallel() | ||
|
||
//nolint:dogsled | ||
server, _, _, _ := setup(t, false, &overrides{ | ||
externalAuthConfigs: []*externalauth.Config{{}}, | ||
}) | ||
|
||
// Generate test data | ||
moduleData := make([]byte, sdkproto.ChunkSize*2) | ||
_, err := crand.Read(moduleData) | ||
require.NoError(t, err) | ||
|
||
upload, chunks := sdkproto.BytesToDataUpload(sdkproto.DataUploadType_UPLOAD_TYPE_MODULE_FILES, moduleData) | ||
|
||
t.Run("chunk_before_upload", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
stream := newMockUploadStream(nil, chunks[0]) | ||
|
||
err := server.UploadFile(stream) | ||
require.ErrorContains(t, err, "unexpected chunk piece while waiting for file upload") | ||
require.True(t, stream.isDone(), "stream should be done after error") | ||
}) | ||
|
||
t.Run("duplicate_upload", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
stream := &mockUploadStream{ | ||
done: make(chan struct{}), | ||
messages: make(chan *proto.UploadFileRequest, 2), | ||
} | ||
|
||
up := &proto.UploadFileRequest{Type: &proto.UploadFileRequest_DataUpload{DataUpload: upload}} | ||
|
||
// Send it twice | ||
stream.messages <- up | ||
stream.messages <- up | ||
|
||
err := server.UploadFile(stream) | ||
require.ErrorContains(t, err, "unexpected file upload while waiting for file completion") | ||
require.True(t, stream.isDone(), "stream should be done after error") | ||
}) | ||
|
||
t.Run("unsupported_upload_type", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
//nolint:govet // Ignore lock copy | ||
cpy := *upload | ||
cpy.UploadType = sdkproto.DataUploadType_UPLOAD_TYPE_UNKNOWN // Set to an unsupported type | ||
stream := newMockUploadStream(&cpy, chunks...) | ||
|
||
err := server.UploadFile(stream) | ||
require.ErrorContains(t, err, "unsupported file upload type") | ||
require.True(t, stream.isDone(), "stream should be done after error") | ||
}) | ||
} | ||
|
||
type mockUploadStream struct { | ||
done chan struct{} | ||
messages chan *proto.UploadFileRequest | ||
} | ||
|
||
func (m mockUploadStream) SendAndClose(empty *proto.Empty) error { | ||
close(m.done) | ||
return nil | ||
} | ||
|
||
func (m mockUploadStream) Recv() (*proto.UploadFileRequest, error) { | ||
msg, ok := <-m.messages | ||
if !ok { | ||
return nil, xerrors.New("no more messages to receive") | ||
} | ||
return msg, nil | ||
} | ||
func (*mockUploadStream) Context() context.Context { panic(errUnimplemented) } | ||
func (*mockUploadStream) MsgSend(msg drpc.Message, enc drpc.Encoding) error { | ||
panic(errUnimplemented) | ||
} | ||
|
||
func (*mockUploadStream) MsgRecv(msg drpc.Message, enc drpc.Encoding) error { | ||
panic(errUnimplemented) | ||
} | ||
func (*mockUploadStream) CloseSend() error { panic(errUnimplemented) } | ||
func (*mockUploadStream) Close() error { panic(errUnimplemented) } | ||
func (m *mockUploadStream) isDone() bool { | ||
select { | ||
case <-m.done: | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
|
||
func newMockUploadStream(up *sdkproto.DataUpload, chunks ...*sdkproto.ChunkPiece) *mockUploadStream { | ||
stream := &mockUploadStream{ | ||
done: make(chan struct{}), | ||
messages: make(chan *proto.UploadFileRequest, 1+len(chunks)), | ||
} | ||
if up != nil { | ||
stream.messages <- &proto.UploadFileRequest{Type: &proto.UploadFileRequest_DataUpload{DataUpload: up}} | ||
} | ||
|
||
for _, chunk := range chunks { | ||
stream.messages <- &proto.UploadFileRequest{Type: &proto.UploadFileRequest_ChunkPiece{ChunkPiece: chunk}} | ||
} | ||
close(stream.messages) | ||
return stream | ||
} |
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.