Skip to content

Conversation

danielbotros
Copy link
Member

@danielbotros danielbotros commented Sep 2, 2025

Description

RSDK-8344 Expose machine internet connectivity

  • ClientConn interface extended to include GetState in this goutils PR
  • This PR follows up by implementing GetState method to AppConn, SharedConn, and ReconfigurableClientConn as well some mock/test types.
    • Returns the connection state (i.e. Ready when connected to app without issue)

Testing

Main use case is for the data manager. I tested these changes alongside my goutils changes by calling my GetState where the data manager calls its version of GetState (in runScheduler in sync.go) receiving this log line:
2025-09-05T15:52:58.260Z INFO rdk.resource_manager.rdk:service:data_manager/dm.sync sync/sync.go:573 cloud conn state is {"state":"READY"}

@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Sep 2, 2025
@danielbotros danielbotros changed the title Rsdk 8344 expose machine internet connectivity [RSDK-8344] Expose machine internet connectivity Sep 2, 2025
@danielbotros danielbotros marked this pull request as ready for review September 2, 2025 21:12
@danielbotros danielbotros requested a review from cheukt September 2, 2025 21:12
grpc/app_conn.go Outdated
Comment on lines 120 to 121
// IsConnected checks if the underlying connection is established.
func (ac *AppConn) IsConnected() bool {
Copy link
Member Author

Choose a reason for hiding this comment

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

Additionally we could add or replace this function with one that returns connectivity.State given that we might want to handle transient failure different from offline

Copy link
Member

Choose a reason for hiding this comment

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

let's return connectivity.State here. if ac.conn == nil we can return Connecting

Copy link
Member Author

Choose a reason for hiding this comment

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

updated

@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 Sep 3, 2025
grpc/app_conn.go Outdated
return grpcConn.GetState()
}

return connectivity.Shutdown
Copy link
Member Author

@danielbotros danielbotros Sep 3, 2025

Choose a reason for hiding this comment

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

We shouldn't really ever hit this since GetState() is a default method for ClientConn but I wasn't too sure how to handle it. I assume the worst case that the connection is shutdown and unusable, but someone may try to reconnect based off that. I could change it to an optional pattern

Copy link
Member

Choose a reason for hiding this comment

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

maybe add a const Invalid connectivity.State = 5?

@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 Sep 3, 2025
Copy link
Member

@cheukt cheukt left a comment

Choose a reason for hiding this comment

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

how did you test this?

grpc/app_conn.go Outdated
return grpcConn.GetState()
}

return connectivity.Shutdown
Copy link
Member

Choose a reason for hiding this comment

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

maybe add a const Invalid connectivity.State = 5?

@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 Sep 5, 2025
@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 Sep 5, 2025
@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 Sep 5, 2025
grpc/conn.go Outdated
Comment on lines 109 to 110
if c.conn == nil {
return connectivity.Connecting
Copy link
Member Author

@danielbotros danielbotros Sep 5, 2025

Choose a reason for hiding this comment

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

I handle this case in ReconfigurableClientConn since app conn and shared conn are wrappers around it and I assume we will continue to build ontop of this type

Copy link
Member

Choose a reason for hiding this comment

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

for ReconfigurableClientConn, I think this would be incorrect because we don't actually know what other structs are doing with ReconfigurableClientConn if conn is nil (they could be purposefully leaving it nil for a while for some other event that we don't know of).
We should return Unknown here but Connecting in AppConn if conn is nil

go.mod Outdated
@@ -83,7 +83,7 @@ require (
go.uber.org/zap v1.27.0
go.viam.com/api v0.1.473
go.viam.com/test v1.2.4
go.viam.com/utils v0.1.164
go.viam.com/utils v0.1.166
Copy link
Member Author

Choose a reason for hiding this comment

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

WIll bump to correct version once goutils changes merged

grpc/conn.go Outdated
Comment on lines 109 to 110
if c.conn == nil {
return connectivity.Connecting
Copy link
Member

Choose a reason for hiding this comment

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

for ReconfigurableClientConn, I think this would be incorrect because we don't actually know what other structs are doing with ReconfigurableClientConn if conn is nil (they could be purposefully leaving it nil for a while for some other event that we don't know of).
We should return Unknown here but Connecting in AppConn if conn is nil

@@ -359,6 +360,10 @@ func (sc *SharedConn) ProcessEncodedAnswer(encodedAnswer string) error {
return nil
}

func (sc *SharedConn) GetState() connectivity.State {
return sc.grpcConn.GetState()
Copy link
Member

Choose a reason for hiding this comment

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

SharedConn is also a bit awkward because it serves both grpcConn and the peerConn, and there isn't a good way to surface the state of both at the same time. I'd also make a separate ticket and leave this as Unknown for now

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah ok thanks for clarifying I didn't think of those considerations for the other two connections

@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 Sep 8, 2025
@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 Sep 8, 2025
@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 Sep 8, 2025
@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 Sep 8, 2025
@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 Sep 8, 2025
@danielbotros danielbotros requested a review from cheukt September 8, 2025 15:39
Copy link
Member

@cheukt cheukt left a comment

Choose a reason for hiding this comment

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

LGTM!

@danielbotros danielbotros merged commit 2031e12 into viamrobotics:main Sep 8, 2025
18 checks passed
danielbotros added a commit to danielbotros/rdk that referenced this pull request Sep 8, 2025
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