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-8867 - Clear resources from resource collection #4398

Merged
merged 7 commits into from
Sep 27, 2024

Conversation

cheukt
Copy link
Member

@cheukt cheukt commented Sep 26, 2024

  • tested with disabling and enabling a camera and using the test card

cc @michaellee1019 @randhid

@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Sep 26, 2024
robot/web/web.go Show resolved Hide resolved
@@ -365,42 +364,43 @@ func (svc *webService) updateResources(resources map[resource.Name]resource.Reso
groupedResources[n.API] = r
}

apiRegs := resource.RegisteredAPIs()
for a, v := range groupedResources {
Copy link
Member Author

Choose a reason for hiding this comment

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

definitely a chance for some existing resources to no longer exist and not appear in this list, preventing this function from updating the collection correctly

// TODO(RSDK-144): register new service if it doesn't currently exist
// All known APIs have pre-registered resource collections, so loop through them. We want to empty out any collections if
// there are no longer resources available in that API.
for api, coll := range svc.services {
Copy link
Member Author

Choose a reason for hiding this comment

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

the logic here was messy because we allowed the possibility of having a group of resources that do not have a pre-existing resource collection. By removing that path (which was never used anyway), the logic can be generally simplified

Copy link
Member

Choose a reason for hiding this comment

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

I think I follow? Does this mean something like: a robot config hypothetically having a "fake motor" model that it's version of the rdk/viam-server is happy to create and configure. But there was no corresponding motor/server.go file that registered the "motor API" and create its corresponding "motor resource collection"?

Copy link
Member Author

Choose a reason for hiding this comment

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

yep - the case is usually for a custom api, and we're adding it to a collection that never gets used anyway

@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 26, 2024
Copy link
Member

@dgottlieb dgottlieb left a comment

Choose a reason for hiding this comment

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

Assuming my interpretations are on point, the new code looks correct/complete to me. Didn't take the time to find the bug in the old code. The new code is way*** more readable.

// TODO(RSDK-144): register new service if it doesn't currently exist
// All known APIs have pre-registered resource collections, so loop through them. We want to empty out any collections if
// there are no longer resources available in that API.
for api, coll := range svc.services {
Copy link
Member

Choose a reason for hiding this comment

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

I think I follow? Does this mean something like: a robot config hypothetically having a "fake motor" model that it's version of the rdk/viam-server is happy to create and configure. But there was no corresponding motor/server.go file that registered the "motor API" and create its corresponding "motor resource collection"?

robot/web/web.go Show resolved Hide resolved
robot/web/web.go Show resolved Hide resolved
robot/web/web.go Show resolved Hide resolved
robot/web/web.go Show resolved Hide resolved
robot/web/web.go Show resolved Hide resolved
robot/web/web.go Show resolved Hide resolved
robot/web/web.go Show resolved Hide resolved
robot/web/web.go Show resolved Hide resolved
robot/web/web.go 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 Sep 27, 2024
robot/web/web.go Show resolved Hide resolved
for n := range group {
if !n.ContainsRemoteNames() {
svc.logger.Warnw(
"missing registration for api, resources with this API will be unreachable through a client", "api", n.API)
Copy link
Member

Choose a reason for hiding this comment

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

Could you explain in what scenario we hit this log?

Copy link
Member Author

Choose a reason for hiding this comment

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

it may be possible if you added a resource without registering an api for it - I think the baseremotecontrol service for example would hit this

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.

@cheukt cheukt merged commit eec1110 into viamrobotics:main Sep 27, 2024
19 checks passed
@cheukt cheukt deleted the clear-resources-from-server branch September 27, 2024 18:58
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.

4 participants