Skip to content

Conversation

@acmorrow
Copy link
Member

I'm still working through the implications of this, particularly w.r.t. to mocks and testing, but this is the general idea:

  • Move sdk/components/x/x.h to skd/components/x.h.
  • Move sdk/components/x/client.h to sdk/components/private/x_client.h.
  • Move sdk/components/x/server.h to sdk/components/private/x_server.h.
    And then adjust #include's as necessary.

After this change, the viam/sdk/components directory looks like this in the source directory:

$ ls src/viam/sdk/components
base.cpp            camera.cpp          encoder.cpp         motor.cpp           power_sensor.cpp    sensor.hpp
base.hpp            camera.hpp          encoder.hpp         motor.hpp           power_sensor.hpp    servo.cpp
board.cpp           component.cpp       generic.cpp         movement_sensor.cpp private             servo.hpp
board.hpp           component.hpp       generic.hpp         movement_sensor.hpp sensor.cpp

And like this in the installation directory (i.e.$PREFIX/include/viam/sdk/components):

$ ls build/install/include/viam/sdk/components
base.hpp            camera.hpp          encoder.hpp         motor.hpp           power_sensor.hpp    servo.hpp
board.hpp           component.hpp       generic.hpp         movement_sensor.hpp sensor.hpp

If we like this approach, I'll do the same for services. In hindsight I should have done that one first as there are fewer services than components, but oh well.

@acmorrow acmorrow requested a review from stuqdog February 16, 2024 20:33
Copy link
Member

@stuqdog stuqdog left a comment

Choose a reason for hiding this comment

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

Awesome, this looks great! Definitely a fan of the new look.

Comment on lines 8 to 9
#include <viam/sdk/components/private/camera_client.hpp>
#include <viam/sdk/components/private/camera_server.hpp>
Copy link
Member

Choose a reason for hiding this comment

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

No need to change especially if we want to keep this PR purely mechanical, but I suspect we can do away with these includes entirely (same in other mocks).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. I want to understand whether tests / mocks actually require access to the concrete FooServer and FooClient types: it would be nice if they don't, because then we can actually not only make them "header private", by not installing the headers, but we can make those types have hidden visibility so they aren't even part of the symbol table for the SDK library.

@acmorrow
Copy link
Member Author

Awesome, this looks great! Definitely a fan of the new look.

Cool! I'll get this done for services and promote this to a real review.

@acmorrow acmorrow marked this pull request as ready for review February 23, 2024 21:19
@acmorrow acmorrow requested a review from a team as a code owner February 23, 2024 21:19
@acmorrow acmorrow requested review from purplenicole730 and stuqdog and removed request for a team February 23, 2024 21:19
Copy link
Member Author

@acmorrow acmorrow left a comment

Choose a reason for hiding this comment

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

@stuqdog - Updated, now services are handled the same way. I ran into one small issue with testing in the mlmodel stuff, so at least one more update is on the way. But please give this a look. I expect given that you were happy with the components changes that you will also be fine with the services changes. The only really interesting change in this review was changing how the mock pipeline stuff worked so it doesn't need to have access to the concrete client types.

auto grpc_channel = test_server.grpc_in_process_channel(args);
ClientType resource_client(mock->name(), grpc_channel);

auto resource_client = Registry::lookup_resource_client(API::get<ClientType>())
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a non-mechanical change, so that tests no longer have a dependency on the concrete FooClient type. Instead of directly constructing ClientType, we ask the registry to do it for us, then downcast.

Potentially we should rename the ClientType template parameter?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I think ResourceType is probably better at this point.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

#include <viam/sdk/services/mlmodel/client.hpp>
#include <viam/sdk/services/mlmodel/private/proto.hpp>
#include <viam/sdk/services/mlmodel/server.hpp>
#include <viam/sdk/services/private/proto.hpp>
Copy link
Member Author

Choose a reason for hiding this comment

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

This needs some thought: this test currently tests directly some internal proto to vocab conversions. I do want to keep testing that code as it is particularly tricky. I'll give it some thought, as there will probably be other places we need something like this.

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'm not quite following what the problem is here. Since it's not being exposed in a header or non-testing code, what is the harm of having this include?

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 tests aren't part of the libviamsdk library. Eventually, the types and symbols under private won't even be exported from libviamsdk, so the tests won't be able to use them. Better to clean it up now.

Copy link
Member

Choose a reason for hiding this comment

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

Got it, thanks for clarifying.


#include <boost/test/included/unit_test.hpp>

#include <viam/api/common/v1/common.pb.h>
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 stripped lots of direct #include <viam/api where I could. There are still some in our public headers. We should strive to eliminate them all.

Copy link
Member

Choose a reason for hiding this comment

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

Just created a ticket for this.

// limitations under the License.

#include <viam/sdk/services/mlmodel/private/proto.hpp>
#include <viam/sdk/services/private/proto.hpp>
Copy link
Member Author

Choose a reason for hiding this comment

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

This file and the associated header should be renamed somehow.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, would love to see the name change here before we land this PR, proto as a name is much too generic without the more qualified path. What about mlmodel_proto_conversions? It's a little wordy, but it's specific and hidden from users.

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 renamed it to services/private/mlmodel.hpp

Copy link
Member

@stuqdog stuqdog left a comment

Choose a reason for hiding this comment

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

LGTM!

// limitations under the License.

#include <viam/sdk/services/mlmodel/private/proto.hpp>
#include <viam/sdk/services/private/proto.hpp>
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, would love to see the name change here before we land this PR, proto as a name is much too generic without the more qualified path. What about mlmodel_proto_conversions? It's a little wordy, but it's specific and hidden from users.

#include <viam/sdk/services/mlmodel/client.hpp>
#include <viam/sdk/services/mlmodel/private/proto.hpp>
#include <viam/sdk/services/mlmodel/server.hpp>
#include <viam/sdk/services/private/proto.hpp>
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'm not quite following what the problem is here. Since it's not being exposed in a header or non-testing code, what is the harm of having this include?

auto grpc_channel = test_server.grpc_in_process_channel(args);
ClientType resource_client(mock->name(), grpc_channel);

auto resource_client = Registry::lookup_resource_client(API::get<ClientType>())
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I think ResourceType is probably better at this point.


#include <boost/test/included/unit_test.hpp>

#include <viam/api/common/v1/common.pb.h>
Copy link
Member

Choose a reason for hiding this comment

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

Just created a ticket for this.

@acmorrow
Copy link
Member Author

@stuqdog - This is ready for another round of review. Changes since last time:

  • Pushed all "private" stuff into an impl namespace. I like this because it gives us a way to see at a glance in the symbols (or in source usage for that matter) if an internal type is being exported or used somehow. Happy to bikeshed a name. Ideally I'd call it private but that's a keyword of course.
  • Fixed the mlmodel tests to not use the internal "proto" functions anymore but test them indirectly by way of a mock and a client pipeline.
  • Renamed the components/private/proto headers to components/private/mlmodel and renamed the mlmodel_details namespace (which used to be public) to mlmodel inside the impl namespace.

@stuqdog
Copy link
Member

stuqdog commented Feb 26, 2024

All still looks good to me, thanks!

@acmorrow acmorrow merged commit c48fbca into viamrobotics:main Feb 26, 2024
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