Skip to content

Commit

Permalink
Empty physical entities named Unknown & set app_id/metadata from prox…
Browse files Browse the repository at this point in the history
…y info

Signed-off-by: Jesus Perez <[email protected]>
  • Loading branch information
jepemi committed Nov 2, 2023
1 parent 3e1525c commit cfac23b
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 12 deletions.
15 changes: 15 additions & 0 deletions include/fastdds_statistics_backend/types/app_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#ifndef _EPROSIMA_FASTDDS_STATISTICS_BACKEND_TYPES_APP_NAMES_HPP_
#define _EPROSIMA_FASTDDS_STATISTICS_BACKEND_TYPES_APP_NAMES_HPP_

#include <types/types.hpp>

namespace eprosima {
namespace statistics_backend {

Expand Down Expand Up @@ -53,6 +55,19 @@ constexpr const char* app_id_str[] =
{"UNKNOWN_APP", FASTDDS_MONITOR_APP, DDS_ROUTER_APP, SHAPES_DEMO_APP, INTEGRATION_SERVICE_APP, FASTDDS_VISUALIZER_APP,
FASTDDS_SPY_APP, DDS_RECORDER_APP, DDS_REPLAYER_APP, AML_IP_APP};

//! Conversion from string to AppId
const std::map<std::string, AppId> app_id_enum = {
{FASTDDS_MONITOR_APP, AppId::FASTDDS_MONITOR},
{DDS_ROUTER_APP, AppId::DDS_ROUTER},
{SHAPES_DEMO_APP, AppId::SHAPES_DEMO},
{INTEGRATION_SERVICE_APP, AppId::INTEGRATION_SERVICE},
{FASTDDS_VISUALIZER_APP, AppId::FASTDDS_VISUALIZER},
{FASTDDS_SPY_APP, AppId::FASTDDS_SPY},
{DDS_RECORDER_APP, AppId::DDS_RECORDER},
{DDS_REPLAYER_APP, AppId::DDS_REPLAYER},
{AML_IP_APP, AppId::AML_IP}
};

} //namespace statistics_backend
} //namespace eprosima

Expand Down
2 changes: 1 addition & 1 deletion src/cpp/database/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1823,7 +1823,7 @@ void Database::link_participant_with_process_nts(
else if (participant_it->second->process)
{
throw BadParameter("Participant with ID " + std::to_string(
participant_id.value()) + " in already linked with a process");
participant_id.value()) + " is already linked with a process");
}

/* Get the process */
Expand Down
24 changes: 16 additions & 8 deletions src/cpp/subscriber/StatisticsParticipantListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@ void StatisticsParticipantListener::on_participant_discovery(
discovery_info.address = get_address(info.info);
discovery_info.participant_name = info.info.m_participantName.to_string();

discovery_info.app_id = AppId::UNKNOWN;
discovery_info.app_metadata = "";

discovery_info.entity_status = StatusLevel::OK;

switch (info.status)
Expand All @@ -176,8 +173,8 @@ void StatisticsParticipantListener::on_participant_discovery(
}
}

