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

RSDK-5608 - CLI commands for managing cloud builds #3298

Merged
merged 27 commits into from
Dec 8, 2023

Conversation

zaporter-work
Copy link
Member

@zaporter-work zaporter-work commented Dec 5, 2023

Ticket: https://viam.atlassian.net/browse/RSDK-5608

This adds the cli commands for managing cloud builds. The backend changes to support these new APIs in app have not been merged yet.

The help text for these functions is still hidden, so these functions can still be considered mostly-internal.

We have been encouraged to merge sooner rather than later so probably okay to merge with some functionality unfinished.

Output:

➜   git:(main) ✗ viam module build list
Info: Using "http://localhost:8080" as base URL value
ID                                   PLATFORM    STATUS VERSION TIME
48a20efd-49ae-4ae9-90f0-86e6faa2af88 linux/amd64 Done   0.1.0   2023-11-30T21:04:08Z
1131099c-f3f4-4309-926a-a0b5b9b830d8 linux/amd64 Done   0.1.1   2023-11-30T23:59:21Z
82df23ac-6d39-4a96-b0e6-d4a649e8db9e linux/amd64 Done   0.1.2   2023-12-01T00:05:39Z
5012a8e9-67ad-4108-a688-1e96832c0f79 linux/amd64 Done   0.1.3   2023-12-01T00:12:52Z
cb8e80d6-7faa-47d4-bc23-f12e2c099605 linux/amd64 Done   0.1.4   2023-12-01T00:15:30Z
66c34409-c4ec-45c4-bcfb-aa011f82df7e linux/amd64 Done   0.1.5   2023-12-01T00:19:14Z
➜   git:(main) ✗ viam module build logs --id 66c34409-c4ec-45c4-bcfb-aa011f82df7e --platform linux/amd64
Info: Using "http://localhost:8080" as base URL value
Info: Spin up environment
Build-agent version 1.0.211975-3953146a (2023-11-30T16:01:58+0000).
System information:
 Server Version: 24.0.7
 Storage Driver: overlay2
  Backing Filesystem: xfs
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Kernel Version: 5.15.0-1039-aws
 Operating System: Ubuntu 20.04.6 LTS
 OSType: linux
 Architecture: x86_64

Starting container ghcr.io/viamrobotics/rdk-devenv:amd64
  image cache not found on this host, downloading ghcr.io/viamrobotics/rdk-devenv:amd64
amd64: Pulling from viamrobotics/rdk-devenv
0a9573503463: Already exists
e7faf8403b00: Pull complete
7dda16c4d1f1: Pull complete
c684d79aeecd: Pull complete
fbdfc6b4d926: Pull complete
0ba22584ce5e: Pull complete
b45fd1bbb58a: Pull complete
ae63152ee5e1: Pull complete
076b2b90a03f: Pull complete
4a3ed1f87f37: Pull complete
30c62fa86fe3: Pull complete
39d99c3b344c: Pull complete
0268616acf85: Pull complete
fdf7a95333e3: Pull complete
a346eb8920ec: Pull complete
5b09d837e0fb: Pull complete
ac7075292dc2: Pull complete
9b52e1bc3a02: Pull complete
539833c67495: Pull complete
ee2955bf182c: Download complete
92587694b170: Download complete
ghcr.io/viamrobotics/rdk-devenv:amd64:
  using image ghcr.io/viamrobotics/rdk-devenv@sha256:6257153b127fe563a8c78a072b51c8fc4947bc8450f95d91df8273e5c0632de3
ee2955bf182c: Pull complete
92587694b170: Pull complete
Digest: sha256:6257153b127fe563a8c78a072b51c8fc4947bc8450f95d91df8273e5c0632de3
Status: Downloaded newer image for ghcr.io/viamrobotics/rdk-devenv:amd64
Time to upload agent and config: 176.689785ms
Time to start containers: 302.446703ms
Info: Preparing environment variables
Using build environment variables:
... OMITTED ...
Total size uploaded: 61 KiB

Note:

This does not have any tests yet.

If we are happy with the functionality, I will happily write a few tests.

@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Dec 5, 2023
go.mod Outdated Show resolved Hide resolved
@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 Dec 5, 2023
Copy link
Member

@benjirewis benjirewis left a comment

Choose a reason for hiding this comment

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

Nice! Some initial comments with what context I have.

cli/app.go Outdated Show resolved Hide resolved
cli/module_build.go Show resolved Hide resolved
cli/module_build.go Show resolved Hide resolved
cli/module_build.go Show resolved Hide resolved
if ctx.Err() != nil {
return ctx.Err()
}
log, err := stream.Recv()
Copy link
Member

