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

dialdbg initial implementation #57

Merged
merged 15 commits into from
Jul 12, 2023
Merged

Conversation

benjirewis
Copy link
Member

@benjirewis benjirewis commented Jun 30, 2023

RSDK-3442
RSDK-3443

cc @edaniels , @cheukt , @zaporter-work , @mattjperez

Implements a basic CLI tool, dialdbg, to better understand the behavior of rust-utils' dial functionality (both through gRPC and WebRTC).

dialdbg --help output:

dialdbg gives information on how rust-utils' dial function makes connections

Usage: viam-dialdbg [OPTIONS] --uri <URI>

Options:
  -u, --uri <URI>
          URI to dial. Must be provided
      --nogrpc
          Whether direct gRPC connection should not be examined. If not provided, gRPC connection will be examined
      --nowebrtc
          Whether WebRTC connection should not be examined. If not provided, WebRTC connection will be examined
  -o, --output <OUTPUT>
          Filepath for output of dialdbg (file will be overwritten). If not provided, dialdbg will output to STDOUT
  -c, --credential <CREDENTIAL>
          Credential payload with which to connect to the URI. If not provided, dialdbg will dial without credentials
  -t, --credential-type <CREDENTIAL_TYPE>
          Type of credential with which to connect to the URI. Can only be provided with "--credential". If "--credential" is provided but "--credential-type" is not, credential type will default to "robot-location-secret"
  -h, --help
          Print help
  -V, --version
          Print version

dialdbg --uri URI --credential ROBOTSECRET output where URI is a robot on the same subnet (connectable to through mDNS) and ROBOTSECRET is its robot location secret.

Debugging dial with basic gRPC...

mDNS address 10.1.5.217:35321 was used for connection
mDNS queried in 339ms
authentication successful in 56ms
gRPC connection establishment successful in 397ms

Done debugging dial with basic gRPC.

Debugging dial with WebRTC...

mDNS address 10.1.5.217:35321 was used for connection
mDNS queried in 176ms
authentication successful in 98ms
WebRTC connection establishment successful in 345ms
selected ICE candidate pair was:
	(local) udp host e6e2f09b-bb6c-4ae4-9c5a-9f1fea22bb13.local:54432 <-> (remote) udp host 10.1.5.217:35130

nominated ICE candidates:

	remote ICE candidate:
		IP address: 127.0.0.1
		port: 49866
		nominated 1.094708ms ago
		relay protocol: udp
		network type: udp4
	local ICE candidate:
		IP address: e6e2f09b-bb6c-4ae4-9c5a-9f1fea22bb13.local
		port: 53121
		nominated 1.105ms ago
		relay protocol: udp
		network type: udp6
	remote ICE candidate:
		IP address: 100.104.116.117
		port: 54473
		nominated 1.093708ms ago
		relay protocol: udp
		network type: udp4
	local ICE candidate:
		IP address: e6e2f09b-bb6c-4ae4-9c5a-9f1fea22bb13.local
		port: 54432
		nominated 1.104291ms ago
		relay protocol: udp
		network type: udp4
	remote ICE candidate:
		IP address: 10.1.5.217
		port: 35130
		nominated 1.094375ms ago
		relay protocol: udp
		network type: udp4
	local ICE candidate:
		IP address: 71.167.222.76
		port: 60829
		nominated 1.103916ms ago
		relay protocol: udp
		network type: udp4
	remote ICE candidate:
		IP address: fd7a:115c:a1e0:ab12:4843:cd96:6268:7475
		port: 56270
		nominated 1.09525ms ago
		relay protocol: udp
		network type: udp6

Done debugging dial with WebRTC.

dialdbg --uri BAD_URI --secret ROBOTSECRET output where bad_rover.json is an incorrect viam.cloud URI.

Debugging dial with basic gRPC...

mDNS could not be used to connect
authentication failed
gRPC connection establishment failed

unexpected dial connect error: status: PermissionDenied, message: "failed to authenticate: no location found", details: [], metadata: MetadataMap { headers: {"content-security-policy": "frame-ancestors 'self'; form-action 'self';", "content-type": "application/grpc", "strict-transport-security": "max-age=63072000; includeSubDomains; preload", "trailer": "Grpc-Status", "trailer": "Grpc-Message", "trailer": "Grpc-Status-Details-Bin", "vary": "Origin", "x-content-type-options": "nosniff", "x-frame-options": "SAMEORIGIN", "date": "Fri, 30 Jun 2023 20:50:04 GMT", "server": "Google Frontend", "x-cloud-trace-context": "012f431cf2557357c3024279dff20029/2554969079733192940", "traceparent": "00-012f431cf2557357c3024279dff20029-237512d7599a88ec-00", "content-length": "0"} }

Done debugging dial with basic gRPC.

Debugging dial with WebRTC...

mDNS could not be used to connect
authentication failed
WebRTC connection establishment failed

unexpected dial connect error: status: PermissionDenied, message: "failed to authenticate: no location found", details: [], metadata: MetadataMap { headers: {"content-security-policy": "frame-ancestors 'self'; form-action 'self';", "content-type": "application/grpc", "strict-transport-security": "max-age=63072000; includeSubDomains; preload", "trailer": "Grpc-Status", "trailer": "Grpc-Message", "trailer": "Grpc-Status-Details-Bin", "vary": "Origin", "x-content-type-options": "nosniff", "x-frame-options": "SAMEORIGIN", "date": "Fri, 30 Jun 2023 20:50:10 GMT", "server": "Google Frontend", "traceparent": "00-196a03bfe2f8f54a3e98cb162e75396e-bc5a856d927ccbd8-00", "x-cloud-trace-context": "196a03bfe2f8f54a3e98cb162e75396e/13572307132689992664", "content-length": "0"} }

Done debugging dial with WebRTC.

Similar errors are output for invalid secret and invalid non-viam URI respectively:

unexpected dial connect error: status: Unauthenticated, message: "invalid credentials", details: [], metadata: MetadataMap { headers: {"content-type": "application/grpc"} }
unexpected dial connect error: status: Unknown, message: "transport error", details: [], metadata: MetadataMap { headers: {} }

@benjirewis benjirewis requested review from npmenard and stuqdog June 30, 2023 21:02
@benjirewis benjirewis marked this pull request as ready for review June 30, 2023 21:02
@benjirewis benjirewis requested a review from a team as a code owner June 30, 2023 21:02
@benjirewis benjirewis requested review from jckras and removed request for a team June 30, 2023 21:02
@edaniels
Copy link
Contributor

edaniels commented Jul 5, 2023

Will take a look today!

Copy link
Contributor

@edaniels edaniels left a comment

Choose a reason for hiding this comment

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

Done with a first pass. nice!

Cargo.toml Show resolved Hide resolved
src/rpc/base_channel.rs Show resolved Hide resolved
dialdbg/src/main.rs Outdated Show resolved Hide resolved
dialdbg/src/main.rs Outdated Show resolved Hide resolved
dialdbg/src/main.rs Outdated Show resolved Hide resolved
dialdbg/src/main.rs Outdated Show resolved Hide resolved
dialdbg/src/main.rs Outdated Show resolved Hide resolved
dialdbg/src/main.rs Outdated Show resolved Hide resolved
dialdbg/src/main.rs Show resolved Hide resolved
Copy link
Member

@zaporter-work zaporter-work left a comment

Choose a reason for hiding this comment

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

Mostly optional language comments. Logic looks reasonable

dialdbg/src/main.rs Outdated Show resolved Hide resolved
dialdbg/src/main.rs Outdated Show resolved Hide resolved
dialdbg/src/main.rs Outdated Show resolved Hide resolved
dialdbg/src/main.rs Outdated Show resolved Hide resolved
dialdbg/src/main.rs Outdated Show resolved Hide resolved
dialdbg/src/main.rs Show resolved Hide resolved
dialdbg/src/parse.rs Outdated Show resolved Hide resolved
Copy link
Member

