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-9299 - refactor get_resource_name to be a non-proto method #329

Merged
merged 4 commits into from
Nov 20, 2024

Conversation

stuqdog
Copy link
Member

@stuqdog stuqdog commented Nov 19, 2024

No description provided.

@stuqdog stuqdog requested a review from a team as a code owner November 19, 2024 16:29
@stuqdog stuqdog requested review from jckras and removed request for a team November 19, 2024 16:29
Copy link
Member

@jckras jckras left a comment

Choose a reason for hiding this comment

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

left a few questions for my own understanding but other than that looks good to me. are there any specific tests for this? also what is the reasoning for changing get_resource_name to be non-proto?

// https://bugs.llvm.org/show_bug.cgi?id=41141
//
// NOLINTNEXTLINE
boost::split(name_parts, long_name, boost::is_any_of(":"));
Copy link
Member

Choose a reason for hiding this comment

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

q: Why do we explicitly use fully qualified names like boost::split or std::something instead of bringing them into scope with using or using namespace in the code?

Copy link
Member Author

Choose a reason for hiding this comment

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

good question! I tend to like fully qualified names when they're not overly verbose. I appreciate the explicitness. And, a broader using line can add more than we need to scope and create potential for namespace collision.

Also in this case, boost::split and boost::is_any_of are only used once each in this file so using them would actually make the code (slightly) more verbose, not less.

@@ -61,6 +61,10 @@ class ClientContext {
grpc::ClientContext wrapped_context_;
};

/// @brief Given a fully qualified resource name, returns remote name (or "" if no remote name
Copy link
Member

Choose a reason for hiding this comment

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

what is a remote name and short name? and what purpose do they server as opposed to resource names?

Copy link
Member Author

Choose a reason for hiding this comment

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

a remote name is the name of a remote that the resource is part of, and the short name is just the name of the resource. so we could have remote1:my_arm as a long name, which is comprised of a remote name (remote1) and a short name my_arm).

// https://bugs.llvm.org/show_bug.cgi?id=41141
//
// NOLINTNEXTLINE
boost::split(name_parts, long_name, boost::is_any_of(":"));
Copy link
Member

Choose a reason for hiding this comment

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

is it ever possible that long_name does not contain colons? in this case remote_name will be empty and name will be the entire long_name (right?) I am not sure if this is an edge case we need to worry about but if it is, is this behavior okay?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think this is possible. A long name is of form {remote}:{short_name} (or {remote1}:...{remoteN}:{short_name}. If there's no colon then we just have a short name so we just return the name as-is, which is ideal.

*r.mutable_type() = kComponent;
return r;
Name Component::get_resource_name() const {
return Resource::get_resource_name(kComponent);
Copy link
Member

Choose a reason for hiding this comment

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

how does this function know what kComponent is? I cant seem to find it as a global variable anywhere...?

Copy link
Member Author

Choose a reason for hiding this comment

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

kComponent and kService are defined in utils.hpp, which is included in this file (and in service.cpp below).

*r.mutable_type() = kService;
return r;
Name Service::get_resource_name() const {
return Resource::get_resource_name(kService);
Copy link
Member

Choose a reason for hiding this comment

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

same as kComponent but where is kService coming from? how does the function know it exists

Copy link
Member Author

Choose a reason for hiding this comment

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

see above

@stuqdog
Copy link
Member Author

stuqdog commented Nov 20, 2024

left a few questions for my own understanding but other than that looks good to me. are there any specific tests for this? also what is the reasoning for changing get_resource_name to be non-proto?

good questions! no new tests but there are existing proto conversion tests. The reasoning is that proto types affect the ABI but we don't have control their shape, so we want to remove them from the user API as much as possible. Also, a Name is basically our custom shadow type that is easier to interact with, so we want to encourage users to use a Name instead of a proto resourcename.

boost::split(name_parts, long_name, boost::is_any_of(":"));
auto name = name_parts.back();
name_parts.pop_back();
auto remote_name = name_parts.empty()
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should be checking name_parts.empty() above before calling back(), that's UB if the container is empty and I think since this is in a public header we might want to be slightly more cautious about inputs

Also could be good to add a unit test or two

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh wait just saw your reply to Julie above, so split will return a vector with one element if there's no separator?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh wait just saw your reply to Julie above, so split will return a vector with one element if there's no separator?

Yep! I've just added a test to highlight a couple cases just to be be explicit.

@stuqdog stuqdog merged commit e331f2c into viamrobotics:main Nov 20, 2024
4 checks passed
@stuqdog stuqdog deleted the refactor-get-resource-name branch November 20, 2024 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.

3 participants