Skip to content

Commit 89f2c7a

Browse files
Added new metatraffic attribute for entities (#126)
* Refs #12534: Added new metatraffic attribute for entities so they can be hiden/shown in FastDDS-Monitor Signed-off-by: Juan López Fernández <juanlopez@eprosima.com> * Refs #12534: Uncrustify Signed-off-by: Juan López Fernández <juanlopez@eprosima.com> * Refs #12534: Database tests fix Signed-off-by: Juan López Fernández <juanlopez@eprosima.com> * Refs #12534: StatisticsBackendTests fix Signed-off-by: Juan López Fernández <juanlopez@eprosima.com> * Refs #12534: Do not filter statistics DataWriters Signed-off-by: Juan López Fernández <juanlopez@eprosima.com> * Refs #12534: Investigating InitMonitorTests failure Signed-off-by: Juan López Fernández <juanlopez@eprosima.com> * Refs #12534: Further investigating InitMonitorTests failure Signed-off-by: Juan López Fernández <juanlopez@eprosima.com> * Print more traces for investigating InitMonitorTests failure in CI Signed-off-by: Juan López Fernández <juanlopez@eprosima.com> * Print more traces for investigating InitMonitorTests failure in CI Signed-off-by: Juan López Fernández <juanlopez@eprosima.com> * Refs #12629: Reverting investigation changes Signed-off-by: Juan López Fernández <juanlopez@eprosima.com> * Refs #12534: Included PR #126 requested changes Signed-off-by: Juan López Fernández <juanlopez@eprosima.com> * Refs #12534: uncrustify Signed-off-by: Juan López Fernández <juanlopez@eprosima.com> * Refs #12534: spell_check fix Signed-off-by: Juan López Fernández <juanlopez@eprosima.com> * Refs #12534: Added metatraffic tests Signed-off-by: Juan López Fernández <juanlopez@eprosima.com> * Refs #12534: Added more tests Signed-off-by: Juan López Fernández <juanlopez@eprosima.com> * Refs #12534: Included PR #126 more requested changes Signed-off-by: Juan López Fernández <juanlopez@eprosima.com> * Refs #12534: Fixing unsetenv/putenv Signed-off-by: Juan López Fernández <juanlopez@eprosima.com> * Refs #12534: Improved metatraffic tests Signed-off-by: Juan López Fernández <juanlopez@eprosima.com>
1 parent 8327765 commit 89f2c7a

34 files changed

+3382
-168
lines changed

docs/rst/spelling_wordlist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ datawriter
1212
destructor
1313
eProsima
1414
Gtest
15+
metatraffic
1516
monitorization
1617
monitorizations
1718
ostream

include/fastdds_statistics_backend/StatisticsBackend.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,19 @@ class FASTDDS_STATISTICS_BACKEND_DllAPI StatisticsBackend
228228
static bool is_active(
229229
EntityId entity_id);
230230

231+
/**
232+
* @brief Returns whether the entity is related to a metatraffic topic.
233+
*
234+
* For Topics, it is true when they are used for sharing metatraffic data.
235+
* For DDSEndpoints, it is true when their associated to a metatraffic Topic.
236+
* For the rest of entities, metatraffic is always false.
237+
*
238+
* @param entity_id The ID of the entity whose metatraffic attribute is requested.
239+
* @return true if metatraffic, false otherwise.
240+
*/
241+
static bool is_metatraffic(
242+
EntityId entity_id);
243+
231244
/**
232245
* @brief Returns the entity kind of a given id.
233246
*

include/fastdds_statistics_backend/types/JSONTags.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ constexpr const char* NAME_INFO_TAG = "name";
9595
constexpr const char* ALIAS_INFO_TAG = "alias";
9696
//! Key tag for alive status of an entity
9797
constexpr const char* ALIVE_INFO_TAG = "alive";
98+
//! Key tag for metatraffic attribute of an entity
99+
constexpr const char* METATRAFFIC_INFO_TAG = "metatraffic";
98100
//! Key tag for process id of a process entity
99101
constexpr const char* PID_INFO_TAG = "pid";
100102
//! Key tag for type name of a topic entity
@@ -103,8 +105,8 @@ constexpr const char* DATA_TYPE_INFO_TAG = "data_type";
103105
constexpr const char* GUID_INFO_TAG = "guid";
104106
//! Key tag for QoS of a participant, datawriter or datareader entity
105107
constexpr const char* QOS_INFO_TAG = "qos";
106-
//! Key tag for meta traffic flag of an endpoint
107-
constexpr const char* METATRAFFIC_TAG = "metatraffic";
108+
//! Key tag for meta traffic flag of a virtual endpoint
109+
constexpr const char* VIRTUAL_METATRAFFIC_TAG = "virtual_metatraffic";
108110
//! Conversion from EntityKind to string
109111
constexpr const char* entity_kind_str[] =
110112
{"invalid", HOST_ENTITY_TAG, USER_ENTITY_TAG, PROCESS_ENTITY_TAG, DOMAIN_ENTITY_TAG, TOPIC_ENTITY_TAG,

src/cpp/StatisticsBackend.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <algorithm>
2020
#include <fstream>
2121
#include <sstream>
22+
#include <stdlib.h>
2223
#include <string>
2324
#include <set>
2425

@@ -301,6 +302,13 @@ EntityId StatisticsBackend::init_monitor(
301302
CallbackMask callback_mask,
302303
DataKindMask data_mask)
303304
{
305+
/* Deactivate statistics in case they were set */
306+
#ifdef _WIN32
307+
_putenv_s("FASTDDS_STATISTICS=", "");
308+
#else
309+
unsetenv("FASTDDS_STATISTICS");
310+
#endif // ifdef _WIN32
311+
304312
/* Set domain_name */
305313
std::stringstream domain_name;
306314
domain_name << domain_id;
@@ -376,6 +384,13 @@ EntityId StatisticsBackend::init_monitor(
376384
CallbackMask callback_mask,
377385
DataKindMask data_mask)
378386
{
387+
/* Deactivate statistics in case they were set */
388+
#ifdef _WIN32
389+
_putenv_s("FASTDDS_STATISTICS=", "");
390+
#else
391+
unsetenv("FASTDDS_STATISTICS");
392+
#endif // ifdef _WIN32
393+
379394
/* Set DomainParticipantQoS */
380395
DomainParticipantQos participant_qos = DomainParticipantFactory::get_instance()->get_default_participant_qos();
381396
participant_qos.name("monitor_discovery_server_" + discovery_server_guid_prefix);
@@ -449,6 +464,12 @@ bool StatisticsBackend::is_active(
449464
return details::StatisticsBackendData::get_instance()->database_->get_entity(entity_id)->active;
450465
}
451466

467+
bool StatisticsBackend::is_metatraffic(
468+
EntityId entity_id)
469+
{
470+
return details::StatisticsBackendData::get_instance()->database_->get_entity(entity_id)->metatraffic;
471+
}
472+
452473
EntityKind StatisticsBackend::get_type(
453474
EntityId entity_id)
454475
{
@@ -468,6 +489,7 @@ Info StatisticsBackend::get_info(
468489
info[NAME_INFO_TAG] = entity->name;
469490
info[ALIAS_INFO_TAG] = entity->alias;
470491
info[ALIVE_INFO_TAG] = entity->active;
492+
info[METATRAFFIC_INFO_TAG] = entity->metatraffic;
471493

472494
switch (entity->kind)
473495
{

src/cpp/database/database.cpp

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,6 +1515,23 @@ void Database::erase(
15151515
if (participant.second->process)
15161516
{
15171517
processes_[participant.second->process->id]->participants.erase(participant.first);
1518+
bool change_status = true;
1519+
if (!processes_[participant.second->process->id]->participants.empty())
1520+
{
1521+
for (const auto& entity_it : processes_[participant.second->process->id]->participants)
1522+
{
1523+
if (entity_it.second->active)
1524+
{
1525+
change_status = false;
1526+
break;
1527+
}
1528+
}
1529+
}
1530+
if (change_status)
1531+
{
1532+
change_entity_status_of_kind(processes_[participant.second->process->id]->id, false,
1533+
EntityKind::PROCESS, domain_id);
1534+
}
15181535
}
15191536
// Erase locators_by_participant map element
15201537
locators_by_participant_.erase(participant.second->id);
@@ -2713,6 +2730,10 @@ DatabaseDump Database::dump_entity_(
27132730
entity_info[NAME_INFO_TAG] = entity->name;
27142731
entity_info[ALIAS_INFO_TAG] = entity->alias;
27152732

2733+
// metatraffic and active attributes are stored but ignored when loading
2734+
entity_info[METATRAFFIC_INFO_TAG] = entity->metatraffic;
2735+
entity_info[ALIVE_INFO_TAG] = entity->active;
2736+
27162737
// Populate subentity array
27172738
{
27182739
DatabaseDump subentities = DatabaseDump::array();
@@ -2735,6 +2756,10 @@ DatabaseDump Database::dump_entity_(
27352756

27362757
entity_info[HOST_ENTITY_TAG] = id_to_string(entity->host->id);
27372758

2759+
// metatraffic and active attributes are stored but ignored when loading
2760+
entity_info[METATRAFFIC_INFO_TAG] = entity->metatraffic;
2761+
entity_info[ALIVE_INFO_TAG] = entity->active;
2762+
27382763
// Populate subentity array
27392764
{
27402765
DatabaseDump subentities = DatabaseDump::array();
@@ -2758,6 +2783,10 @@ DatabaseDump Database::dump_entity_(
27582783

27592784
entity_info[USER_ENTITY_TAG] = id_to_string(entity->user->id);
27602785

2786+
// metatraffic and active attributes are stored but ignored when loading
2787+
entity_info[METATRAFFIC_INFO_TAG] = entity->metatraffic;
2788+
entity_info[ALIVE_INFO_TAG] = entity->active;
2789+
27612790
// Populate subentity array
27622791
{
27632792
DatabaseDump subentities = DatabaseDump::array();
@@ -2778,6 +2807,10 @@ DatabaseDump Database::dump_entity_(
27782807
entity_info[NAME_INFO_TAG] = entity->name;
27792808
entity_info[ALIAS_INFO_TAG] = entity->alias;
27802809

2810+
// metatraffic and active attributes are stored but ignored when loading
2811+
entity_info[METATRAFFIC_INFO_TAG] = entity->metatraffic;
2812+
entity_info[ALIVE_INFO_TAG] = entity->active;
2813+
27812814
// Populate subentity array for Topics
27822815
{
27832816
DatabaseDump subentities = DatabaseDump::array();
@@ -2811,6 +2844,10 @@ DatabaseDump Database::dump_entity_(
28112844

28122845
entity_info[DOMAIN_ENTITY_TAG] = id_to_string(entity->domain->id);
28132846

2847+
// metatraffic and active attributes are stored but ignored when loading
2848+
entity_info[METATRAFFIC_INFO_TAG] = entity->metatraffic;
2849+
entity_info[ALIVE_INFO_TAG] = entity->active;
2850+
28142851
// Populate subentity array for DataWriters
28152852
{
28162853
DatabaseDump subentities = DatabaseDump::array();
@@ -2844,6 +2881,11 @@ DatabaseDump Database::dump_entity_(
28442881
entity_info[QOS_INFO_TAG] = entity->qos;
28452882

28462883
entity_info[DOMAIN_ENTITY_TAG] = id_to_string(entity->domain->id);
2884+
2885+
// metatraffic and active attributes are stored but ignored when loading
2886+
entity_info[METATRAFFIC_INFO_TAG] = entity->metatraffic;
2887+
entity_info[ALIVE_INFO_TAG] = entity->active;
2888+
28472889
if (entity->process)
28482890
{
28492891
entity_info[PROCESS_ENTITY_TAG] = id_to_string(entity->process->id);
@@ -2939,7 +2981,11 @@ DatabaseDump Database::dump_entity_(
29392981

29402982
entity_info[PARTICIPANT_ENTITY_TAG] = id_to_string(entity->participant->id);
29412983
entity_info[TOPIC_ENTITY_TAG] = id_to_string(entity->topic->id);
2942-
entity_info[METATRAFFIC_TAG] = entity->is_metatraffic;
2984+
entity_info[VIRTUAL_METATRAFFIC_TAG] = entity->is_virtual_metatraffic;
2985+
2986+
// metatraffic and active attributes are stored but ignored when loading
2987+
entity_info[METATRAFFIC_INFO_TAG] = entity->metatraffic;
2988+
entity_info[ALIVE_INFO_TAG] = entity->active;
29432989

29442990
// Populate subentity array for Locators
29452991
{
@@ -3005,7 +3051,11 @@ DatabaseDump Database::dump_entity_(
30053051

30063052
entity_info[PARTICIPANT_ENTITY_TAG] = id_to_string(entity->participant->id);
30073053
entity_info[TOPIC_ENTITY_TAG] = id_to_string(entity->topic->id);
3008-
entity_info[METATRAFFIC_TAG] = entity->is_metatraffic;
3054+
entity_info[VIRTUAL_METATRAFFIC_TAG] = entity->is_virtual_metatraffic;
3055+
3056+
// metatraffic and active attributes are stored but ignored when loading
3057+
entity_info[METATRAFFIC_INFO_TAG] = entity->metatraffic;
3058+
entity_info[ALIVE_INFO_TAG] = entity->active;
30093059

30103060
// Populate subentity array for Locators
30113061
{
@@ -3049,6 +3099,10 @@ DatabaseDump Database::dump_entity_(
30493099
entity_info[NAME_INFO_TAG] = entity->name;
30503100
entity_info[ALIAS_INFO_TAG] = entity->alias;
30513101

3102+
// metatraffic and active attributes are stored but ignored when loading
3103+
entity_info[METATRAFFIC_INFO_TAG] = entity->metatraffic;
3104+
entity_info[ALIVE_INFO_TAG] = entity->active;
3105+
30523106
// Populate subentity array for DataWriters
30533107
{
30543108
DatabaseDump subentities = DatabaseDump::array();
@@ -3605,7 +3659,7 @@ void Database::load_database(
36053659
participants_[participant_domain_id][participant_id],
36063660
topics_[topic_domain_id][topic_id]);
36073661
entity->alias = (*it).at(ALIAS_INFO_TAG);
3608-
entity->is_metatraffic = (*it).at(METATRAFFIC_TAG).get<bool>();
3662+
entity->is_virtual_metatraffic = (*it).at(VIRTUAL_METATRAFFIC_TAG).get<bool>();
36093663

36103664
/* Add reference to locator to the endpoint */
36113665
for (auto it_loc = (*it).at(LOCATOR_CONTAINER_TAG).begin();
@@ -3659,7 +3713,7 @@ void Database::load_database(
36593713
participants_[participant_domain_id][participant_id],
36603714
topics_[topic_domain_id][topic_id]);
36613715
entity->alias = (*it).at(ALIAS_INFO_TAG);
3662-
entity->is_metatraffic = (*it).at(METATRAFFIC_TAG).get<bool>();
3716+
entity->is_virtual_metatraffic = (*it).at(VIRTUAL_METATRAFFIC_TAG).get<bool>();
36633717

36643718
/* Add reference to locator to the endpoint */
36653719
for (auto it_loc = (*it).at(LOCATOR_CONTAINER_TAG).begin();

src/cpp/database/database.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ class Database
521521

522522
/* Add endpoint to participant' collection */
523523
(*(endpoint->participant)).template ddsendpoints<T>()[endpoint->id] = endpoint;
524-
if (endpoint->is_metatraffic)
524+
if (endpoint->is_virtual_metatraffic)
525525
{
526526
assert(nullptr == endpoint->participant->meta_traffic_endpoint);
527527
endpoint->participant->meta_traffic_endpoint = endpoint;

src/cpp/database/entities.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,63 @@
1313
* limitations under the License.
1414
*/
1515

16+
#include <set>
17+
1618
#include "entities.hpp"
1719

1820
namespace eprosima {
1921
namespace statistics_backend {
2022
namespace database {
2123

24+
bool Entity::is_metatraffic_topic(
25+
std::string topic_name)
26+
{
27+
bool is_metatraffic = false;
28+
std::set<std::string> metatraffic_topics_keywords = {
29+
"___EPROSIMA___METATRAFFIC___",
30+
"ros_discovery_info",
31+
"rosout",
32+
"parameter_events",
33+
"get_parameters",
34+
"set_parameters",
35+
"get_parameter_types",
36+
"set_parameters_atomically",
37+
"describe_parameters",
38+
"list_parameters",
39+
"_fastdds_statistics_"};
40+
41+
std::set<std::string>::iterator it = metatraffic_topics_keywords.begin();
42+
size_t found;
43+
while (it != metatraffic_topics_keywords.end())
44+
{
45+
found = topic_name.rfind(*it);
46+
if (found != std::string::npos)
47+
{
48+
is_metatraffic = true;
49+
break;
50+
}
51+
it++;
52+
}
53+
return is_metatraffic;
54+
}
55+
56+
DDSEndpoint::DDSEndpoint(
57+
EntityKind entity_kind, /* EntityKind::INVALID */
58+
std::string endpoint_name, /* "INVALID" */
59+
Qos endpoint_qos, /* {} */
60+
std::string endpoint_guid, /* "|GUID UNKNOWN|" */
61+
std::shared_ptr<DomainParticipant> endpoint_participant, /* nullptr */
62+
std::shared_ptr<Topic> endpoint_topic /* nullptr */) noexcept
63+
: DDSEntity(entity_kind, endpoint_name, endpoint_qos, endpoint_guid)
64+
, participant(endpoint_participant)
65+
, topic(endpoint_topic)
66+
{
67+
if (topic != nullptr)
68+
{
69+
metatraffic = topic->metatraffic;
70+
}
71+
}
72+
2273
void Host::clear()
2374
{
2475
users.clear();

0 commit comments

Comments
 (0)