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-8294] Use Global Connection to App in Internal Cloud Service and Local Robot #4782

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

bashar-515
Copy link
Member

@bashar-515 bashar-515 commented Feb 7, 2025

The function AcquireConnection(), is directly called in two places. This PR eliminates one of said calls by ensuring all code paths that lead to the call have their own global connection that propagates down to where the function executes to replace the call. All of these paths except for one stem from either a test or code in our examples subdirectory. In many of the tests, a nil connection is sufficient. For the few where this is not true (i.e., the ones that expect to use a connection to app--determined by the existence of a "Cloud" component within the config used to define the robot being tested), a catch-all call to AcquireConnection()is made, giving the local robot its own connection to manage. This call is marked with a comment in the code.

@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 Feb 7, 2025
@bashar-515 bashar-515 closed this Feb 12, 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 Feb 12, 2025
@bashar-515 bashar-515 reopened this Feb 12, 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 Feb 12, 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 Feb 13, 2025
@viambot viambot removed the safe to test This pull request is marked safe to test from a trusted zone label Feb 13, 2025
}

// RobotFromConfig is a helper to process a config and then create a robot based on it.
func RobotFromConfig(ctx context.Context, cfg *config.Config, logger logging.Logger, opts ...Option) (robot.LocalRobot, error) {
func RobotFromConfig(ctx context.Context, cfg *config.Config, conn rpc.ClientConn, logger logging.Logger, opts ...Option) (robot.LocalRobot, error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

There is a code path where this function might be called in a scenario where a connection to App is expected (i.e., the config might have a cloud component), so I am including the parameter here.

@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 Feb 13, 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 Feb 13, 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 Feb 13, 2025
@@ -529,7 +529,7 @@ func (s *robotServer) serveWeb(ctx context.Context, cfg *config.Config) (err err
// state of initializing until reconfigured with full config.
minimalProcessedConfig.Initial = true

myRobot, err := robotimpl.New(ctx, &minimalProcessedConfig, s.logger, robotOptions...)
myRobot, err := robotimpl.New(ctx, &minimalProcessedConfig, s.conn, s.logger, robotOptions...)
Copy link
Member Author

Choose a reason for hiding this comment

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

MAIN CODE PATH START

Copy link
Member

Choose a reason for hiding this comment

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

AHHHH

@bashar-515 bashar-515 marked this pull request as ready for review February 13, 2025 22:05
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.

Generally LGTM, just a couple comments and know you're still working on the internal cloud service piece.

Copy link
Member

Choose a reason for hiding this comment

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

Off-topic, but any context on the purpose of this example @cheukt ? Still necessary to keep around ?

@@ -434,6 +435,12 @@ func newWithResources(
r.packageManager = packages.NewDeferredPackageManager(
ctx,
func(ctx context.Context) (packagespb.PackageServiceClient, error) {
if conn != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Spoke offline, but these few lines are probably unnecessary if AcquireConnection gets the global app connection.

@@ -529,7 +529,7 @@ func (s *robotServer) serveWeb(ctx context.Context, cfg *config.Config) (err err
// state of initializing until reconfigured with full config.
minimalProcessedConfig.Initial = true

myRobot, err := robotimpl.New(ctx, &minimalProcessedConfig, s.logger, robotOptions...)
myRobot, err := robotimpl.New(ctx, &minimalProcessedConfig, s.conn, s.logger, robotOptions...)
Copy link
Member

Choose a reason for hiding this comment

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

AHHHH

@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 Feb 13, 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 Feb 13, 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 Feb 13, 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 Feb 13, 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 Feb 13, 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