Skip to content

Commit

Permalink
[RSDK-9637] Add deprecation warning with date the Discover Components…
Browse files Browse the repository at this point in the history
… will be deprecated to the go SDK (#4739)

Co-authored-by: martha-johnston <[email protected]>
  • Loading branch information
randhid and martha-johnston authored Jan 24, 2025
1 parent 1e62e54 commit 2c8260e
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ require (
go.uber.org/atomic v1.11.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.27.0
go.viam.com/api v0.1.380
go.viam.com/api v0.1.383
go.viam.com/test v1.2.4
go.viam.com/utils v0.1.126
goji.io v2.0.2+incompatible
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1513,8 +1513,8 @@ go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI=
go.uber.org/zap v1.23.0/go.mod h1:D+nX8jyLsMHMYrln8A0rJjFt/T/9/bGgIhAqxv5URuY=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
go.viam.com/api v0.1.380 h1:VgRHDlPBku+kjIp4omxmPNmRVZezytFUUOFJ2xpRFR8=
go.viam.com/api v0.1.380/go.mod h1:g5eipXHNm0rQmW7DWya6avKcmzoypLmxnMlAaIsE5Ls=
go.viam.com/api v0.1.383 h1:HE9EpUWoyDBYJLTVLo29f66oCjzH31V1YJ02tlzCtyo=
go.viam.com/api v0.1.383/go.mod h1:g5eipXHNm0rQmW7DWya6avKcmzoypLmxnMlAaIsE5Ls=
go.viam.com/test v1.2.4 h1:JYgZhsuGAQ8sL9jWkziAXN9VJJiKbjoi9BsO33TW3ug=
go.viam.com/test v1.2.4/go.mod h1:zI2xzosHdqXAJ/kFqcN+OIF78kQuTV2nIhGZ8EzvaJI=
go.viam.com/utils v0.1.126 h1:ecFlzln5/u1NqzVMOVxwgwbkg4dDWvQmcCS2fMg0ZNU=
Expand Down
3 changes: 3 additions & 0 deletions module/modmanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1304,12 +1304,15 @@ func (m *module) registerResources(mgr modmaninterface.ModuleManager) {
if err != nil {
return nil, err
}

//nolint:deprecated,staticcheck
req := &robotpb.DiscoverComponentsRequest{
Queries: []*robotpb.DiscoveryQuery{
{Subtype: apiCopy.API.String(), Model: modelCopy.String(), Extra: extraStructPb},
},
}

//nolint:deprecated,staticcheck
res, err := m.robotClient.DiscoverComponents(ctx, req)
if err != nil {
m.logger.Errorf("error in modular DiscoverComponents: %s", err)
Expand Down
3 changes: 3 additions & 0 deletions module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,11 @@ func (m *Module) AddResource(ctx context.Context, req *pb.AddResourceRequest) (*
return &pb.AddResourceResponse{}, nil
}

// DiscoverComponents is DEPRECATED!!! Please use the Discovery Service instead.
// DiscoverComponents takes a list of discovery queries and returns corresponding
// component configurations.
//
//nolint:deprecated,staticcheck
func (m *Module) DiscoverComponents(
ctx context.Context,
req *robotpb.DiscoverComponentsRequest,
Expand Down
5 changes: 5 additions & 0 deletions robot/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,7 @@ func (rc *RobotClient) Logger() logging.Logger {
return rc.logger
}

// DiscoverComponents is DEPRECATED!!! Please use the Discovery Service instead.
// DiscoverComponents takes a list of discovery queries and returns corresponding
// component configurations.
//
Expand All @@ -871,7 +872,11 @@ func (rc *RobotClient) Logger() logging.Logger {
//
// // Get component configurations with these queries.
// component_configs, err := machine.DiscoverComponents(ctx.Background(), qs)
//
//nolint:deprecated,staticcheck
func (rc *RobotClient) DiscoverComponents(ctx context.Context, qs []resource.DiscoveryQuery) ([]resource.Discovery, error) {
rc.logger.Warn(
"DiscoverComponents is deprecated and will be removed on March 10th 2025. Please use the Discovery Service instead.")
pbQueries := make([]*pb.DiscoveryQuery, 0, len(qs))
for _, q := range qs {
extra, err := structpb.NewStruct(q.Extra)
Expand Down
1 change: 1 addition & 0 deletions robot/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,7 @@ func TestClientDiscovery(t *testing.T) {
injectRobot.MachineStatusFunc = func(_ context.Context) (robot.MachineStatus, error) {
return robot.MachineStatus{State: robot.StateRunning}, nil
}
injectRobot.LoggerFunc = func() logging.Logger { return logging.NewTestLogger(t) }
q := resource.DiscoveryQuery{
API: movementsensor.Named("foo").API,
Model: resource.DefaultModelFamily.WithModel("bar"),
Expand Down
5 changes: 5 additions & 0 deletions robot/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,14 @@ func (s *Server) ResourceRPCSubtypes(ctx context.Context, _ *pb.ResourceRPCSubty
return &pb.ResourceRPCSubtypesResponse{ResourceRpcSubtypes: protoTypes}, nil
}

// DiscoverComponents is DEPRECATED!!! Please use the Discovery Service instead.
// DiscoverComponents takes a list of discovery queries and returns corresponding
// component configurations.
//
//nolint:deprecated,staticcheck
func (s *Server) DiscoverComponents(ctx context.Context, req *pb.DiscoverComponentsRequest) (*pb.DiscoverComponentsResponse, error) {
s.robot.Logger().CWarn(ctx,
"DiscoverComponents is deprecated and will be removed on March 10th 2025. Please use the Discovery Service instead.")
// nonTriplet indicates older syntax for type and model E.g. "camera" instead of "rdk:component:camera"
// TODO(PRODUCT-344): remove triplet checking here after complete
var nonTriplet bool
Expand Down
2 changes: 2 additions & 0 deletions robot/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,12 @@ func TestServer(t *testing.T) {
test.That(t, resp.GetMachinePartId(), test.ShouldEqual, "the-robot-part")
})

//nolint:deprecated,staticcheck
t.Run("Discovery", func(t *testing.T) {
injectRobot := &inject.Robot{}
injectRobot.ResourceRPCAPIsFunc = func() []resource.RPCAPI { return nil }
injectRobot.ResourceNamesFunc = func() []resource.Name { return []resource.Name{} }
injectRobot.LoggerFunc = func() logging.Logger { return logging.NewTestLogger(t) }
server := server.New(injectRobot)

q := resource.DiscoveryQuery{arm.Named("arm").API, resource.DefaultModelFamily.WithModel("some-arm"), nil}
Expand Down

0 comments on commit 2c8260e

Please sign in to comment.