-
Notifications
You must be signed in to change notification settings - Fork 18
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
Check if message's "header" field is of type std_msgs::msg::Header #54
Check if message's "header" field is of type std_msgs::msg::Header #54
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## rolling #54 +/- ##
==========================================
Coverage ? 17.36%
==========================================
Files ? 35
Lines ? 1192
Branches ? 190
==========================================
Hits ? 207
Misses ? 818
Partials ? 167
Flags with carried forward coverage won't be shown. Click here to find out more. Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
7427f67
to
4c89d1a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, thanks for the patch!
@ros2/aws-oncall - please run this CI job |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you'll need to add std_msgs
as a <test_depend>
given the CI errors.
Also when running CI for this package I would change the build arguments to:
BUILD args: --packages-up-to rclcpp
TEST args: --packages-select rclcpp
to ensure we don't break anything.
Thanks for the comment. Pushed an update with std_msgs added as <test_depend> to package.xml |
|
Not sure why it's still failing, trying to reproduce it myself. |
Likewise... It seems like a dependency issue w/ the rclcpp. May need to explicitly include std_msgs/msg/header.hpp in received_message_age.hpp, but haven't had immediate luck with that. |
FYI I'm seeing the same issue when checking out your PR. When I have bandwidth I'll try and track down the compile time issue. It seems that something may be incorrect with the header check. |
* @tparam M | ||
*/ | ||
template<typename M> | ||
struct HasHeader<M, decltype((void) M::header)>: std::true_type {}; | ||
struct HasHeader<M, typename std::enable_if<std::is_same<std_msgs::msg::Header, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You will definitely need to #include std_msgs/msg/header.hpp
in this file - any given file that is including this header will not necessarily have included it. "Include what you use".
You will probably also now need to include std_msgs
as an ament dependency of libstatistics_collector in the CMakeLists, so that other packages that consume this library have access to its headers. It was included as an exec_depend
and build_depend
in package.xml
, but is not currently mentioned in ament_target_dependencies
for libstatistics_collector
in CMakeLists.txt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that yesterday here (just pushed), but something is still missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the only problem in your attempt was that you included the C header header.h
instead of the C++ header header.hpp
, which declares the std_msgs
namespace. I just pushed commit 83486f2 to your branch and I was able to successfully colcon build --packages-up-to rclcpp
Thanks all for the assist. Went ahead and merged changes to my branch from 83486f2. |
Build looks ok but failing some tests in rcl and rclcpp. It looks like due to the fact they define Header.msg as a custom message rather than using std_msgs/Header. See: https://github.com/ros2/rclcpp/tree/master/rclcpp/test/msg This begs the question, is this implementation an incorrect check? Should the check be instead:
|
That test in The more sophisticated check is probably also fine, as it does make this functionality more flexible. |
We are essentially changing the API (expected message type then), no? https://index.ros.org/doc/ros2/Concepts/About-Topic-Statistics/#types-of-statistics-calculated I agree that a sophisticated check is good, but wonder how we can gain more input from the community for this change (e.g. are people using message timestamps and if so then how? - ROS 2 doesn't have a default header unlike ROS 1). |
I would say no - we would not be changing the API with the more sophisticated check. In fact, I think that the original attempt here changed the API whereas this new proposal would maintain it.
This would (if i understand correctly) remove the requirement for |
My misunderstanding: changing the check to
is a good proposal. |
So a lot of discussion on ABI breaks. I would already be happy if this was merged for the rolling release. So at least the next Humble release does not have this issue for the next 5 years 🙂 |
Aaaand we missed the Humble release... |
Anyone planning to pick this ticket up? It sounds like changing the logic to check for a |
…mber has type Header. Added unit test case and DummyCustomHeaderMessage for use with tests. Signed-off-by: Scott Mende Signed-off-by: scott.mende@sslmda.com <scott.mende@sslmda.com>
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
9290368
to
cf3cfe8
Compare
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
So I spent a few minutes on this. I went in, rebased this change onto the latest, and made a change so that we are at least checking whether the message contains a field called |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this change reduces the chances of a collision with custom user messages, but it doesn't really fix the bug. E.g. if this test message was updated to use a type other than builtin_interfaces/msg/Time
, then I guess we'd run into the same issue.
Explicitly checking for the message fields and types we expect, would ultimately fix the bug I think. IIUC, the code requires that the message has the following two members:
header.stamp.sec
header.stamp.nanosec
Both of which should be casted to int64_t.
Line 80 in bb824c5
const auto nanos = RCL_S_TO_NS(static_cast<int64_t>(stamp.sec)) + stamp.nanosec; |
It's probably best to check for either std_msgs/msg/Header
or builtin_interfaces/msg/Time
type to avoid any semantic errors though. We probably don't want custom user types to be accidentally picked up by libstatistics_collector.
No, there's an explicit test in here for that now (see https://github.com/ros-tooling/libstatistics_collector/pull/54/files#diff-3fc787b3bbc36449500f207e1fec489c5b2d6e7c67d86b233c54f458fb4e318c). In particular, if the field called
I don't think we want to do this, based on the earlier conversation. It adds a new transitive dependency to
That would be ideal, since rclcpp already depends on it. My metaprogramming-fu isn't good enough to figure it out, though. |
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
All right, it turns out I just needed to do some more reading on template meta-programming. I think I've got it in ca5cd77; it both checks to see if a type has I'm going to run a full-up CI on it to see what happens, but this is promising. |
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
To be complete, could we not add the same checks for |
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
Done in 929ad82.
The only way I can come up with to do this is to count the number of fields in the struct. It looks like this probably requires C++20 (https://stackoverflow.com/questions/2589861/c-template-meta-programming-number-of-member-variables). So I'd say let's leave this particular check out for now, unless someone comes up with a way to do it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes LGTM, one question about a dependency.
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
I think this change maintains ABI compatibility. If others agree, I think it is worth backporting to Humble, Galactic, and Foxy. |
Actually, this was a mistake both conceptually and in CI. Conceptually, it really doesn't matter if the header has a And this shows up in CI in an rclcpp test, because it defines a custom Header with only a stamp, which is actually enough. So I'm actually going to revert 929ad82 here, then re-run CI. |
This reverts commit 929ad82.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
With green CI and approvals, I'm going to go ahead and merge this despite the failing CI. I'll fix up the DCO problems during the squash since this PR has a complicated history. |
…uiltin_interfaces::msg::Time (ros-tooling#54) * Fix for Issue 51. Adds check to HasHeader template to check that the message in question has a field called 'header' with a subfield 'stamp' of type builtin_interfaces::msg::Time. Added unit test case and DummyCustomHeaderMessage for use with tests. Signed-off-by: scott.mende@sslmda.com <scott.mende@sslmda.com> Signed-off-by: Devin Bonnie <dbbonnie@amazon.com> Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com> Signed-off-by: Chris Lalancette <clalancette@openrobotics.org> Signed-off-by: Tim Clephas <tim.clephas@nobleo.nl>
…uiltin_interfaces::msg::Time (#54) (#153) * Fix for Issue 51. Adds check to HasHeader template to check that the message in question has a field called 'header' with a subfield 'stamp' of type builtin_interfaces::msg::Time. Added unit test case and DummyCustomHeaderMessage for use with tests. Signed-off-by: scott.mende@sslmda.com <scott.mende@sslmda.com> Signed-off-by: Devin Bonnie <dbbonnie@amazon.com> Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com> Signed-off-by: Chris Lalancette <clalancette@openrobotics.org> Signed-off-by: Tim Clephas <tim.clephas@nobleo.nl>
Resolves #51
HasHeader function in received_message_age.hpp will now check to make sure that member of name "header" is also of type std_msgs::msg::Header to return true.