Skip to content
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

[DATA-1649]/[DATA-1647] Add GetPointCloudMap collector and use streaming sync rpc for large files. #2703

Merged
merged 16 commits into from
Jul 28, 2023

Conversation

AaronCasas
Copy link
Contributor

@AaronCasas AaronCasas commented Jul 27, 2023

Use new streaming sync rpc for uploading binary capture files > 1MB.

Testing

Confirmed that capture of point cloud maps works locally.
Confirmed that images are successfully uploaded to the backend using the streaming rpc.

@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Jul 27, 2023
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jul 27, 2023
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jul 27, 2023
@AaronCasas AaronCasas marked this pull request as ready for review July 27, 2023 21:32
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jul 27, 2023
@AaronCasas AaronCasas requested a review from agreenb July 28, 2023 14:26
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jul 28, 2023
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jul 28, 2023
Copy link
Contributor

@agreenb agreenb left a comment

Choose a reason for hiding this comment

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

This looks fantastic, super excited for this addition! Just a few comments/nits and then looks ready to go. 🔥

Thank you for adding the testing into the PR description — for the image testing to ensure that the streamed files were well-formed, did you reduce the chunk size and verify that it was using the streaming option?

@@ -332,31 +332,26 @@ func TestArbitraryFileUpload(t *testing.T) {
name string
manualSync bool
scheduleSyncDisabled bool
serviceFail bool
Copy link
Contributor

Choose a reason for hiding this comment

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

I see you removed this because it wasn't actually being used, but do we want a test that checks this in arbitrary file upload? "scheduled sync of arbitrary files should work" and "if an error response is received from the backend, local files should not be deleted" are actually the same test where manualSync and scheduleSyncDisabled are both false (and were previously as well, so was an existing test bug)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, added

@@ -694,6 +813,15 @@ func (c mockDataSyncServiceClient) FileUpload(ctx context.Context, opts ...grpc.
return ret, nil
}

func (c mockDataSyncServiceClient) StreamingDataCaptureUpload(ctx context.Context, opts ...grpc.CallOption) (v1.DataSyncService_StreamingDataCaptureUploadClient, error) {
if c.fail.Load() {
Copy link
Contributor

Choose a reason for hiding this comment

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

[question] Why are you checking for a context cancelation in the fail.Load() in DataCaptureUpload but not these streaming requests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, we should be. Added here and in FileUpload

}
test.That(t, actData, test.ShouldResemble, fileContents)
test.That(t, actData, test.ShouldResemble, capturedData[0].GetBinary())
Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome, elegant check.


// Validate file no longer exists.
waitUntilNoFiles(additionalPathsDir)
test.That(t, len(getAllFileInfos(additionalPathsDir)), test.ShouldEqual, 0)
waitUntilNoFiles(tmpDir)
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to you adding this helper function before, makes tests extremely readable.

// If it's a large binary file, we need to upload it in chunks.
if md.GetType() == v1.DataType_DATA_TYPE_BINARY_SENSOR && f.Size() > MaxUnaryFileSize {
if len(sensorData) > 1 {
return errors.New("binary sensor data file with more than one sensor reading is not supported")
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit/question] I agree that you should throw an error here since we're passing along bytes rather than sensorData, so we need to ensure that there's only a single datapoint. For DataCaptureUpload, we fail if there's multiple SensorData for binary only once we hit the app logic.

Considering whether we should error from the RDK side there as well - but I also like that the below DataCaptureUploadRequest is generic to tabular/binary and simply passes the sensorData along.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think for now, I'd rather not change that logic as part of this PR. I don't have a strong opinion on doing it rdk side too

if err != nil {
return err

// If it's a large binary file, we need to upload it in chunks.
Copy link
Contributor

Choose a reason for hiding this comment

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

Really great work making the streaming option readable and fit into the existing flow well by just checking the binary file size.

return nil, data.FailedToReadErr(params.ComponentName, getPointCloudMap.String(), err)
}

pcd, err := HelperConcatenateChunksToFull(f)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, glad SLAM already had a helper method to convert into bytes!

@AaronCasas
Copy link
Contributor Author

did you reduce the chunk size and verify that it was using the streaming option?
Yup exactly. Made the minimum size to use streaming 1 byte, then let it upload a bunch of images

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jul 28, 2023
@@ -240,7 +239,7 @@ func getFileTimestampName() string {
// TODO DATA-246: Implement this in some more robust, programmatic way.
func getDataType(methodName string) v1.DataType {
switch methodName {
case nextPointCloud, readImage:
case nextPointCloud, readImage, getPointCloudMap:
Copy link
Contributor

Choose a reason for hiding this comment

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

Whew good catch!

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jul 28, 2023
@@ -11,7 +11,7 @@ import (
)

// UploadChunkSize defines the size of the data included in each message of a FileUpload stream.
var UploadChunkSize = 64 * 1024
var UploadChunkSize = 256 * 1024
Copy link
Contributor

Choose a reason for hiding this comment

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

Double checking on this bump?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jul 28, 2023
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jul 28, 2023
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jul 28, 2023
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jul 28, 2023
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jul 28, 2023
@AaronCasas AaronCasas requested a review from agreenb July 28, 2023 18:19
Copy link
Contributor

@agreenb agreenb left a comment

Choose a reason for hiding this comment

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

Just two more minor questions.

return errors.Wrapf(err, "received error response while syncing %s", f.Name())
}

return nil
}

func sendFileUploadRequests(ctx context.Context, stream v1.DataSyncService_FileUploadClient, f *os.File) error {
//nolint:errcheck
defer stream.CloseSend()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this removed? Is this in order to synchronously have uploadArbitraryFile and uploadDataCaptureFile in charge of closing the channel and getting the client response (via CloseAndRecv), rather than splitting that between the helper and main loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CloseAndRecv is the recommended/intended method for ending a client side stream (docs. I believe this is because the stream ending and a response being received are supposed to always happen in this fixed order (since there is only one response message). In bidi streams where these can be interleaveed, CloseSend is used

test.That(t, len(getAllFileInfos(additionalPathsDir)), test.ShouldEqual, 0)
test.That(t, dmsvc.Close(context.Background()), test.ShouldBeNil)
} else {
// Validate file still exists.
Copy link
Contributor

Choose a reason for hiding this comment

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

For here and in the other tests, in this failure case, we should check that len(fileUploads) (or streaming uploads) == 0.

The file could technically still exist since we didn't call waitUntilNoFiles.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, and moved waitUntilNoFiles up so it gets called in call cases

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jul 28, 2023
@AaronCasas AaronCasas requested a review from agreenb July 28, 2023 19:04
Copy link
Contributor

@agreenb agreenb left a comment

Choose a reason for hiding this comment

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

Fantastic work, really excited for SLAM to start using this! 🚀🚀🚀

@AaronCasas AaronCasas changed the title [DATA-1649] Streaming sync [DATA-1649]/[DATA-1647] Add GetPointCloudMap collector and use streaming sync rpc for large files. Jul 28, 2023
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jul 28, 2023
@github-actions
Copy link
Contributor

Code Coverage

Code Coverage
Package Line Rate Delta Health
go.viam.com/rdk/components/arm 58% 0.00%
go.viam.com/rdk/components/arm/fake 27% 0.00%
go.viam.com/rdk/components/arm/universalrobots 41% 0.00%
go.viam.com/rdk/components/arm/wrapper 19% 0.00%
go.viam.com/rdk/components/arm/xarm 22% 0.00%
go.viam.com/rdk/components/arm/yahboom 6% 0.00%
go.viam.com/rdk/components/audioinput 43% 0.00%
go.viam.com/rdk/components/base 60% 0.00%
go.viam.com/rdk/components/base/agilex 61% 0.00%
go.viam.com/rdk/components/base/kinematicbase 42% 0.00%
go.viam.com/rdk/components/base/wheeled 81% 0.00%
go.viam.com/rdk/components/board 60% 0.00%
go.viam.com/rdk/components/board/customlinux 35% 0.00%
go.viam.com/rdk/components/board/fake 38% 0.00%
go.viam.com/rdk/components/board/genericlinux 8% 0.00%
go.viam.com/rdk/components/board/numato 19% 0.00%
go.viam.com/rdk/components/board/pi/impl 11% 0.00%
go.viam.com/rdk/components/camera 58% 0.00%
go.viam.com/rdk/components/camera/align 58% 0.00%
go.viam.com/rdk/components/camera/fake 74% 0.00%
go.viam.com/rdk/components/camera/ffmpeg 81% -1.49%
go.viam.com/rdk/components/camera/replaypcd 89% 0.00%
go.viam.com/rdk/components/camera/rtsp 52% 0.00%
go.viam.com/rdk/components/camera/transformpipeline 77% 0.00%
go.viam.com/rdk/components/camera/ultrasonic 61% 0.00%
go.viam.com/rdk/components/camera/videosource 38% 0.00%
go.viam.com/rdk/components/encoder 57% 0.00%
go.viam.com/rdk/components/encoder/ams 63% 0.00%
go.viam.com/rdk/components/encoder/fake 83% 0.00%
go.viam.com/rdk/components/encoder/incremental 80% 0.00%
go.viam.com/rdk/components/encoder/single 86% 0.00%
go.viam.com/rdk/components/gantry 60% 0.00%
go.viam.com/rdk/components/gantry/multiaxis 82% 0.00%
go.viam.com/rdk/components/gantry/singleaxis 81% 0.00%
go.viam.com/rdk/components/generic 79% 0.00%
go.viam.com/rdk/components/gripper 56% 0.00%
go.viam.com/rdk/components/input 88% 0.00%
go.viam.com/rdk/components/input/fake 93% -1.49%
go.viam.com/rdk/components/input/gpio 85% 0.00%
go.viam.com/rdk/components/motor 71% 0.00%
go.viam.com/rdk/components/motor/dimensionengineering 67% 0.00%
go.viam.com/rdk/components/motor/dmc4000 70% 0.00%
go.viam.com/rdk/components/motor/fake 55% 0.00%
go.viam.com/rdk/components/motor/gpio 73% 0.00%
go.viam.com/rdk/components/motor/gpiostepper 69% 0.00%
go.viam.com/rdk/components/motor/tmcstepper 53% 0.00%
go.viam.com/rdk/components/motor/ulnstepper 53% 0.00%
go.viam.com/rdk/components/movementsensor 76% 0.00%
go.viam.com/rdk/components/movementsensor/adxl345 75% 0.00%
go.viam.com/rdk/components/movementsensor/cameramono 42% 0.00%
go.viam.com/rdk/components/movementsensor/gpsnmea 55% 0.00%
go.viam.com/rdk/components/movementsensor/gpsrtkpmtk 33% 0.00%
go.viam.com/rdk/components/movementsensor/gpsrtkserial 29% 0.00%
go.viam.com/rdk/components/movementsensor/merged 91% 0.00%
go.viam.com/rdk/components/movementsensor/mpu6050 84% 0.00%
go.viam.com/rdk/components/movementsensor/rtkutils 24% 0.00%
go.viam.com/rdk/components/posetracker 71% 0.00%
go.viam.com/rdk/components/sensor 51% 0.00%
go.viam.com/rdk/components/sensor/ultrasonic 38% 0.00%
go.viam.com/rdk/components/servo 62% 0.00%
go.viam.com/rdk/components/servo/gpio 72% 0.00%
go.viam.com/rdk/config 79% 0.00%
go.viam.com/rdk/control 57% 0.00%
go.viam.com/rdk/data 77% 0.00%
go.viam.com/rdk/examples/customresources/demos/remoteserver 0% 0.00%
go.viam.com/rdk/grpc 25% 0.00%
go.viam.com/rdk/internal/cloud 100% 0.00%
go.viam.com/rdk/ml 67% 0.00%
go.viam.com/rdk/ml/inference 71% 0.00%
go.viam.com/rdk/module 75% 0.00%
go.viam.com/rdk/module/modmanager 82% 0.00%
go.viam.com/rdk/motionplan 80% +0.05%
go.viam.com/rdk/motionplan/tpspace 78% 0.00%
go.viam.com/rdk/operation 82% 0.00%
go.viam.com/rdk/pointcloud 67% 0.00%
go.viam.com/rdk/protoutils 49% 0.00%
go.viam.com/rdk/referenceframe 65% 0.00%
go.viam.com/rdk/resource 76% 0.00%
go.viam.com/rdk/rimage 55% 0.00%
go.viam.com/rdk/rimage/depthadapter 94% 0.00%
go.viam.com/rdk/rimage/transform 72% 0.00%
go.viam.com/rdk/rimage/transform/cmd/extrinsic_calibration 67% 0.00%
go.viam.com/rdk/robot 86% 0.00%
go.viam.com/rdk/robot/client 82% 0.00%
go.viam.com/rdk/robot/framesystem 36% 0.00%
go.viam.com/rdk/robot/impl 83% 0.00%
go.viam.com/rdk/robot/packages 80% 0.00%
go.viam.com/rdk/robot/server 55% 0.00%
go.viam.com/rdk/robot/web 65% +0.16%
go.viam.com/rdk/robot/web/stream 87% 0.00%
go.viam.com/rdk/services/baseremotecontrol 50% 0.00%
go.viam.com/rdk/services/baseremotecontrol/builtin 81% 0.00%
go.viam.com/rdk/services/datamanager 65% 0.00%
go.viam.com/rdk/services/datamanager/builtin 89% +0.49%
go.viam.com/rdk/services/datamanager/datacapture 73% 0.00%
go.viam.com/rdk/services/datamanager/datasync 0% 0.00%
go.viam.com/rdk/services/mlmodel 83% 0.00%
go.viam.com/rdk/services/mlmodel/tflitecpu 82% 0.00%
go.viam.com/rdk/services/motion 45% 0.00%
go.viam.com/rdk/services/motion/builtin 79% 0.00%
go.viam.com/rdk/services/navigation 49% 0.00%
go.viam.com/rdk/services/navigation/builtin 85% 0.00%
go.viam.com/rdk/services/sensors 81% 0.00%
go.viam.com/rdk/services/sensors/builtin 97% 0.00%
go.viam.com/rdk/services/shell 11% 0.00%
go.viam.com/rdk/services/slam 73% -5.78%
go.viam.com/rdk/services/slam/fake 82% 0.00%
go.viam.com/rdk/services/vision 35% 0.00%
go.viam.com/rdk/services/vision/colordetector 56% 0.00%
go.viam.com/rdk/services/vision/detectionstosegments 67% 0.00%
go.viam.com/rdk/services/vision/mlvision 67% 0.00%
go.viam.com/rdk/services/vision/obstacledistance 77% 0.00%
go.viam.com/rdk/services/vision/radiusclustering 59% 0.00%
go.viam.com/rdk/session 94% 0.00%
go.viam.com/rdk/spatialmath 82% 0.00%
go.viam.com/rdk/utils 68% 0.00%
go.viam.com/rdk/utils/contextutils 38% 0.00%
go.viam.com/rdk/vision 32% 0.00%
go.viam.com/rdk/vision/delaunay 87% 0.00%
go.viam.com/rdk/vision/keypoints 92% 0.00%
go.viam.com/rdk/vision/objectdetection 69% 0.00%
go.viam.com/rdk/vision/odometry 60% 0.00%
go.viam.com/rdk/vision/odometry/cmd 0% 0.00%
go.viam.com/rdk/vision/segmentation 49% 0.00%
go.viam.com/rdk/web/server 26% 0.00%
Summary 63% (22100 / 34831) -0.06%

@AaronCasas AaronCasas merged commit 8b3f5c4 into viamrobotics:main Jul 28, 2023
bazile-clyde pushed a commit to bazile-clyde/rdk that referenced this pull request Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test This pull request is marked safe to test from a trusted zone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants