Use rclcpp::NodeOptions during node construction #73
Conversation
Still need to fix some minor unit test failures. |
system_metrics_collector/src/system_metrics_collector/periodic_measurement_node.cpp
Outdated
Show resolved
Hide resolved
system_metrics_collector/src/system_metrics_collector/periodic_measurement_node.cpp
Outdated
Show resolved
Hide resolved
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.
SGTM - a few nits.
Why do we need to rename the topic? I think we can remove kTestTopic and use the real topic, no?
system_metrics_collector/src/system_metrics_collector/linux_cpu_measurement_node.hpp
Outdated
Show resolved
Hide resolved
system_metrics_collector/src/system_metrics_collector/linux_cpu_measurement_node.cpp
Outdated
Show resolved
Hide resolved
system_metrics_collector/src/system_metrics_collector/linux_memory_measurement_node.cpp
Outdated
Show resolved
Hide resolved
system_metrics_collector/src/system_metrics_collector/linux_memory_measurement_node.hpp
Outdated
Show resolved
Hide resolved
system_metrics_collector/src/system_metrics_collector/linux_process_cpu_measurement_node.cpp
Outdated
Show resolved
Hide resolved
@@ -104,7 +122,7 @@ std::string PeriodicMeasurementNode::GetStatusString() const | |||
std::stringstream ss; | |||
ss << "name=" << get_name() << | |||
", measurement_period=" << std::to_string(measurement_period_.count()) << "ms" << | |||
", publishing_topic=" << publishing_topic_ << | |||
", publishing_topic=" << ((publisher_ == nullptr) ? "" : publisher_->get_topic_name()) << |
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.
The .hpp still has publishing_topic_
. Why tie displaying the topic to the node state?
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.
If displaying the topic doesn't depend on the node state, then when the user does topic name remapping, the output is technically wrong.
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.
Could this be simplified to publisher_ ? publisher_->get_topic_name() : ""
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.
Done.
/** | ||
* The period used to publish measurement data | ||
*/ | ||
const std::chrono::milliseconds publish_period_; | ||
std::chrono::milliseconds publish_period_; |
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.
Is this used anymore?
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.
The value is coming from the parameters and stored here. Is your idea that the parameters values should be read at Start()
and not stored, so that each Stop()
->Start()
cycle might have updated/different parameter values?
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.
Sorry, this is the wrong line. I meant for line 107 (std::string publishing_topic_;
). Mainly because there is a change with the status string that does not used publishing_topic_
.
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.
Okay, I removed the publishing_topic_
member variable.
system_metrics_collector/test/system_metrics_collector/test_linux_memory_measurement.cpp
Outdated
Show resolved
Hide resolved
...trics_collector/test/system_metrics_collector/test_linux_process_memory_measurement_node.cpp
Show resolved
Hide resolved
@@ -130,8 +142,17 @@ constexpr std::chrono::milliseconds PeriodicMeasurementTestFixure::kDontPublishD | |||
|
|||
TEST_F(PeriodicMeasurementTestFixure, Sanity) { | |||
ASSERT_NE(test_periodic_measurer_, nullptr); | |||
|
|||
ASSERT_EQ("name=test_periodic_node, measurement_period=50ms," | |||
" publishing_topic=, publish_period=500ms, started=false," |
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.
An empty publishing_topic
isn't indicative of what was actually set. I'm not a fan of this change. If we want to tie it to publisher state then I would only display when started.
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.
Okay, changed this test to call Start()
on the measurement node beforehand.
I agree with this, since it seems redundant to test the ROS2 parameter code. |
I have removed the remapping of the publishing topic to |
system_metrics_collector/src/system_metrics_collector/periodic_measurement_node.cpp
Show resolved
Hide resolved
..._metrics_collector/test/system_metrics_collector/test_linux_process_cpu_measurement_node.cpp
Outdated
Show resolved
Hide resolved
system_metrics_collector/test/system_metrics_collector/test_periodic_measurement_node.cpp
Outdated
Show resolved
Hide resolved
system_metrics_collector/test/system_metrics_collector/test_periodic_measurement_node.cpp
Outdated
Show resolved
Hide resolved
@@ -68,7 +75,8 @@ bool PeriodicMeasurementNode::SetupStart() | |||
measurement_period_, [this]() {this->PerformPeriodicMeasurement();}); | |||
|
|||
if (publisher_ == nullptr) { | |||
publisher_ = create_publisher<MetricsMessage>(publishing_topic_, 10 /*history_depth*/); | |||
publisher_ = create_publisher<MetricsMessage>(collector_node_constants::kStatisticsTopicName, |
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.
Oh I see what you're doing now. Why aren't we keeping the member? This PR is actually removing functionality where we could pull the publishing topic out of NodeOptions. The work required seems minimal and I don't see why we can't do it, as a read only parameter, here.
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 PR is actually removing functionality where we could pull the publishing topic out of NodeOptions.
I was going to do that, too, but this is what @thomas-moulard suggested under on the same rationale as the node name.
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 took @thomas-moulard 's comment to mean we don't need to set and test a custom topic name in test. I'm going to follow up with him as we've discussed allowing a user to configure the topic name.
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 was discussed in the team chatroom. Topic name will be configured via remapping (--ros-args --remap system_metrics:=custom_topic_name
).
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.
--ros-args --remap
Got it, found this explanation: https://index.ros.org/doc/ros2/Tutorials/Node-arguments/#example
system_metrics_collector/src/system_metrics_collector/linux_cpu_collector.cpp
Outdated
Show resolved
Hide resolved
system_metrics_collector/src/system_metrics_collector/linux_cpu_measurement_node.hpp
Outdated
Show resolved
Hide resolved
system_metrics_collector/src/system_metrics_collector/periodic_measurement_node.cpp
Show resolved
Hide resolved
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 LGTM
@@ -25,10 +26,11 @@ namespace collector_node_constants | |||
constexpr const char kStatisticsTopicName[] = "system_metrics"; | |||
|
|||
constexpr const char kCollectPeriodParam[] = "measurement_period"; | |||
constexpr const int64_t kDefaultCollectPeriodInMs = 1000; // 1 second | |||
constexpr const std::chrono::milliseconds kDefaultCollectPeriod{1000}; // 1 second |
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.
Why is this still in milliseconds when the delay is now 1 second?
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 need to get the count()
in milliseconds at some point.
system_metrics_collector/src/system_metrics_collector/linux_cpu_measurement_node.hpp
Outdated
Show resolved
Hide resolved
system_metrics_collector/src/system_metrics_collector/linux_cpu_measurement_node.hpp
Outdated
Show resolved
Hide resolved
system_metrics_collector/test/system_metrics_collector/test_periodic_measurement_node.cpp
Outdated
Show resolved
Hide resolved
Build successful but codecov still broken. FYI @ros2/aws-oncall |
In order to support composeable nodes, the configurations for the node need to come from the
rclcpp::NodeOptions
as opposed to from C++ parameters in code.