Choose a reason for hiding this comment

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

What is the type of stream and can Recv() block forever? I'm surprised Recv() does not take a context if this is doing network IO.

Copy link
Member Author

@zaporter-work zaporter-work Dec 6, 2023

Choose a reason for hiding this comment

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

It is quite surprising that it doesn't take a context. After looking it up, it seems like this is a known issue and the fix is to just put it in a goroutine 🤦 grpc/grpc-go#1229 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

just put it in a goroutine

Hmm gotcha; thanks for looking into it. Curious to see what that will look like here; my intuition is that you will inevitably potentially leak that goroutine. FWIW old Golang libraries (apparently e.g. grpc-go) sometimes have network I/O functions that do not take contexts, as contexts weren't around/popular at the time of writing the library (unclear if that's the reason for lack of context here, just a hypothesis). The "workaround"s usually look like an alternative "context" version of the method like stream.RecvCtx(...) or some stream.SetTimeout(...) method to control the deadline of the Recv call.

Copy link
Member Author

Choose a reason for hiding this comment

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

stream.RecvCtx(...) or some stream.SetTimeout(...) method to control the deadline of the Recv call.

That is what I was hoping to find, but I can't seem to find it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've put a basic impl in the bottom of f1d120d

It is a bit inefficient because it creates a new goroutine every loop, but from what I've been reading about goroutines, that seems cheap compared to network io.

If you have a better impl, I would love to see what you come up with.

Copy link
Member Author

Choose a reason for hiding this comment

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

Reverted to Recv because I /think/ it respects the ctx of the stream which is the ctx of the cli (passed to GetLogs).

I haven't tested this and it is many layers deep in grpc code, but I am ~60% confident. (also the rest of viam uses the same pattern so if it is a problem, it is a problem everywhere. so we should fix it then)

grpc/internal/transport/transport.go:321

func (s *Stream) waitOnHeader() {
	if s.headerChan == nil {
		// On the server headerChan is always nil since a stream originates
		// only after having received headers.
		return
	}
	select {
	case <-s.ctx.Done():
		// Close the stream to prevent headers/trailers from changing after
		// this function returns.
		s.ct.CloseStream(s, ContextErr(s.ctx.Err()))
		// headerChan could possibly not be closed yet if closeStream raced
		// with operateHeaders; wait until it is closed explicitly here.
		<-s.headerChan
	case <-s.headerChan:
	}
}

// RecvCompress returns the compression algorithm applied to the inbound
// message. It is empty string if there is no compression applied.
func (s *Stream) RecvCompress() string {
	s.waitOnHeader()
	return s.recvCompress
}

Copy link
Member Author

Choose a reason for hiding this comment

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

(also talked offline)

Copy link
Member

Choose a reason for hiding this comment

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

Cool; after offline discussion, stream.Recv() seems totally fine for now (especially given, as you pointed out, the prevalence of no-timeout-network-IO across the CLI). Thanks for digging into this; I'll trust the 60% for now and we can reconsider if NetCode and/or fleet decide we need sensible default timeouts for the CLI.

Copy link
Member

@michaellee1019 michaellee1019 left a comment

Choose a reason for hiding this comment

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

Just some small comments about usability. otherwise LGTM!

cli/app.go Outdated
@@ -40,6 +40,12 @@ const (
moduleFlagPlatform = "platform"
moduleFlagForce = "force"

moduleBuildFlagNumber = "number"
Copy link
Member

Choose a reason for hiding this comment

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

Initially read as build number, something like PR number, so recommend count instead. I think it will reduce any confusion that users might have.

Suggested change
moduleBuildFlagNumber = "number"
moduleBuildFlagCount = "count"

Copy link
Member Author

Choose a reason for hiding this comment

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

SGTM! Will do

Copy link
Member Author

@zaporter-work zaporter-work Dec 6, 2023

Choose a reason for hiding this comment

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

Previously:


NAME:
   viam module build list - check on the status of your cloud builds

USAGE:
   viam module build list [command options] [arguments...]

OPTIONS:
   --id value                restrict output to just return builds that match this id
   --module value            path to meta.json (default: "./meta.json")
   --number value, -n value  number of builds to list (default: all)

Now:

NAME:
   viam module build list - check on the status of your cloud builds

USAGE:
   viam module build list [command options] [arguments...]

OPTIONS:
   --count value, -c value  number of builds to list (default: all)
   --id value               restrict output to just return builds that match this id
   --module value           path to meta.json (default: "./meta.json")

"--count" > "--number" however "-n" > "-c" in my opinion... not sure. (also not sure it really matters.)

Happy to go either way (count or number) if you still think count is better

Copy link
Member

Choose a reason for hiding this comment

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

hmm. just do -c because usually single character flags should match the first character of the larger one.

Copy link
Member Author

Choose a reason for hiding this comment

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

LGTM

Name: moduleBuildFlagNumber,
Usage: "number of builds to list",
Aliases: []string{"n"},
DefaultText: "all",
Copy link
Member

Choose a reason for hiding this comment

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

I tried to look this up myself but couldn't figure it out. Should DefaultText always come with a Value? Is it that DefaultText is a suggested value where as Value is an actual default?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, this surprising behavior was fixed for the other cli commands in #3162

My understanding is that:
DefaultText => shows in help msg, does not actually change the default value when you try to read the flag
Value => shows in help msg + actual default value

Copy link
Member

@michaellee1019 michaellee1019 Dec 6, 2023

Choose a reason for hiding this comment

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

Yup thanks for confirming what I found. I feel like DefaultText isn't appropriate then. The "default" is that you don't specify the flag at all, otherwise you specify it and it should be a int.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, as we discussed keep it as-is.

@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 Dec 6, 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 Dec 6, 2023
Copy link
Member

@benjirewis benjirewis left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks 🧑‍🔧 .

cli/module_build.go Show resolved Hide resolved
if ctx.Err() != nil {
return ctx.Err()
}
log, err := stream.Recv()
Copy link
Member

Choose a reason for hiding this comment

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

Cool; after offline discussion, stream.Recv() seems totally fine for now (especially given, as you pointed out, the prevalence of no-timeout-network-IO across the CLI). Thanks for digging into this; I'll trust the 60% for now and we can reconsider if NetCode and/or fleet decide we need sensible default timeouts for the CLI.

@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 Dec 6, 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 Dec 8, 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 Dec 8, 2023
Copy link
Contributor

github-actions bot commented Dec 8, 2023

Code Coverage

Code Coverage
Package Line Rate Delta Health
go.viam.com/rdk/cli 15% +1.64%
go.viam.com/rdk/components/arm 67% 0.00%
go.viam.com/rdk/components/arm/fake 29% 0.00%
go.viam.com/rdk/components/arm/universalrobots 43% +0.72%
go.viam.com/rdk/components/arm/wrapper 22% 0.00%
go.viam.com/rdk/components/arm/xarm 22% 0.00%
go.viam.com/rdk/components/audioinput 44% 0.00%
go.viam.com/rdk/components/base 60% 0.00%
go.viam.com/rdk/components/base/kinematicbase 37% 0.00%
go.viam.com/rdk/components/base/sensorcontrolled 61% -1.24%
go.viam.com/rdk/components/base/wheeled 84% 0.00%
go.viam.com/rdk/components/board 66% 0.00%
go.viam.com/rdk/components/board/customlinux 47% 0.00%
go.viam.com/rdk/components/board/fake 40% 0.00%
go.viam.com/rdk/components/board/genericlinux 5% 0.00%
go.viam.com/rdk/components/board/numato 19% 0.00%
go.viam.com/rdk/components/board/pi/impl 12% 0.00%
go.viam.com/rdk/components/camera 55% 0.00%
go.viam.com/rdk/components/camera/align 63% 0.00%
go.viam.com/rdk/components/camera/fake 74% 0.00%
go.viam.com/rdk/components/camera/ffmpeg 81% 0.00%
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 73% 0.00%
go.viam.com/rdk/components/camera/ultrasonic 61% 0.00%
go.viam.com/rdk/components/camera/videosource 36% 0.00%
go.viam.com/rdk/components/encoder 66% 0.00%
go.viam.com/rdk/components/encoder/ams 61% 0.00%
go.viam.com/rdk/components/encoder/fake 83% 0.00%
go.viam.com/rdk/components/encoder/incremental 81% 0.00%
go.viam.com/rdk/components/encoder/single 86% 0.00%
go.viam.com/rdk/components/gantry 71% 0.00%
go.viam.com/rdk/components/gantry/multiaxis 82% 0.00%
go.viam.com/rdk/components/gantry/singleaxis 83% 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 79% 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 67% +0.40%
go.viam.com/rdk/components/motor/gpiostepper 72% 0.00%
go.viam.com/rdk/components/motor/tmcstepper 50% 0.00%
go.viam.com/rdk/components/motor/ulnstepper 52% 0.00%
go.viam.com/rdk/components/movementsensor 73% 0.00%
go.viam.com/rdk/components/movementsensor/adxl345 75% 0.00%
go.viam.com/rdk/components/movementsensor/gpsnmea 52% -2.75%
go.viam.com/rdk/components/movementsensor/gpsrtkpmtk 22% 0.00%
go.viam.com/rdk/components/movementsensor/gpsrtkserial 18% 0.00%
go.viam.com/rdk/components/movementsensor/merged 91% 0.00%
go.viam.com/rdk/components/movementsensor/mpu6050 79% 0.00%
go.viam.com/rdk/components/movementsensor/replay 88% 0.00%
go.viam.com/rdk/components/movementsensor/rtkutils 24% 0.00%
go.viam.com/rdk/components/movementsensor/wheeledodometry 76% +0.64%
go.viam.com/rdk/components/posetracker 71% 0.00%
go.viam.com/rdk/components/powersensor 74% 0.00%
go.viam.com/rdk/components/sensor 75% 0.00%
go.viam.com/rdk/components/sensor/ultrasonic 38% 0.00%
go.viam.com/rdk/components/servo 72% 0.00%
go.viam.com/rdk/components/servo/gpio 72% 0.00%
go.viam.com/rdk/config 81% 0.00%
go.viam.com/rdk/control 58% 0.00%
go.viam.com/rdk/data 72% 0.00%
go.viam.com/rdk/examples/customresources/demos/remoteserver 0% 0.00%
go.viam.com/rdk/gostream 20% 0.00%
go.viam.com/rdk/gostream/codec/x264 8% 0.00%
go.viam.com/rdk/grpc 25% 0.00%
go.viam.com/rdk/internal/cloud 65% 0.00%
go.viam.com/rdk/logging 70% 0.00%
go.viam.com/rdk/ml/inference 67% 0.00%
go.viam.com/rdk/module 75% 0.00%
go.viam.com/rdk/module/modmanager 75% 0.00%
go.viam.com/rdk/motionplan 77% +0.32%
go.viam.com/rdk/motionplan/ik 67% 0.00%
go.viam.com/rdk/motionplan/tpspace 43% 0.00%
go.viam.com/rdk/operation 83% 0.00%
go.viam.com/rdk/pointcloud 67% +0.07%
go.viam.com/rdk/protoutils 49% 0.00%
go.viam.com/rdk/referenceframe 68% 0.00%
go.viam.com/rdk/referenceframe/urdf 79% 0.00%
go.viam.com/rdk/resource 77% 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 70% 0.00%
go.viam.com/rdk/rimage/transform/cmd/extrinsic_calibration 67% 0.00%
go.viam.com/rdk/robot 85% 0.00%
go.viam.com/rdk/robot/client 82% +0.18%
go.viam.com/rdk/robot/framesystem 37% 0.00%
go.viam.com/rdk/robot/impl 82% 0.00%
go.viam.com/rdk/robot/packages 77% 0.00%
go.viam.com/rdk/robot/server 55% 0.00%
go.viam.com/rdk/robot/web 65% 0.00%
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 58% 0.00%
go.viam.com/rdk/services/datamanager/builtin 81% -0.81%
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 81% 0.00%
go.viam.com/rdk/services/mlmodel/tflitecpu 86% 0.00%
go.viam.com/rdk/services/motion 85% 0.00%
go.viam.com/rdk/services/motion/builtin 87% 0.00%
go.viam.com/rdk/services/motion/builtin/state 85% 0.00%
go.viam.com/rdk/services/motion/explore 44% 0.00%
go.viam.com/rdk/services/navigation 50% 0.00%
go.viam.com/rdk/services/navigation/builtin 78% 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% 0.00%
go.viam.com/rdk/services/slam/fake 82% 0.00%
go.viam.com/rdk/services/vision 34% 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 64% -0.26%
go.viam.com/rdk/services/vision/obstaclesdepth 70% 0.00%
go.viam.com/rdk/services/vision/obstaclesdistance 73% 0.00%
go.viam.com/rdk/services/vision/obstaclespointcloud 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 47% 0.00%
go.viam.com/rdk/vision 37% 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/segmentation 55% 0.00%
go.viam.com/rdk/web/server 0% 0.00%
Summary 61% (25211 / 41572) -0.03%

@zaporter-work zaporter-work merged commit 5c1ac8c into viamrobotics:main Dec 8, 2023
15 checks passed
@zaporter-work zaporter-work deleted the cloud-build branch December 8, 2023 16:57
bazile-clyde pushed a commit to bazile-clyde/rdk that referenced this pull request Jan 5, 2024
Co-authored-by: Abe Winter <abe-winter@users.noreply.github.com>
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.

5 participants