Skip to content

Conversation

@stuqdog
Copy link
Member

@stuqdog stuqdog commented Oct 1, 2024

Adds support for server-side debug logging.

Note to reviewers: this PR gets us 90+% of the way to where we want to be. The problem is that a few methods (get_properties and is_moving, e.g.) do not take extra as a param. I spent some time brainstorming but I don't see a way to support adding debug logs for these without adding new params to the methods (which would be breaking). Even if we decided to break things, we'd either have to add extra to these (which would be misleading to users) or add a special field to these (which would have unclear/ambiguous utility to many implementers and would create inconsistency in our implementation that could be confusing for users). As such, I've opted to go with the "good enough" approach; we can cross this bridge if/when if a user desperately needs debug log support for these particular methods sometime in the future.

example code:

#include <viam/sdk/common/proto_type.hpp>
#include <viam/sdk/components/motor.hpp>

auto robot = connect();

auto m = robot->resource_by_name<Motor>("<my-motor-name>");
// "my-cool-key" is optional; if not provided, a random key will be created
AttributeMap with_key = debug_map("my-cool-key"); 
// alternatively if you already have a map you could call `add_debug_entry(my_map, "my-cool-key");` 
m->go_for(100, 2, with_key);

example output:
Screenshot 2024-10-01 at 11 00 10

Flybys:

  • remove some include/using invocations
  • Add extra-less, inline Arm::move_to_joint_positions

@stuqdog stuqdog requested a review from lia-viam October 1, 2024 16:48
@stuqdog stuqdog requested a review from a team as a code owner October 1, 2024 16:48
@stuqdog stuqdog requested review from purplenicole730 and removed request for a team October 1, 2024 16:48
@stuqdog
Copy link
Member Author

stuqdog commented Oct 1, 2024

@dgottlieb fyi!

@stuqdog
Copy link
Member Author

stuqdog commented Oct 1, 2024

Just noticed that the commit hash starts with 993355757. which isn't important at all but I kinda like it.

Copy link
Collaborator

@lia-viam lia-viam left a comment

Choose a reason for hiding this comment

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

Mostly minor changes, maybe we should also add a change to one of the unit tests using a peek_debug_key parameter or similar?

AttributeMap debug_map(std::string debug_key);

/// @brief Adds @param debug_key for server-side debug logging to @param map
/// @throws Exception if the debug_key contains invalid (e.g., uppercase )gRPC characters
Copy link
Collaborator

Choose a reason for hiding this comment

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

slight typo with the close paren

AttributeMap add_debug_entry(AttributeMap map, std::string debug_key);

/// @brief Adds a random key to @param map for server-side debug logging
AttributeMap add_debug_entry(AttributeMap&& map);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This and the one above should probably pass the parameter in the same way?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm maybe you can help me out here! I have an add_debug_entry that passes the param the same way above, but with just those two I get compilation errors (candidate function not viable: expects an rvalue for 1st argument). Having the "pass by value" version fixed that, though perhaps it shouldn't be exposed to users?

Copy link
Member Author

@stuqdog stuqdog Oct 7, 2024

Choose a reason for hiding this comment

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

actually nevermind! I think after I rebase with your ProtoStruct changes this issue goes away :)

edit: actually maybe not haha, we'll see!

edit edit: okay std::move okay I think we're good.


AttributeMap debug_map() {
auto debug_key = random_debug_key();
return debug_map(debug_key);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return debug_map(debug_key);
return debug_map(random_debug_key());

Copy link
Member Author

Choose a reason for hiding this comment

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

looks like this suggestion doesn't remove the debug_key variable creation so I'm modifying locally and pushing, but will make this change!

Copy link
Collaborator

Choose a reason for hiding this comment

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

oops yes haha limitation of github inline code suggestions

@stuqdog stuqdog requested a review from lia-viam October 7, 2024 14:44
@lia-viam
Copy link
Collaborator

lia-viam commented Oct 7, 2024

ok sorry for the bikeshedding but the parameter passing thing got me thinking, maybe we should rename add_debug_entry and/or add an extra overload? If I have a class Meow I would expect a function with "add" in the name to mutate it like add_entry(Meow&), rather than add_entry(Meow&&), because the latter takes Meow as a "sink" argument, which takes ownership and potentially leaves it in a a moved-from state:

Meow m;
other_function(add_something(std::move(m)); // m is now in moved-from state

I think that something like with_debug_entry might better communicate the intended fluent-style API. so we could have

void add_debug_entry(ProtoStruct&);
ProtoStruct with_debug_entry(ProtoStruct&&);

void f()
{
  ProtoStruct s1{{"cat", "meow"}};
  add_debug_entry(s1);
  component.doCommand(s1);

  component.doCommand(withDebugEntry(ProtoStruct{{"dog", "woof"}}));
}

And then I think with could be implemented in terms of add

@stuqdog
Copy link
Member Author

stuqdog commented Oct 7, 2024

@lia-viam ooh yeah I like that change, thanks! just added :)

std::vector<WorldState::transform> transforms;
ProtoStruct extra = fake_map();
std::string debug_key = "debug-key";
extra = add_debug_entry(std::move(extra), debug_key);
Copy link
Collaborator

@lia-viam lia-viam Oct 7, 2024

Choose a reason for hiding this comment

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

I think now that add_debug_entry is void this will need a change, maybe you can change the get_pose call below to be

pose_in_frame pose = client.get_pose(fake_component_name(), destination_frame, {}, with_debug_entry(fake_map(), debug_key));

and the above line deleted, then technically we'll be testing both the add and move version.

Other than that LGTM though, and feel free to merge without re-requesting review once the build passes

@stuqdog stuqdog merged commit 056edfd into viamrobotics:main Oct 7, 2024
3 checks passed
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.

2 participants