//Get physical data from participant discovery info
auto get_physical_property_value =
//Get data from participant discovery info
auto get_property_value =
[](const fastdds::dds::ParameterPropertyList_t& properties, const std::string& property_name) -> std::string
{
auto property = std::find_if(
Expand All @@ -194,12 +191,23 @@ void StatisticsParticipantListener::on_participant_discovery(
return std::string("");
};

discovery_info.host = get_physical_property_value(info.info.m_properties,
discovery_info.host = get_property_value(info.info.m_properties,
eprosima::fastdds::dds::parameter_policy_physical_data_host);
discovery_info.user = get_physical_property_value(info.info.m_properties,
discovery_info.host = discovery_info.host.empty()? "Unknown" : discovery_info.host;

discovery_info.user = get_property_value(info.info.m_properties,
eprosima::fastdds::dds::parameter_policy_physical_data_user);
discovery_info.process = get_physical_property_value(info.info.m_properties,
discovery_info.user = discovery_info.user.empty()? "Unknown" : discovery_info.user;

discovery_info.process = get_property_value(info.info.m_properties,
eprosima::fastdds::dds::parameter_policy_physical_data_process);
discovery_info.process = discovery_info.process.empty()? "Unknown" : discovery_info.process;

std::string app_id = get_property_value(info.info.m_properties, "fastdds.application.id");
auto it = app_id_enum.find(app_id);
discovery_info.app_id = it != app_id_enum.end()? it->second : AppId::UNKNOWN;

discovery_info.app_metadata = get_property_value(info.info.m_properties, "fastdds.application.metadata");

entity_queue_->push(timestamp, discovery_info);

Expand Down
1 change: 1 addition & 0 deletions src/cpp/subscriber/StatisticsParticipantListener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <database/entities.hpp>

#include <fastdds_statistics_backend/topic_types/monitorservice_types.h>
#include <fastdds_statistics_backend/types/app_names.h>

namespace eprosima {
namespace statistics_backend {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1827,6 +1827,10 @@ TEST_F(calling_user_listeners_tests_end_to_end, entity_discovery_end_to_end)
participant_data.m_guid = participant_guid_;
participant_data.m_participantName = participant_name_;

participant_data.m_properties.push_back(eprosima::fastdds::dds::parameter_policy_physical_data_host, "host_name");
participant_data.m_properties.push_back(eprosima::fastdds::dds::parameter_policy_physical_data_user, "user_name");
participant_data.m_properties.push_back(eprosima::fastdds::dds::parameter_policy_physical_data_process, "process_name");

// The participant locator
eprosima::fastrtps::rtps::Locator_t participant_locator(LOCATOR_KIND_UDPv4, 2049);
participant_locator.address[12] = 127;
Expand All @@ -1851,7 +1855,9 @@ TEST_F(calling_user_listeners_tests_end_to_end, entity_discovery_end_to_end)
EXPECT_EQ(monitor_id_, participant->domain->id);
EXPECT_EQ(participant_guid_str_, participant->guid);
EXPECT_EQ(participant_name_, participant->name);
EXPECT_EQ(nullptr, participant->process);
EXPECT_NE(nullptr, participant->process);
EXPECT_NE(nullptr, participant->process->user);
EXPECT_NE(nullptr, participant->process->user->host);
EXPECT_TRUE(participant->data_readers.empty());
ASSERT_EQ(1u, participant->data_writers.size()); // There is the metatraffic endpoint

Expand Down
18 changes: 16 additions & 2 deletions test/unittest/StatisticsBackend/IsActiveTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,10 @@ TEST_F(is_active_tests, discover_datawriter_on_inactive_domain)
data.m_guid = participant_guid_;
data.m_participantName = participant->name;

data.m_properties.push_back(eprosima::fastdds::dds::parameter_policy_physical_data_host, host->name);
data.m_properties.push_back(eprosima::fastdds::dds::parameter_policy_physical_data_user, user->name);
data.m_properties.push_back(eprosima::fastdds::dds::parameter_policy_physical_data_process, process->name);

// Finish building the discovered reader info
eprosima::fastrtps::rtps::ParticipantDiscoveryInfo info(data);
info.status = eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::DROPPED_PARTICIPANT;
Expand Down Expand Up @@ -537,6 +541,10 @@ TEST_F(is_active_tests, discover_datawriter_on_inactive_domain)
data.m_guid = participant_guid_;
data.m_participantName = participant->name + "_1";

data.m_properties.push_back(eprosima::fastdds::dds::parameter_policy_physical_data_host, host->name);
data.m_properties.push_back(eprosima::fastdds::dds::parameter_policy_physical_data_user, user->name);
data.m_properties.push_back(eprosima::fastdds::dds::parameter_policy_physical_data_process, "process1");

// Finish building the discovered reader info
eprosima::fastrtps::rtps::ParticipantDiscoveryInfo info(data);
info.status = eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::DISCOVERED_PARTICIPANT;
Expand All @@ -548,7 +556,6 @@ TEST_F(is_active_tests, discover_datawriter_on_inactive_domain)
// Link participant - process
auto participant_id =
db->get_entity_by_guid(EntityKind::PARTICIPANT, "01.0f.00.00.00.00.00.00.00.00.00.01|0.0.1.c1").second;
db->link_participant_with_process(participant_id, process1->id);

ASSERT_TRUE(StatisticsBackendTest::is_active(host->id));
ASSERT_TRUE(StatisticsBackendTest::is_active(user->id));
Expand Down Expand Up @@ -621,6 +628,10 @@ TEST_F(is_active_tests, discover_datareader_on_inactive_domain)
std::stringstream(participant->guid) >> participant_guid_;
data.m_guid = participant_guid_;
data.m_participantName = participant->name;

data.m_properties.push_back(eprosima::fastdds::dds::parameter_policy_physical_data_host, host->name);
data.m_properties.push_back(eprosima::fastdds::dds::parameter_policy_physical_data_user, user->name);
data.m_properties.push_back(eprosima::fastdds::dds::parameter_policy_physical_data_process, process->name);

// Finish building the discovered reader info
eprosima::fastrtps::rtps::ParticipantDiscoveryInfo info(data);
Expand Down Expand Up @@ -709,6 +720,10 @@ TEST_F(is_active_tests, discover_datareader_on_inactive_domain)
std::stringstream("01.0f.00.00.00.00.00.00.00.00.00.01|0.0.1.c1") >> participant_guid_;
data.m_guid = participant_guid_;
data.m_participantName = participant->name + "_1";

data.m_properties.push_back(eprosima::fastdds::dds::parameter_policy_physical_data_host, host->name);
data.m_properties.push_back(eprosima::fastdds::dds::parameter_policy_physical_data_user, user->name);
data.m_properties.push_back(eprosima::fastdds::dds::parameter_policy_physical_data_process, "process1");

// Finish building the discovered reader info
eprosima::fastrtps::rtps::ParticipantDiscoveryInfo info(data);
Expand All @@ -721,7 +736,6 @@ TEST_F(is_active_tests, discover_datareader_on_inactive_domain)
// Link participant - process
auto participant_id =
db->get_entity_by_guid(EntityKind::PARTICIPANT, "01.0f.00.00.00.00.00.00.00.00.00.01|0.0.1.c1").second;
db->link_participant_with_process(participant_id, process1->id);

ASSERT_TRUE(StatisticsBackendTest::is_active(host->id));
ASSERT_TRUE(StatisticsBackendTest::is_active(user->id));
Expand Down

0 comments on commit cfac23b

Please sign in to comment.