@npmenard npmenard left a comment

Choose a reason for hiding this comment

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

Done with first pass. Tricky to use log file to pass stats around (tracing could be better here) but for a POC i think its fine. I would definitely add a test to make sure that parsing works when the rust-lib gets updated.
Your parsing fails on the first error encountered, so where it makes sense I would continue parsing even in case of errors.

dialdbg/src/main.rs Outdated Show resolved Hide resolved
dialdbg/src/main.rs Outdated Show resolved Hide resolved
src/rpc/dial.rs Outdated Show resolved Hide resolved
Copy link
Member

@stuqdog stuqdog left a comment

Choose a reason for hiding this comment

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

First pass, looks pretty good!

src/rpc/dial.rs Outdated Show resolved Hide resolved
dialdbg/src/main.rs Outdated Show resolved Hide resolved
dialdbg/src/main.rs Outdated Show resolved Hide resolved
dialdbg/src/main.rs Outdated Show resolved Hide resolved
dialdbg/src/main.rs Outdated Show resolved Hide resolved
dialdbg/src/main.rs Outdated Show resolved Hide resolved
dialdbg/src/main.rs Outdated Show resolved Hide resolved
dialdbg/src/parse.rs Outdated Show resolved Hide resolved
dialdbg/src/parse.rs Show resolved Hide resolved
dialdbg/src/strings.rs Outdated Show resolved Hide resolved
@stuqdog stuqdog removed the request for review from jckras July 7, 2023 14:20
@stuqdog
Copy link
Member

stuqdog commented Jul 7, 2023

(removed @jckras as a reviewer to avoid a "too many cooks" situation, Julie feel free to look of course if you're interested!)

Copy link
Contributor

@edaniels edaniels left a comment

Choose a reason for hiding this comment

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

LGTM from my side but I am yet a lowly rust newbie.

dialdbg/src/parse.rs Outdated Show resolved Hide resolved
Copy link
Member

@npmenard npmenard left a comment

Choose a reason for hiding this comment

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

LGTM

@zaporter-work zaporter-work removed their request for review July 11, 2023 16:08
@zaporter-work
Copy link
Member

zaporter-work commented Jul 11, 2023

Don't have time for in-depth review, but overall LGTM!

// NOTE(benjirewis): Use a duration of 1500ms for getting the mDNS URI. I've anecdotally
// seen times as great as 922ms to fetch a non-loopback mDNS URI. With an
// interface_with_loopback query interval of 250ms, 1500ms here should give us time for ~6
// queries.
Copy link
Member Author

Choose a reason for hiding this comment

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

@cheukt / @stuqdog , I lowered both the interface_with_loopback query interval and the get_mdns_uri timeout to allow for faster-completing mDNS discovery (@erh hopefully this fixes your issue with excessively long dials when mDNS is enabled but not used).

Copy link
Member

@stuqdog stuqdog left a comment

Choose a reason for hiding this comment

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

LGTM!

src/rpc/dial.rs Outdated Show resolved Hide resolved
src/rpc/dial.rs Outdated Show resolved Hide resolved
dialdbg/src/main.rs Outdated Show resolved Hide resolved
pub(crate) const DIAL_ERROR_PREFIX: &'static str = "unexpected dial connect error";

#[derive(Debug, Default)]
pub(crate) struct GRPCResult {
Copy link
Member

Choose a reason for hiding this comment

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

Probably over-engineering right now, but it would be neat if we could dedup some of the shared code across GRPCResult and WebRTCResult

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good point; I probably won't in this PR, but I can imagine deduping more in the future as the code around these structs increases (potentially as part of RSDK-3444).

dialdbg/src/parse.rs Show resolved Hide resolved
@benjirewis benjirewis merged commit 3468c50 into viamrobotics:main Jul 12, 2023
@benjirewis benjirewis deleted the dialdbg branch July 12, 2023 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants