diff --git a/engine/doc/engine-doc.md b/engine/doc/engine-doc.md index dbcd93a6432..cfcd167a151 100644 --- a/engine/doc/engine-doc.md +++ b/engine/doc/engine-doc.md @@ -64,8 +64,8 @@ Engine can receive open telemetry data on a grpc server A new module is added opentelemetry It works like that: * metrics are received -* extractors tries to extract host name and service description for each data_point. On success, data_point are pushed on fifos indexed by host, service -* a service that used these datas wants to do a check. The cmd line identifies the otl_converter that will construct check result from host service data_point fifos. If converter achieves to build a result from metrics, it returns right now, if it doesn't, a handler will be called as soon as needed metrics will be available or timeout expires. +* extractors tries to extract host name and service description for each otl_data_point. On success, otl_data_point are pushed on fifos indexed by host, service +* a service that used these datas wants to do a check. The cmd line identifies the otl_check_result_builder that will construct check result from host service otl_data_point fifos. If converter achieves to build a result from metrics, it returns right now, if it doesn't, a handler will be called as soon as needed metrics will be available or timeout expires. ### open telemetry request The proto is organized like that @@ -173,14 +173,14 @@ The proto is organized like that ``` ### Concepts and classes -* data_point: data_point is the smallest unit of received request, data_point class contains data_point protobuf object and all his parents (resource, scope, metric) -* host serv extractors: When we receive otel metrics, we must extract host and service, this is his job. It can be configurable in order for example to search host name in data_point attribute or in scope. host serv extractors also contains host serv allowed. This list is updated by register_host_serv command method -* data_point fifo: a container that contains data points indexed by timestamp -* data_point fifo container: fifos indexed by host service -* otel_command: a fake connector that is used to make the link between engine and otel module +* otl_data_point: otl_data_point is the smallest unit of received request, otl_data_point class contains otl_data_point protobuf object and all his parents (resource, scope, metric) +* host serv extractors: When we receive otel metrics, we must extract host and service, this is his job. It can be configurable in order for example to search host name in otl_data_point attribute or in scope. host serv extractors also contains host serv allowed. This list is updated by register_host_serv command method +* otl_data_point fifo: a container that contains data points indexed by timestamp +* otl_data_point fifo container: fifos indexed by host service +* otel_connector: a fake connector that is used to make the link between engine and otel module * otl_server: a grpc server that accept otel collector incoming connections -* otl_converter: This short lived object is created each time engine wants to do a check. His final class as his configuration is done from the command line of the check. His job is to create a check result from data_point fifo container datas. It's destroyed when he achieved to create a check result or when timeout expires. -* host_serv_list: in order to extract host and service, an host_serv extractor must known allowed host service pairs. As otel_command may be notified of host service using it by register_host_serv method while otel module is not yet loaded. This object shared between otel_command and host_serv_extractor is actualized from otel_command::register_host_serv. +* otl_check_result_builder: This short lived object is created each time engine wants to do a check. His final class as his configuration is done from the command line of the check. His job is to create a check result from otl_data_point fifo container datas. It's destroyed when he achieved to create a check result or when timeout expires. +* host_serv_list: in order to extract host and service, an host_serv extractor must known allowed host service pairs. As otel_connector may be notified of host service using it by register_host_serv method while otel module is not yet loaded. This object shared between otel_connector and host_serv_extractor is actualized from otel_connector::register_host_serv. ### How engine access to otl object In otel_interface.hh, otel object interface are defined in engine commands namespace. @@ -188,16 +188,16 @@ Object used by both otel module and engine are inherited from these interfaces. Engine only knows a singleton of the interface open_telemetry_base. This singleton is initialized at otl module loading. ### How to configure it -We use a fake connector. When configuration is loaded, if a connector command line begins with "open_telemetry", we create an otel_command. Arguments following "open_telemetry" are used to create an host service extractor. If otel module is loaded, we create extractor, otherwise, the otel_command initialization will be done at otel module loading. +We use a fake connector. When configuration is loaded, if a connector command line begins with "open_telemetry", we create an otel_connector. Arguments following "open_telemetry" are used to create an host service extractor. If otel module is loaded, we create extractor, otherwise, the otel_connector initialization will be done at otel module loading. So user has to build one connector by host serv extractor configuration. -Then commands can use these fake connectors (class otel_command) to run checks. +Then commands can use these fake connectors (class otel_connector) to run checks. ### How a service do a check -When otel_command::run is called, it calls the check method of open_telemetry singleton. -The check method of open_telemetry object will use command line passed to run to create an otl_converter object that has to convert metrics to check result. -The open_telemetry call sync_build_result_from_metrics, if it can't achieve to build a result, otl_converter is stored in a container. -When a metric of a waiting service is received, async_build_result_from_metrics of otl_converter is called. -In open_telemetry object, a second timer is also used to call async_time_out of otl_converter on timeout expire. +When otel_connector::run is called, it calls the check method of open_telemetry singleton. +The check method of open_telemetry object will use command line passed to run to create an otl_check_result_builder object that has to convert metrics to check result. +The open_telemetry call sync_build_result_from_metrics, if it can't achieve to build a result, otl_check_result_builder is stored in a container. +When a metric of a waiting service is received, async_build_result_from_metrics of otl_check_result_builder is called. +In open_telemetry object, a second timer is also used to call async_time_out of otl_check_result_builder on timeout expire. ### other configuration other configuration parameters are stored in a dedicated json file. The path of this file is passed as argument in centengine.cfg diff --git a/engine/inc/com/centreon/engine/commands/otel_command.hh b/engine/inc/com/centreon/engine/commands/otel_connector.hh similarity index 77% rename from engine/inc/com/centreon/engine/commands/otel_command.hh rename to engine/inc/com/centreon/engine/commands/otel_connector.hh index bc566328bb8..7a21e4c4589 100644 --- a/engine/inc/com/centreon/engine/commands/otel_command.hh +++ b/engine/inc/com/centreon/engine/commands/otel_connector.hh @@ -16,8 +16,8 @@ * For more information : contact@centreon.com */ -#ifndef CCE_COMMANDS_OTEL_COMMAND_HH -#define CCE_COMMANDS_OTEL_COMMAND_HH +#ifndef CCE_COMMANDS_OTEL_CONNECTOR_HH +#define CCE_COMMANDS_OTEL_CONNECTOR_HH #include "com/centreon/engine/commands/command.hh" #include "com/centreon/engine/commands/otel_interface.hh" @@ -31,19 +31,19 @@ namespace com::centreon::engine::commands { * open telemetry request run command line configure converter who converts * data_points to result */ -class otel_command : public command, - public std::enable_shared_from_this { +class otel_connector : public command, + public std::enable_shared_from_this { otel::host_serv_list::pointer _host_serv_list; public: - using otel_command_container = - absl::flat_hash_map>; + using otel_connector_container = + absl::flat_hash_map>; private: - static otel_command_container _commands; + static otel_connector_container _commands; std::shared_ptr _extractor; - std::shared_ptr _conv_conf; + std::shared_ptr _conv_conf; std::shared_ptr _logger; @@ -59,18 +59,20 @@ class otel_command : public command, static bool update(const std::string& connector_name, const std::string& cmd_line); - static std::shared_ptr get_otel_command( + static std::shared_ptr get_otel_connector( const std::string& connector_name); static void clear(); static void init_all(); - static const otel_command_container& get_otel_commands() { return _commands; } + static const otel_connector_container& get_otel_connectors() { + return _commands; + } - otel_command(const std::string& connector_name, - const std::string& cmd_line, - commands::command_listener* listener); + otel_connector(const std::string& connector_name, + const std::string& cmd_line, + commands::command_listener* listener); void update(const std::string& cmd_line); diff --git a/engine/inc/com/centreon/engine/commands/otel_interface.hh b/engine/inc/com/centreon/engine/commands/otel_interface.hh index 8a208e6fb82..7c26706c86e 100644 --- a/engine/inc/com/centreon/engine/commands/otel_interface.hh +++ b/engine/inc/com/centreon/engine/commands/otel_interface.hh @@ -25,7 +25,7 @@ namespace com::centreon::engine::commands::otel { /** - * @brief struct returned by otl_converter::extract_host_serv_metric + * @brief struct returned by otl_check_result_builder::extract_host_serv_metric * success if host not empty * service may be empty if it's a host check * @@ -52,7 +52,7 @@ struct host_serv_metric { /** * @brief this list is the list of host service(may be empty) pairs - * This list is shared between otel_command and his extractor + * This list is shared between otel_connector and his extractor * */ class host_serv_list { @@ -64,20 +64,19 @@ class host_serv_list { void register_host_serv(const std::string& host, const std::string& service_description); - void unregister_host_serv(const std::string& host, - const std::string& service_description); + void remove(const std::string& host, const std::string& service_description); - bool is_allowed(const std::string& host, - const std::string& service_description) const; + bool contains(const std::string& host, + const std::string& service_description) const; template - host_serv_metric is_allowed(const host_set& hosts, - const service_set& services) const; + host_serv_metric match(const host_set& hosts, + const service_set& services) const; }; template -host_serv_metric host_serv_list::is_allowed(const host_set& hosts, - const service_set& services) const { +host_serv_metric host_serv_list::match(const host_set& hosts, + const service_set& services) const { host_serv_metric ret; absl::ReaderMutexLock l(&_data_m); for (const auto& host : hosts) { @@ -110,12 +109,11 @@ host_serv_metric host_serv_list::is_allowed(const host_set& hosts, class host_serv_extractor { public: virtual ~host_serv_extractor() = default; - }; -class converter_config { +class check_result_builder_config { public: - virtual ~converter_config() = default; + virtual ~check_result_builder_config() = default; }; using result_callback = std::function; @@ -141,16 +139,17 @@ class open_telemetry_base const std::string& cmdline, const host_serv_list::pointer& host_serv_list) = 0; - virtual std::shared_ptr create_converter_config( - const std::string& cmd_line) = 0; - - virtual bool check(const std::string& processed_cmd, - const std::shared_ptr& conv_conf, - uint64_t command_id, - nagios_macros& macros, - uint32_t timeout, - commands::result& res, - result_callback&& handler) = 0; + virtual std::shared_ptr + create_check_result_builder_config(const std::string& cmd_line) = 0; + + virtual bool check( + const std::string& processed_cmd, + const std::shared_ptr& conv_conf, + uint64_t command_id, + nagios_macros& macros, + uint32_t timeout, + commands::result& res, + result_callback&& handler) = 0; }; }; // namespace com::centreon::engine::commands::otel diff --git a/engine/modules/opentelemetry/CMakeLists.txt b/engine/modules/opentelemetry/CMakeLists.txt index fd65ef641d6..0146d3f81de 100644 --- a/engine/modules/opentelemetry/CMakeLists.txt +++ b/engine/modules/opentelemetry/CMakeLists.txt @@ -51,12 +51,12 @@ ${SRC_DIR}/grpc_config.cc ${SRC_DIR}/host_serv_extractor.cc ${SRC_DIR}/open_telemetry.cc ${SRC_DIR}/otl_config.cc -${SRC_DIR}/otl_converter.cc +${SRC_DIR}/otl_check_result_builder.cc ${SRC_DIR}/otl_data_point.cc ${SRC_DIR}/otl_server.cc ${SRC_DIR}/main.cc ${SRC_DIR}/telegraf/conf_server.cc -${SRC_DIR}/telegraf/nagios_converter.cc +${SRC_DIR}/telegraf/nagios_check_result_builder.cc ${SRC_DIR}/opentelemetry/proto/collector/metrics/v1/metrics_service.grpc.pb.cc ) diff --git a/engine/modules/opentelemetry/doc/opentelemetry.md b/engine/modules/opentelemetry/doc/opentelemetry.md index 0fab609effc..3ad030d9e8a 100644 --- a/engine/modules/opentelemetry/doc/opentelemetry.md +++ b/engine/modules/opentelemetry/doc/opentelemetry.md @@ -4,8 +4,8 @@ Engine can receive open telemetry data on a grpc server A new module is added opentelemetry It works like that: * metrics are received -* extractors tries to extract host name and service description for each data_point. On success, data_point are pushed on fifos indexed by host, service -* a service that used these datas wants to do a check. The cmd line identifies the otl_converter that will construct check result from host service data_point fifos. If converter achieves to build a result from metrics, it returns right now, if it doesn't, a handler will be called as soon as needed metrics will be available or timeout expires. +* extractors tries to extract host name and service description for each otl_data_point. On success, otl_data_point are pushed on fifos indexed by host, service +* a service that used these datas wants to do a check. The cmd line identifies the otl_check_result_builder that will construct check result from host service otl_data_point fifos. If converter achieves to build a result from metrics, it returns right now, if it doesn't, a handler will be called as soon as needed metrics will be available or timeout expires. ### open telemetry request The proto is organized like that @@ -113,14 +113,14 @@ The proto is organized like that ``` ### Concepts and classes -* data_point: data_point is the smallest unit of received request, data_point class contains data_point protobuf object and all his parents (resource, scope, metric) -* host serv extractors: When we receive otel metrics, we must extract host and service, this is his job. It can be configurable in order for example to search host name in data_point attribute or in scope. host serv extractors also contains host serv allowed. This list is updated by register_host_serv command method -* data_point fifo: a container that contains data points indexed by timestamp -* data_point fifo container: fifos indexed by host service -* otel_command: a fake connector that is used to make the link between engine and otel module +* otl_data_point: otl_data_point is the smallest unit of received request, otl_data_point class contains otl_data_point protobuf object and all his parents (resource, scope, metric) +* host serv extractors: When we receive otel metrics, we must extract host and service, this is his job. It can be configurable in order for example to search host name in otl_data_point attribute or in scope. host serv extractors also contains host serv allowed. This list is updated by register_host_serv command method +* otl_data_point fifo: a container that contains data points indexed by timestamp +* otl_data_point fifo container: fifos indexed by host service +* otel_connector: a fake connector that is used to make the link between engine and otel module * otl_server: a grpc server that accept otel collector incoming connections -* otl_converter: This short lived object is created each time engine wants to do a check. His final class as his configuration is done from the command line of the check. His job is to create a check result from data_point fifo container datas. It's destroyed when he achieved to create a check result or when timeout expires. -* host_serv_list: in order to extract host and service, an host_serv extractor must known allowed host service pairs. As otel_command may be notified of host service using it by register_host_serv method while otel module is not yet loaded. This object shared between otel_command and host_serv_extractor is actualized from otel_command::register_host_serv. +* otl_check_result_builder: This short lived object is created each time engine wants to do a check. His final class as his configuration is done from the command line of the check. His job is to create a check result from otl_data_point fifo container datas. It's destroyed when he achieved to create a check result or when timeout expires. +* host_serv_list: in order to extract host and service, an host_serv extractor must known allowed host service pairs. As otel_connector may be notified of host service using it by register_host_serv method while otel module is not yet loaded. This object shared between otel_connector and host_serv_extractor is actualized from otel_connector::register_host_serv. ### How engine access to otl object In otel_interface.hh, otel object interface are defined in engine commands namespace. @@ -128,16 +128,16 @@ Object used by both otel module and engine are inherited from these interfaces. Engine only knows a singleton of the interface open_telemetry_base. This singleton is initialized at otl module loading. ### How to configure it -We use a fake connector. When configuration is loaded, if a connector command line begins with "open_telemetry", we create an otel_command. Arguments following "open_telemetry" are used to create an host service extractor. If otel module is loaded, we create extractor, otherwise, the otel_command initialization will be done at otel module loading. +We use a fake connector. When configuration is loaded, if a connector command line begins with "open_telemetry", we create an otel_connector. Arguments following "open_telemetry" are used to create an host service extractor. If otel module is loaded, we create extractor, otherwise, the otel_connector initialization will be done at otel module loading. So user has to build one connector by host serv extractor configuration. -Then commands can use these fake connectors (class otel_command) to run checks. +Then commands can use these fake connectors (class otel_connector) to run checks. ### How a service do a check -When otel_command::run is called, it calls the check method of open_telemetry singleton. -The check method of open_telemetry object will use command line passed to run to create an otl_converter object that has to convert metrics to check result. -The open_telemetry call sync_build_result_from_metrics, if it can't achieve to build a result, otl_converter is stored in a container. -When a metric of a waiting service is received, async_build_result_from_metrics of otl_converter is called. -In open_telemetry object, a second timer is also used to call async_time_out of otl_converter on timeout expire. +When otel_connector::run is called, it calls the check method of open_telemetry singleton. +The check method of open_telemetry object will use command line passed to run to create an otl_check_result_builder object that has to convert metrics to check result. +The open_telemetry call sync_build_result_from_metrics, if it can't achieve to build a result, otl_check_result_builder is stored in a container. +When a metric of a waiting service is received, async_build_result_from_metrics of otl_check_result_builder is called. +In open_telemetry object, a second timer is also used to call async_time_out of otl_check_result_builder on timeout expire. ### other configuration other configuration parameters are stored in a dedicated json file. The path of this file is passed as argument in centengine.cfg diff --git a/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/data_point_fifo.hh b/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/data_point_fifo.hh index fefdab041ab..bf78b223b7b 100644 --- a/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/data_point_fifo.hh +++ b/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/data_point_fifo.hh @@ -23,7 +23,7 @@ namespace com::centreon::engine::modules::opentelemetry { /** - * @brief This class is a multiset of opentelemetry data_point ordered by + * @brief This class is a multiset of opentelemetry otl_data_point ordered by * nano_timestamp * */ @@ -36,21 +36,23 @@ class data_point_fifo { * */ using is_transparent = void; - bool operator()(const data_point& left, const data_point& right) const { + bool operator()(const otl_data_point& left, + const otl_data_point& right) const { return left.get_nano_timestamp() < right.get_nano_timestamp(); } - bool operator()(const data_point& left, + bool operator()(const otl_data_point& left, uint64_t nano_timestamp_right) const { return left.get_nano_timestamp() < nano_timestamp_right; } bool operator()(uint64_t nano_timestamp_left, - const data_point& right) const { + const otl_data_point& right) const { return nano_timestamp_left < right.get_nano_timestamp(); } }; public: - using container = absl::btree_multiset; + using container = + absl::btree_multiset; private: static time_t _second_datapoint_expiry; @@ -67,7 +69,7 @@ class data_point_fifo { size_t size() const { return _fifo.size(); } - void add_data_point(const data_point& data_pt); + void add_data_point(const otl_data_point& data_pt); void clean(); diff --git a/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/data_point_fifo_container.hh b/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/data_point_fifo_container.hh index 043417b0d6e..7406ea65648 100644 --- a/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/data_point_fifo_container.hh +++ b/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/data_point_fifo_container.hh @@ -57,7 +57,7 @@ class data_point_fifo_container { void add_data_point(const std::string_view& host, const std::string_view& service, const std::string_view& metric, - const data_point& data_pt); + const otl_data_point& data_pt); const metric_name_to_fifo& get_fifos(const std::string& host, const std::string& service) const; diff --git a/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/host_serv_extractor.hh b/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/host_serv_extractor.hh index 78ceed5b436..143c8bca621 100644 --- a/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/host_serv_extractor.hh +++ b/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/host_serv_extractor.hh @@ -50,7 +50,7 @@ class host_serv_extractor : public commands::otel::host_serv_extractor { const commands::otel::host_serv_list::pointer& host_serv_list); virtual host_serv_metric extract_host_serv_metric( - const data_point&) const = 0; + const otl_data_point&) const = 0; bool is_allowed(const std::string& host, const std::string& service_description) const; @@ -64,12 +64,12 @@ template host_serv_metric host_serv_extractor::is_allowed( const host_set& hosts, const service_set& services) const { - return _host_serv_list->is_allowed(hosts, services); + return _host_serv_list->match(hosts, services); } /** * @brief this class try to find host service in opentelemetry attributes object - * It may search in data resource attributes, scope attributes or data_point + * It may search in data resource attributes, scope attributes or otl_data_point * attributes * An example of telegraf otel data: * @code {.json} @@ -108,7 +108,7 @@ host_serv_metric host_serv_extractor::is_allowed( * */ class host_serv_attributes_extractor : public host_serv_extractor { - enum class attribute_owner { resource, scope, data_point }; + enum class attribute_owner { resource, scope, otl_data_point }; attribute_owner _host_path; std::string _host_key; attribute_owner _serv_path; @@ -120,7 +120,7 @@ class host_serv_attributes_extractor : public host_serv_extractor { const commands::otel::host_serv_list::pointer& host_serv_list); host_serv_metric extract_host_serv_metric( - const data_point& data_pt) const override; + const otl_data_point& data_pt) const override; }; } // namespace com::centreon::engine::modules::opentelemetry diff --git a/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/open_telemetry.hh b/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/open_telemetry.hh index fe3f928fdc6..b558b07c4e4 100644 --- a/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/open_telemetry.hh +++ b/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/open_telemetry.hh @@ -24,8 +24,8 @@ #include "data_point_fifo_container.hh" #include "host_serv_extractor.hh" +#include "otl_check_result_builder.hh" #include "otl_config.hh" -#include "otl_converter.hh" namespace com::centreon::engine::modules::opentelemetry { @@ -60,14 +60,15 @@ class open_telemetry : public commands::otel::open_telemetry_base { struct host_serv_getter { using result_type = host_serv; const result_type& operator()( - const std::shared_ptr& node) const { + const std::shared_ptr& node) const { return node->get_host_serv(); } }; struct time_out_getter { using result_type = std::chrono::system_clock::time_point; - result_type operator()(const std::shared_ptr& node) const { + result_type operator()( + const std::shared_ptr& node) const { return node->get_time_out(); } }; @@ -79,7 +80,7 @@ class open_telemetry : public commands::otel::open_telemetry_base { * */ using waiting_converter = boost::multi_index::multi_index_container< - std::shared_ptr, + std::shared_ptr, boost::multi_index::indexed_by< boost::multi_index::hashed_non_unique, boost::multi_index::ordered_non_unique>>; @@ -89,7 +90,7 @@ class open_telemetry : public commands::otel::open_telemetry_base { std::shared_ptr _io_context; mutable std::mutex _protect; - void _forward_to_broker(const std::vector& unknown); + void _forward_to_broker(const std::vector& unknown); void _second_timer_handler(); @@ -127,7 +128,8 @@ class open_telemetry : public commands::otel::open_telemetry_base { static void unload(const std::shared_ptr& logger); bool check(const std::string& processed_cmd, - const std::shared_ptr& conv_conf, + const std::shared_ptr& + conv_conf, uint64_t command_id, nagios_macros& macros, uint32_t timeout, @@ -138,8 +140,8 @@ class open_telemetry : public commands::otel::open_telemetry_base { const std::string& cmdline, const commands::otel::host_serv_list::pointer& host_serv_list) override; - std::shared_ptr create_converter_config( - const std::string& cmd_line) override; + std::shared_ptr + create_check_result_builder_config(const std::string& cmd_line) override; }; } // namespace com::centreon::engine::modules::opentelemetry diff --git a/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/otl_converter.hh b/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/otl_check_result_builder.hh similarity index 69% rename from engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/otl_converter.hh rename to engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/otl_check_result_builder.hh index 0152ba75ef1..2c1d3526819 100644 --- a/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/otl_converter.hh +++ b/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/otl_check_result_builder.hh @@ -16,8 +16,8 @@ ** For more information : contact@centreon.com */ -#ifndef CCE_MOD_OTL_CONVERTER_HH -#define CCE_MOD_OTL_CONVERTER_HH +#ifndef CCE_MOD_OTL_CHECK_RESULT_BUILDER_HH +#define CCE_MOD_OTL_CHECK_RESULT_BUILDER_HH #include "com/centreon/engine/commands/otel_interface.hh" #include "data_point_fifo.hh" @@ -32,15 +32,16 @@ class data_point_fifo_container; * create a converter config that will be used to create converter * */ -class converter_config : public commands::otel::converter_config { +class check_result_builder_config + : public commands::otel::check_result_builder_config { public: - enum class converter_type { nagios_converter }; + enum class converter_type { nagios_check_result_builder }; private: const converter_type _type; public: - converter_config(converter_type conv_type) : _type(conv_type) {} + check_result_builder_config(converter_type conv_type) : _type(conv_type) {} converter_type get_type() const { return _type; } }; @@ -52,7 +53,8 @@ class converter_config : public commands::otel::converter_config { * These objects are oneshot, their lifetime is the check duration * */ -class otl_converter : public std::enable_shared_from_this { +class otl_check_result_builder + : public std::enable_shared_from_this { const std::string _cmd_line; const uint64_t _command_id; const std::pair _host_serv; @@ -66,15 +68,15 @@ class otl_converter : public std::enable_shared_from_this { commands::result& res) = 0; public: - otl_converter(const std::string& cmd_line, - uint64_t command_id, - const host& host, - const service* service, - std::chrono::system_clock::time_point timeout, - commands::otel::result_callback&& handler, - const std::shared_ptr& logger); + otl_check_result_builder(const std::string& cmd_line, + uint64_t command_id, + const host& host, + const service* service, + std::chrono::system_clock::time_point timeout, + commands::otel::result_callback&& handler, + const std::shared_ptr& logger); - virtual ~otl_converter() = default; + virtual ~otl_check_result_builder() = default; const std::string& get_cmd_line() const { return _cmd_line; } @@ -101,9 +103,9 @@ class otl_converter : public std::enable_shared_from_this { virtual void dump(std::string& output) const; - static std::shared_ptr create( + static std::shared_ptr create( const std::string& cmd_line, - const std::shared_ptr& conf, + const std::shared_ptr& conf, uint64_t command_id, const host& host, const service* service, @@ -111,8 +113,8 @@ class otl_converter : public std::enable_shared_from_this { commands::otel::result_callback&& handler, const std::shared_ptr& logger); - static std::shared_ptr create_converter_config( - const std::string& cmd_line); + static std::shared_ptr + create_check_result_builder_config(const std::string& cmd_line); }; } // namespace com::centreon::engine::modules::opentelemetry @@ -120,12 +122,13 @@ class otl_converter : public std::enable_shared_from_this { namespace fmt { template <> -struct formatter +struct formatter< + com::centreon::engine::modules::opentelemetry::otl_check_result_builder> : formatter { template - auto format( - const com::centreon::engine::modules::opentelemetry::otl_converter& cont, - FormatContext& ctx) const -> decltype(ctx.out()) { + auto format(const com::centreon::engine::modules::opentelemetry:: + otl_check_result_builder& cont, + FormatContext& ctx) const -> decltype(ctx.out()) { std::string output; (&cont)->dump(output); return formatter::format(output, ctx); diff --git a/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/otl_config.hh b/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/otl_config.hh index 3d8f3d06966..16276151653 100644 --- a/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/otl_config.hh +++ b/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/otl_config.hh @@ -31,7 +31,7 @@ class otl_config { bool _json_grpc_log = false; // if true, otel object are logged in json // format instead of protobuf debug format - // this two attributes are limits used by otel data_point fifos + // this two attributes are limits used by otel otl_data_point fifos // if fifo size exceed _max_fifo_size, oldest data_points are removed // Also, data_points older than _second_fifo_expiry are removed from fifos unsigned _second_fifo_expiry; diff --git a/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/otl_data_point.hh b/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/otl_data_point.hh index 205a3acf625..1e0ca128278 100644 --- a/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/otl_data_point.hh +++ b/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/otl_data_point.hh @@ -16,8 +16,8 @@ * For more information : contact@centreon.com */ -#ifndef CCE_MOD_OTL_SERVER_METRIC_HH -#define CCE_MOD_OTL_SERVER_METRIC_HH +#ifndef CCE_MOD_OTL_DATA_POINT_HH +#define CCE_MOD_OTL_DATA_POINT_HH namespace com::centreon::engine::modules::opentelemetry { @@ -93,10 +93,10 @@ using metric_request_ptr = * This bean represents a DataPoint, it embeds all ExportMetricsServiceRequest * (_parent attribute) in order to avoid useless copies. Many attributes are * references to _parent attribute - * As we can receive several types of data_point, we tries to expose common data - * by unique getters + * As we can receive several types of otl_data_point, we tries to expose common + * data by unique getters */ -class data_point { +class otl_data_point { public: enum class data_point_type { number, @@ -117,21 +117,21 @@ class data_point { data_point_type _type; double _value; - data_point( + otl_data_point( const metric_request_ptr& parent, const ::opentelemetry::proto::resource::v1::Resource& resource, const ::opentelemetry::proto::common::v1::InstrumentationScope& scope, const ::opentelemetry::proto::metrics::v1::Metric& metric, const ::opentelemetry::proto::metrics::v1::NumberDataPoint& data_pt); - data_point( + otl_data_point( const metric_request_ptr& parent, const ::opentelemetry::proto::resource::v1::Resource& resource, const ::opentelemetry::proto::common::v1::InstrumentationScope& scope, const ::opentelemetry::proto::metrics::v1::Metric& metric, const ::opentelemetry::proto::metrics::v1::HistogramDataPoint& data_pt); - data_point( + otl_data_point( const metric_request_ptr& parent, const ::opentelemetry::proto::resource::v1::Resource& resource, const ::opentelemetry::proto::common::v1::InstrumentationScope& scope, @@ -139,7 +139,7 @@ class data_point { const ::opentelemetry::proto::metrics::v1::ExponentialHistogramDataPoint& data_pt); - data_point( + otl_data_point( const metric_request_ptr& parent, const ::opentelemetry::proto::resource::v1::Resource& resource, const ::opentelemetry::proto::common::v1::InstrumentationScope& scope, @@ -189,8 +189,8 @@ class data_point { * @param handler called on every data point found */ template -void data_point::extract_data_points(const metric_request_ptr& metrics, - data_point_handler&& handler) { +void otl_data_point::extract_data_points(const metric_request_ptr& metrics, + data_point_handler&& handler) { using namespace ::opentelemetry::proto::metrics::v1; for (const ResourceMetrics& resource_metric : metrics->resource_metrics()) { const ::opentelemetry::proto::resource::v1::Resource& resource = @@ -203,26 +203,31 @@ void data_point::extract_data_points(const metric_request_ptr& metrics, switch (pb_metric.data_case()) { case Metric::kGauge: for (const NumberDataPoint& iter : pb_metric.gauge().data_points()) - handler(data_point(metrics, resource, scope, pb_metric, iter)); + handler( + otl_data_point(metrics, resource, scope, pb_metric, iter)); break; case Metric::kSum: for (const NumberDataPoint& iter : pb_metric.sum().data_points()) - handler(data_point(metrics, resource, scope, pb_metric, iter)); + handler( + otl_data_point(metrics, resource, scope, pb_metric, iter)); break; case Metric::kHistogram: for (const HistogramDataPoint& iter : pb_metric.histogram().data_points()) - handler(data_point(metrics, resource, scope, pb_metric, iter)); + handler( + otl_data_point(metrics, resource, scope, pb_metric, iter)); break; case Metric::kExponentialHistogram: for (const ExponentialHistogramDataPoint& iter : pb_metric.exponential_histogram().data_points()) - handler(data_point(metrics, resource, scope, pb_metric, iter)); + handler( + otl_data_point(metrics, resource, scope, pb_metric, iter)); break; case Metric::kSummary: for (const SummaryDataPoint& iter : pb_metric.summary().data_points()) - handler(data_point(metrics, resource, scope, pb_metric, iter)); + handler( + otl_data_point(metrics, resource, scope, pb_metric, iter)); break; } } @@ -232,4 +237,4 @@ void data_point::extract_data_points(const metric_request_ptr& metrics, }; // namespace com::centreon::engine::modules::opentelemetry -#endif \ No newline at end of file +#endif diff --git a/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/telegraf/conf_server.hh b/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/telegraf/conf_server.hh index cc024e1d5fb..1e6a94b9f6b 100644 --- a/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/telegraf/conf_server.hh +++ b/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/telegraf/conf_server.hh @@ -79,11 +79,11 @@ class conf_session : public connection_class { bool _get_commands(const std::string& host_name, std::string& request_body); - bool _otel_command_to_stream(const std::string& cmd_name, - const std::string& cmd_line, - const std::string& host, - const std::string& service, - std::string& to_append); + bool _otel_connector_to_stream(const std::string& cmd_name, + const std::string& cmd_line, + const std::string& host, + const std::string& service, + std::string& to_append); public: using my_type = conf_session; diff --git a/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/telegraf/nagios_converter.hh b/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/telegraf/nagios_check_result_builder.hh similarity index 79% rename from engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/telegraf/nagios_converter.hh rename to engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/telegraf/nagios_check_result_builder.hh index dc3b36fcbc9..77bcd34b533 100644 --- a/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/telegraf/nagios_converter.hh +++ b/engine/modules/opentelemetry/inc/com/centreon/engine/modules/opentelemetry/telegraf/nagios_check_result_builder.hh @@ -91,26 +91,26 @@ namespace com::centreon::engine::modules::opentelemetry::telegraf { * * */ -class nagios_converter : public otl_converter { +class nagios_check_result_builder : public otl_check_result_builder { protected: bool _build_result_from_metrics(metric_name_to_fifo& fifos, commands::result& res) override; public: - nagios_converter(const std::string& cmd_line, - uint64_t command_id, - const host& host, - const service* service, - std::chrono::system_clock::time_point timeout, - commands::otel::result_callback&& handler, - const std::shared_ptr& logger) - : otl_converter(cmd_line, - command_id, - host, - service, - timeout, - std::move(handler), - logger) {} + nagios_check_result_builder(const std::string& cmd_line, + uint64_t command_id, + const host& host, + const service* service, + std::chrono::system_clock::time_point timeout, + commands::otel::result_callback&& handler, + const std::shared_ptr& logger) + : otl_check_result_builder(cmd_line, + command_id, + host, + service, + timeout, + std::move(handler), + logger) {} }; } // namespace com::centreon::engine::modules::opentelemetry::telegraf diff --git a/engine/modules/opentelemetry/src/data_point_fifo.cc b/engine/modules/opentelemetry/src/data_point_fifo.cc index 8c1827854ac..3082d0644c5 100644 --- a/engine/modules/opentelemetry/src/data_point_fifo.cc +++ b/engine/modules/opentelemetry/src/data_point_fifo.cc @@ -41,7 +41,7 @@ void data_point_fifo::update_fifo_limit(time_t second_datapoint_expiry, * * @param data_pt */ -void data_point_fifo::add_data_point(const data_point& data_pt) { +void data_point_fifo::add_data_point(const otl_data_point& data_pt) { clean(); _fifo.insert(data_pt); } diff --git a/engine/modules/opentelemetry/src/data_point_fifo_container.cc b/engine/modules/opentelemetry/src/data_point_fifo_container.cc index b2ab98dc433..112ffb271d5 100644 --- a/engine/modules/opentelemetry/src/data_point_fifo_container.cc +++ b/engine/modules/opentelemetry/src/data_point_fifo_container.cc @@ -65,12 +65,12 @@ void data_point_fifo_container::clean_empty_fifos( * @brief add a data point in the corresponding fifo * mutex must be locked during returned data use * - * @param data_pt data_point to add + * @param data_pt otl_data_point to add */ void data_point_fifo_container::add_data_point(const std::string_view& host, const std::string_view& service, const std::string_view& metric, - const data_point& data_pt) { + const otl_data_point& data_pt) { metric_name_to_fifo& fifos = _data[std::make_pair(host, service)]; auto exist = fifos.find(metric); if (exist == fifos.end()) { diff --git a/engine/modules/opentelemetry/src/host_serv_extractor.cc b/engine/modules/opentelemetry/src/host_serv_extractor.cc index 1912a84971e..bbb26cdb215 100644 --- a/engine/modules/opentelemetry/src/host_serv_extractor.cc +++ b/engine/modules/opentelemetry/src/host_serv_extractor.cc @@ -35,7 +35,7 @@ using namespace com::centreon::engine::modules::opentelemetry; bool host_serv_extractor::is_allowed( const std::string& host, const std::string& service_description) const { - return _host_serv_list->is_allowed(host, service_description); + return _host_serv_list->contains(host, service_description); } std::shared_ptr host_serv_extractor::create( @@ -77,7 +77,7 @@ std::shared_ptr host_serv_extractor::create( * * @param command_line command line that contains options used by extractor * @param host_serv_list list that will be shared bu host_serv_extractor and - * otel_command + * otel_connector */ host_serv_attributes_extractor::host_serv_attributes_extractor( const std::string& command_line, @@ -113,7 +113,7 @@ host_serv_attributes_extractor::host_serv_attributes_extractor( } else if (sz_attr == "scope") { attr = attribute_owner::scope; } else { - attr = attribute_owner::data_point; + attr = attribute_owner::otl_data_point; } }; @@ -125,13 +125,13 @@ host_serv_attributes_extractor::host_serv_attributes_extractor( .run(), vm); if (!vm.count("host_path")) { - _host_path = attribute_owner::data_point; + _host_path = attribute_owner::otl_data_point; _host_key = "host"; } else { parse_path(vm["host_path"].as(), _host_path, _host_key); } if (!vm.count("service_path")) { - _serv_path = attribute_owner::data_point; + _serv_path = attribute_owner::otl_data_point; _serv_key = "service"; } else { parse_path(vm["service_path"].as(), _serv_path, _serv_key); @@ -154,15 +154,15 @@ host_serv_attributes_extractor::host_serv_attributes_extractor( * found */ host_serv_metric host_serv_attributes_extractor::extract_host_serv_metric( - const data_point& data_pt) const { + const otl_data_point& data_pt) const { auto extract = - [](const data_point& data_pt, attribute_owner owner, + [](const otl_data_point& data_pt, attribute_owner owner, const std::string& key) -> absl::flat_hash_set { absl::flat_hash_set ret; const ::google::protobuf::RepeatedPtrField< ::opentelemetry::proto::common::v1::KeyValue>* attributes = nullptr; switch (owner) { - case attribute_owner::data_point: + case attribute_owner::otl_data_point: attributes = &data_pt.get_data_point_attributes(); break; case attribute_owner::scope: diff --git a/engine/modules/opentelemetry/src/main.cc b/engine/modules/opentelemetry/src/main.cc index abd6d08cfc5..54a63103f57 100644 --- a/engine/modules/opentelemetry/src/main.cc +++ b/engine/modules/opentelemetry/src/main.cc @@ -16,7 +16,7 @@ * For more information : contact@centreon.com */ -#include "com/centreon/engine/commands/otel_command.hh" +#include "com/centreon/engine/commands/otel_connector.hh" #include "com/centreon/engine/nebmods.hh" #include "com/centreon/engine/nebmodules.hh" #include "com/centreon/exceptions/msg_fmt.hh" @@ -108,7 +108,7 @@ extern "C" int nebmodule_init(int flags, char const* args, void* handle) { open_telemetry::load(conf_file_path, g_io_context, log_v2::instance().get(log_v2::OTEL)); - commands::otel_command::init_all(); + commands::otel_connector::init_all(); return 0; } diff --git a/engine/modules/opentelemetry/src/open_telemetry.cc b/engine/modules/opentelemetry/src/open_telemetry.cc index 478564393bd..34da5d8fbf8 100644 --- a/engine/modules/opentelemetry/src/open_telemetry.cc +++ b/engine/modules/opentelemetry/src/open_telemetry.cc @@ -218,7 +218,7 @@ void open_telemetry::_shutdown() { * @param cmdline which begins with name of extractor, following parameters * are used by extractor * @param host_serv_list list that will be shared bu host_serv_extractor and - * otel_command + * otel_connector * @return * std::shared_ptr * @throw if extractor type is unknown @@ -264,16 +264,19 @@ open_telemetry::create_extractor( /** * @brief converter is created for each check, so in order to not parse otel - * connector command line on each check , we create a converter_config - * object that is used to create converter it search the flag extractor + * connector command line on each check , we create a + * check_result_builder_config object that is used to create converter it search + * the flag extractor * * @param cmd_line * @return - * std::shared_ptr + * std::shared_ptr */ -std::shared_ptr -open_telemetry::create_converter_config(const std::string& cmd_line) { - return otl_converter::create_converter_config(cmd_line); +std::shared_ptr< + com::centreon::engine::commands::otel::check_result_builder_config> +open_telemetry::create_check_result_builder_config( + const std::string& cmd_line) { + return otl_check_result_builder::create_check_result_builder_config(cmd_line); } /** @@ -295,16 +298,18 @@ open_telemetry::create_converter_config(const std::string& cmd_line) { */ bool open_telemetry::check( const std::string& processed_cmd, - const std::shared_ptr& conv_config, + const std::shared_ptr& + conv_config, uint64_t command_id, nagios_macros& macros, uint32_t timeout, commands::result& res, commands::otel::result_callback&& handler) { - std::shared_ptr to_use; + std::shared_ptr to_use; try { - to_use = otl_converter::create( - processed_cmd, std::static_pointer_cast(conv_config), + to_use = otl_check_result_builder::create( + processed_cmd, + std::static_pointer_cast(conv_config), command_id, *macros.host_ptr, macros.service_ptr, std::chrono::system_clock::now() + std::chrono::seconds(timeout), std::move(handler), _logger); @@ -335,61 +340,63 @@ bool open_telemetry::check( /** * @brief called on metric reception - * we first fill data_point fifos and then if a converter of a service is - * waiting for data_point, we call him. If it achieve to generate a check - * result, the handler of otl_converter is called + * we first fill otl_data_point fifos and then if a converter of a service is + * waiting for otl_data_point, we call him. If it achieve to generate a check + * result, the handler of otl_check_result_builder is called * unknown metrics are passed to _forward_to_broker * * @param metrics collector request */ void open_telemetry::_on_metric(const metric_request_ptr& metrics) { - std::vector unknown; + std::vector unknown; { std::lock_guard l(_protect); if (_extractors.empty()) { // no extractor configured => all unknown - data_point::extract_data_points(metrics, - [&unknown](const data_point& data_pt) { - unknown.push_back(data_pt); - }); + otl_data_point::extract_data_points( + metrics, [&unknown](const otl_data_point& data_pt) { + unknown.push_back(data_pt); + }); } else { waiting_converter::nth_index<0>::type& host_serv_index = _waiting.get<0>(); - std::vector> to_notify; + std::vector> to_notify; auto last_success = _extractors.begin(); - data_point::extract_data_points(metrics, [this, &unknown, &last_success, - &host_serv_index, &to_notify]( - const data_point& data_pt) { - bool data_point_known = false; - // we try all extractors and we begin with the last which has - // achieved to extract host - for (unsigned tries = 0; tries < _extractors.size(); ++tries) { - host_serv_metric hostservmetric = - last_success->second->extract_host_serv_metric(data_pt); - - if (!hostservmetric.host.empty()) { // match - _fifo.add_data_point(hostservmetric.host, hostservmetric.service, - hostservmetric.metric, data_pt); - - // converters waiting this metric? - auto waiting = host_serv_index.equal_range( - host_serv{hostservmetric.host, hostservmetric.service}); - while (waiting.first != waiting.second) { - to_notify.push_back(*waiting.first); - waiting.first = host_serv_index.erase(waiting.first); + otl_data_point::extract_data_points( + metrics, [this, &unknown, &last_success, &host_serv_index, + &to_notify](const otl_data_point& data_pt) { + bool data_point_known = false; + // we try all extractors and we begin with the last which has + // achieved to extract host + for (unsigned tries = 0; tries < _extractors.size(); ++tries) { + host_serv_metric hostservmetric = + last_success->second->extract_host_serv_metric(data_pt); + + if (!hostservmetric.host.empty()) { // match + _fifo.add_data_point(hostservmetric.host, + hostservmetric.service, + hostservmetric.metric, data_pt); + + // converters waiting this metric? + auto waiting = host_serv_index.equal_range( + host_serv{hostservmetric.host, hostservmetric.service}); + while (waiting.first != waiting.second) { + to_notify.push_back(*waiting.first); + waiting.first = host_serv_index.erase(waiting.first); + } + data_point_known = true; + break; + } + // no match => we try next extractor + ++last_success; + if (last_success == _extractors.end()) { + last_success = _extractors.begin(); + } } - data_point_known = true; - break; - } - // no match => we try next extractor - ++last_success; - if (last_success == _extractors.end()) { - last_success = _extractors.begin(); - } - } - if (!data_point_known) { - unknown.push_back(data_pt); // unknown metric => forward to broker - } - }); + if (!data_point_known) { + unknown.push_back( + data_pt); // unknown metric => forward to broker + } + }); SPDLOG_LOGGER_TRACE(_logger, "fifos:{}", _fifo); // we wait that all request datas have been computed to give us more // chance of converter success @@ -428,7 +435,7 @@ void open_telemetry::_start_second_timer() { * */ void open_telemetry::_second_timer_handler() { - std::vector> to_notify; + std::vector> to_notify; { std::lock_guard l(_protect); std::chrono::system_clock::time_point now = @@ -445,7 +452,7 @@ void open_telemetry::_second_timer_handler() { } // notify all timeout - for (std::shared_ptr to_not : to_notify) { + for (std::shared_ptr to_not : to_notify) { SPDLOG_LOGGER_DEBUG(_logger, "time out: {}", *to_not); to_not->async_time_out(); } @@ -459,4 +466,4 @@ void open_telemetry::_second_timer_handler() { * @param unknown */ void open_telemetry::_forward_to_broker( - const std::vector& unknown) {} + const std::vector& unknown) {} diff --git a/engine/modules/opentelemetry/src/otl_converter.cc b/engine/modules/opentelemetry/src/otl_check_result_builder.cc similarity index 66% rename from engine/modules/opentelemetry/src/otl_converter.cc rename to engine/modules/opentelemetry/src/otl_check_result_builder.cc index 9f45e962b12..e1f75423fee 100644 --- a/engine/modules/opentelemetry/src/otl_converter.cc +++ b/engine/modules/opentelemetry/src/otl_check_result_builder.cc @@ -20,21 +20,34 @@ #include "com/centreon/exceptions/msg_fmt.hh" #include "data_point_fifo_container.hh" -#include "otl_converter.hh" -#include "telegraf/nagios_converter.hh" +#include "otl_check_result_builder.hh" +#include "telegraf/nagios_check_result_builder.hh" #include "absl/flags/commandlineflag.h" #include "absl/strings/str_split.h" using namespace com::centreon::engine::modules::opentelemetry; -otl_converter::otl_converter(const std::string& cmd_line, - uint64_t command_id, - const host& host, - const service* service, - std::chrono::system_clock::time_point timeout, - commands::otel::result_callback&& handler, - const std::shared_ptr& logger) +/** + * @brief Construct a new otl check result builder::otl check result builder + * object + * + * @param cmd_line + * @param command_id + * @param host + * @param service + * @param timeout + * @param handler called when mandatory metrics will be available + * @param logger + */ +otl_check_result_builder::otl_check_result_builder( + const std::string& cmd_line, + uint64_t command_id, + const host& host, + const service* service, + std::chrono::system_clock::time_point timeout, + commands::otel::result_callback&& handler, + const std::shared_ptr& logger) : _cmd_line(cmd_line), _command_id(command_id), _host_serv{host.name(), service ? service->description() : ""}, @@ -42,7 +55,15 @@ otl_converter::otl_converter(const std::string& cmd_line, _callback(handler), _logger(logger) {} -bool otl_converter::sync_build_result_from_metrics( +/** + * @brief try to build a check result + * + * @param data_pts + * @param res + * @return true all mandatory metrics are available and a check_result is built + * @return false + */ +bool otl_check_result_builder::sync_build_result_from_metrics( data_point_fifo_container& data_pts, commands::result& res) { std::lock_guard l(data_pts); @@ -59,10 +80,10 @@ bool otl_converter::sync_build_result_from_metrics( * clients * * @param data_pts - * @return true otl_converter has managed to create check result + * @return true otl_check_result_builder has managed to create check result * @return false */ -bool otl_converter::async_build_result_from_metrics( +bool otl_check_result_builder::async_build_result_from_metrics( data_point_fifo_container& data_pts) { commands::result res; bool success = false; @@ -82,7 +103,7 @@ bool otl_converter::async_build_result_from_metrics( * _timeout * */ -void otl_converter::async_time_out() { +void otl_check_result_builder::async_time_out() { commands::result res; res.exit_status = process::timeout; res.command_id = _command_id; @@ -94,24 +115,26 @@ void otl_converter::async_time_out() { * first field identify type of config * Example: * @code {.c++} - * std::shared_ptr converter = - * otl_converter::create("--processor=nagios_telegraf --fifo_depth=5", conf, 5, *host, serv, - * timeout_point, [](const commads::result &res){}, _logger); + * std::shared_ptr converter = + * otl_check_result_builder::create("--processor=nagios_telegraf + * --fifo_depth=5", conf, 5, *host, serv, timeout_point, [](const + * commads::result &res){}, _logger); * @endcode * * @param cmd_line - * @param conf bean configuration object created by create_converter_config + * @param conf bean configuration object created by + * create_check_result_builder_config * @param command_id * @param host * @param service * @param timeout * @param handler handler that will be called once we have all metrics mandatory * to create a check_result - * @return std::shared_ptr + * @return std::shared_ptr */ -std::shared_ptr otl_converter::create( +std::shared_ptr otl_check_result_builder::create( const std::string& cmd_line, - const std::shared_ptr& conf, + const std::shared_ptr& conf, uint64_t command_id, const host& host, const service* service, @@ -119,8 +142,9 @@ std::shared_ptr otl_converter::create( commands::otel::result_callback&& handler, const std::shared_ptr& logger) { switch (conf->get_type()) { - case converter_config::converter_type::nagios_converter: - return std::make_shared( + case check_result_builder_config::converter_type:: + nagios_check_result_builder: + return std::make_shared( cmd_line, command_id, host, service, timeout, std::move(handler), logger); default: @@ -134,7 +158,7 @@ std::shared_ptr otl_converter::create( * * @param output string to log */ -void otl_converter::dump(std::string& output) const { +void otl_check_result_builder::dump(std::string& output) const { output = fmt::format( "host:{}, service:{}, command_id={}, timeout:{} cmdline: \"{}\"", _host_serv.first, _host_serv.second, _command_id, _timeout, _cmd_line); @@ -146,13 +170,14 @@ void otl_converter::dump(std::string& output) const { * Example: * @code {.c++} * std::shared_ptr converter = - * otl_converter::create("--processor=nagios_telegraf --fifo_depth=5"); - * @endcode + * otl_converter::create_check_result_builder_config("--processor=nagios_telegraf + * --fifo_depth=5"); * * @param cmd_line - * @return std::shared_ptr + * @return std::shared_ptr */ -std::shared_ptr otl_converter::create_converter_config( +std::shared_ptr +otl_check_result_builder::create_check_result_builder_config( const std::string& cmd_line) { static initialized_data_class desc( [](po::options_description& desc) { @@ -172,8 +197,9 @@ std::shared_ptr otl_converter::create_converter_config( } std::string extractor_type = vm["processor"].as(); if (extractor_type == "nagios_telegraf") { - return std::make_shared( - converter_config::converter_type::nagios_converter); + return std::make_shared( + check_result_builder_config::converter_type:: + nagios_check_result_builder); } else { throw exceptions::msg_fmt("unknown processor in {}", cmd_line); } diff --git a/engine/modules/opentelemetry/src/otl_data_point.cc b/engine/modules/opentelemetry/src/otl_data_point.cc index 0b7811b6fe1..515244c92a9 100644 --- a/engine/modules/opentelemetry/src/otl_data_point.cc +++ b/engine/modules/opentelemetry/src/otl_data_point.cc @@ -21,7 +21,7 @@ using namespace com::centreon::engine::modules::opentelemetry; using namespace ::opentelemetry::proto::metrics::v1; -data_point::data_point( +otl_data_point::otl_data_point( const metric_request_ptr& parent, const ::opentelemetry::proto::resource::v1::Resource& resource, const ::opentelemetry::proto::common::v1::InstrumentationScope& scope, @@ -38,7 +38,7 @@ data_point::data_point( _value = data_pt.as_double() ? data_pt.as_double() : data_pt.as_int(); } -data_point::data_point( +otl_data_point::otl_data_point( const metric_request_ptr& parent, const ::opentelemetry::proto::resource::v1::Resource& resource, const ::opentelemetry::proto::common::v1::InstrumentationScope& scope, @@ -55,7 +55,7 @@ data_point::data_point( _value = data_pt.count(); } -data_point::data_point( +otl_data_point::otl_data_point( const metric_request_ptr& parent, const ::opentelemetry::proto::resource::v1::Resource& resource, const ::opentelemetry::proto::common::v1::InstrumentationScope& scope, @@ -73,7 +73,7 @@ data_point::data_point( _value = data_pt.count(); } -data_point::data_point( +otl_data_point::otl_data_point( const metric_request_ptr& parent, const ::opentelemetry::proto::resource::v1::Resource& resource, const ::opentelemetry::proto::common::v1::InstrumentationScope& scope, diff --git a/engine/modules/opentelemetry/src/telegraf/conf_server.cc b/engine/modules/opentelemetry/src/telegraf/conf_server.cc index 48646b4b1ee..b7b53fa2ec8 100644 --- a/engine/modules/opentelemetry/src/telegraf/conf_server.cc +++ b/engine/modules/opentelemetry/src/telegraf/conf_server.cc @@ -270,7 +270,7 @@ void conf_session::on_receive_request( * @return false */ template -bool conf_session::_otel_command_to_stream( +bool conf_session::_otel_connector_to_stream( const std::string& cmd_name, const std::string& cmd_line, const std::string& host, @@ -341,9 +341,9 @@ bool conf_session::_get_commands(const std::string& host_name, if (use_otl_command(*hst)) { nagios_macros* macros(get_global_macros()); - ret |= _otel_command_to_stream(hst->check_command(), - hst->get_check_command_line(macros), - hst->name(), "", request_body); + ret |= _otel_connector_to_stream(hst->check_command(), + hst->get_check_command_line(macros), + hst->name(), "", request_body); clear_volatile_macros_r(macros); } else { SPDLOG_LOGGER_DEBUG(this->_logger, @@ -359,7 +359,7 @@ bool conf_session::_get_commands(const std::string& host_name, std::shared_ptr serv = serv_iter->second; if (use_otl_command(*serv)) { nagios_macros* macros(get_global_macros()); - ret |= _otel_command_to_stream( + ret |= _otel_connector_to_stream( serv->check_command(), serv->get_check_command_line(macros), serv->get_hostname(), serv->name(), request_body); clear_volatile_macros_r(macros); diff --git a/engine/modules/opentelemetry/src/telegraf/nagios_converter.cc b/engine/modules/opentelemetry/src/telegraf/nagios_check_result_builder.cc similarity index 97% rename from engine/modules/opentelemetry/src/telegraf/nagios_converter.cc rename to engine/modules/opentelemetry/src/telegraf/nagios_check_result_builder.cc index 1078ee3e8e3..7c96fb57d25 100644 --- a/engine/modules/opentelemetry/src/telegraf/nagios_converter.cc +++ b/engine/modules/opentelemetry/src/telegraf/nagios_check_result_builder.cc @@ -17,9 +17,9 @@ */ #include "data_point_fifo_container.hh" -#include "otl_converter.hh" +#include "otl_check_result_builder.hh" -#include "telegraf/nagios_converter.hh" +#include "telegraf/nagios_check_result_builder.hh" using namespace com::centreon::engine::modules::opentelemetry::telegraf; @@ -158,8 +158,9 @@ static std::string_view get_nagios_telegraf_suffix( * check_icmp_state * @return com::centreon::engine::commands::result */ -bool nagios_converter::_build_result_from_metrics(metric_name_to_fifo& fifos, - commands::result& res) { +bool nagios_check_result_builder::_build_result_from_metrics( + metric_name_to_fifo& fifos, + commands::result& res) { // first we search last state timestamp uint64_t last_time = 0; diff --git a/engine/src/commands/CMakeLists.txt b/engine/src/commands/CMakeLists.txt index 1ac102e9129..1c094f5c580 100644 --- a/engine/src/commands/CMakeLists.txt +++ b/engine/src/commands/CMakeLists.txt @@ -31,7 +31,7 @@ set( "${SRC_DIR}/connector.cc" "${SRC_DIR}/environment.cc" "${SRC_DIR}/forward.cc" - "${SRC_DIR}/otel_command.cc" + "${SRC_DIR}/otel_connector.cc" "${SRC_DIR}/otel_interface.cc" "${SRC_DIR}/processing.cc" "${SRC_DIR}/raw.cc" diff --git a/engine/src/commands/otel_command.cc b/engine/src/commands/otel_connector.cc similarity index 73% rename from engine/src/commands/otel_command.cc rename to engine/src/commands/otel_connector.cc index bab48809b64..44538b01e0f 100644 --- a/engine/src/commands/otel_command.cc +++ b/engine/src/commands/otel_connector.cc @@ -16,7 +16,7 @@ * For more information : contact@centreon.com */ -#include "com/centreon/engine/commands/otel_command.hh" +#include "com/centreon/engine/commands/otel_connector.hh" #include "com/centreon/exceptions/msg_fmt.hh" #include "common/log_v2/log_v2.hh" @@ -24,24 +24,24 @@ using namespace com::centreon::engine::commands; using log_v2 = com::centreon::common::log_v2::log_v2; /** - * @brief static list of all otel_command + * @brief static list of all otel_connector * */ -absl::flat_hash_map> - otel_command::_commands; +absl::flat_hash_map> + otel_connector::_commands; /** - * @brief create an otel_command + * @brief create an otel_connector * * @param connector_name * @param cmd_line * @param listener */ -void otel_command::create(const std::string& connector_name, - const std::string& cmd_line, - commands::command_listener* listener) { - std::shared_ptr cmd( - std::make_shared(connector_name, cmd_line, listener)); +void otel_connector::create(const std::string& connector_name, + const std::string& cmd_line, + commands::command_listener* listener) { + std::shared_ptr cmd( + std::make_shared(connector_name, cmd_line, listener)); auto iter_res = _commands.emplace(connector_name, cmd); if (!iter_res.second) { iter_res.first->second = cmd; @@ -55,7 +55,7 @@ void otel_command::create(const std::string& connector_name, * @return true * @return false */ -bool otel_command::remove(const std::string& connector_name) { +bool otel_connector::remove(const std::string& connector_name) { return _commands.erase(connector_name); } @@ -67,8 +67,8 @@ bool otel_command::remove(const std::string& connector_name) { * @return true the otel command was found and hist update method was called * @return false the otel command doesn't exist */ -bool otel_command::update(const std::string& connector_name, - const std::string& cmd_line) { +bool otel_connector::update(const std::string& connector_name, + const std::string& cmd_line) { auto search = _commands.find(connector_name); if (search == _commands.end()) { return false; @@ -81,20 +81,20 @@ bool otel_command::update(const std::string& connector_name, * @brief get otel command from connector name * * @param connector_name - * @return std::shared_ptr + * @return std::shared_ptr */ -std::shared_ptr otel_command::get_otel_command( +std::shared_ptr otel_connector::get_otel_connector( const std::string& connector_name) { auto search = _commands.find(connector_name); return search != _commands.end() ? search->second - : std::shared_ptr(); + : std::shared_ptr(); } /** * @brief erase all otel commands * */ -void otel_command::clear() { +void otel_connector::clear() { _commands.clear(); } @@ -102,7 +102,7 @@ void otel_command::clear() { * @brief to call once otel module have been loaded * */ -void otel_command::init_all() { +void otel_connector::init_all() { for (auto& to_init : _commands) { to_init.second->init(); } @@ -117,9 +117,9 @@ void otel_command::init_all() { * @param cmd_line * @param listener */ -otel_command::otel_command(const std::string& connector_name, - const std::string& cmd_line, - commands::command_listener* listener) +otel_connector::otel_connector(const std::string& connector_name, + const std::string& cmd_line, + commands::command_listener* listener) : command(connector_name, cmd_line, listener, e_type::otel), _host_serv_list(std::make_shared()), _logger(log_v2::instance().get(log_v2::OTEL)) { @@ -131,7 +131,7 @@ otel_command::otel_command(const std::string& connector_name, * * @param cmd_line */ -void otel_command::update(const std::string& cmd_line) { +void otel_connector::update(const std::string& cmd_line) { if (get_command_line() == cmd_line) { return; } @@ -150,11 +150,11 @@ void otel_command::update(const std::string& cmd_line) { * @param caller * @return uint64_t */ -uint64_t otel_command::run(const std::string& processed_cmd, - nagios_macros& macros, - uint32_t timeout, - const check_result::pointer& to_push_to_checker, - const void* caller) { +uint64_t otel_connector::run(const std::string& processed_cmd, + nagios_macros& macros, + uint32_t timeout, + const check_result::pointer& to_push_to_checker, + const void* caller) { std::shared_ptr otel = otel::open_telemetry_base::instance(); @@ -180,17 +180,18 @@ uint64_t otel_command::run(const std::string& processed_cmd, "{} unable to do a check without a converter configuration", get_name()); } - SPDLOG_LOGGER_TRACE(_logger, - "otel_command::async_run: connector='{}', command_id={}, " - "cmd='{}', timeout={}", - _name, command_id, processed_cmd, timeout); + SPDLOG_LOGGER_TRACE( + _logger, + "otel_connector::async_run: connector='{}', command_id={}, " + "cmd='{}', timeout={}", + _name, command_id, processed_cmd, timeout); result res; bool res_available = otel->check( processed_cmd, _conv_conf, command_id, macros, timeout, res, [me = shared_from_this(), command_id](const result& async_res) { SPDLOG_LOGGER_TRACE( - me->_logger, "otel_command async_run callback: connector='{}' {}", + me->_logger, "otel_connector async_run callback: connector='{}' {}", me->_name, async_res); me->update_result_cache(command_id, async_res); if (me->_listener) { @@ -200,7 +201,7 @@ uint64_t otel_command::run(const std::string& processed_cmd, if (res_available) { SPDLOG_LOGGER_TRACE(_logger, - "otel_command data available : connector='{}', " + "otel_connector data available : connector='{}', " "cmd='{}', {}", _name, processed_cmd, res); update_result_cache(command_id, res); @@ -222,10 +223,10 @@ uint64_t otel_command::run(const std::string& processed_cmd, * @param timeout timeout in seconds * @param res check result */ -void otel_command::run(const std::string& processed_cmd, - nagios_macros& macros, - uint32_t timeout, - result& res) { +void otel_connector::run(const std::string& processed_cmd, + nagios_macros& macros, + uint32_t timeout, + result& res) { std::shared_ptr otel = otel::open_telemetry_base::instance(); if (!otel) { @@ -239,7 +240,7 @@ void otel_command::run(const std::string& processed_cmd, uint64_t command_id(get_uniq_id()); SPDLOG_LOGGER_TRACE(_logger, - "otel_command::sync_run: connector='{}', cmd='{}', " + "otel_connector::sync_run: connector='{}', cmd='{}', " "command_id={}, timeout={}", _name, processed_cmd, command_id, timeout); @@ -253,13 +254,13 @@ void otel_command::run(const std::string& processed_cmd, cv.notify_one(); }); - // no data_point available => wait util available or timeout + // no otl_data_point available => wait util available or timeout if (!res_available) { std::unique_lock l(cv_m); cv.wait(l); } SPDLOG_LOGGER_TRACE( - _logger, "otel_command::end sync_run: connector='{}', cmd='{}', {}", + _logger, "otel_connector::end sync_run: connector='{}', cmd='{}', {}", _name, processed_cmd, res); } @@ -270,7 +271,7 @@ void otel_command::run(const std::string& processed_cmd, * otel module loading * */ -void otel_command::init() { +void otel_connector::init() { try { if (!_extractor) { std::shared_ptr otel = @@ -291,7 +292,8 @@ void otel_command::init() { std::shared_ptr otel = otel::open_telemetry_base::instance(); if (otel) { - _conv_conf = otel->create_converter_config(get_command_line()); + _conv_conf = + otel->create_check_result_builder_config(get_command_line()); } } } catch (const std::exception& e) { @@ -308,8 +310,9 @@ void otel_command::init() { * @param host * @param service_description empty if host command */ -void otel_command::register_host_serv(const std::string& host, - const std::string& service_description) { +void otel_connector::register_host_serv( + const std::string& host, + const std::string& service_description) { _host_serv_list->register_host_serv(host, service_description); } @@ -320,8 +323,8 @@ void otel_command::register_host_serv(const std::string& host, * @param host * @param service_description empty if host command */ -void otel_command::unregister_host_serv( +void otel_connector::unregister_host_serv( const std::string& host, const std::string& service_description) { - _host_serv_list->unregister_host_serv(host, service_description); + _host_serv_list->remove(host, service_description); } diff --git a/engine/src/commands/otel_interface.cc b/engine/src/commands/otel_interface.cc index 6e733c75c24..19d5559b1fb 100644 --- a/engine/src/commands/otel_interface.cc +++ b/engine/src/commands/otel_interface.cc @@ -34,9 +34,8 @@ void host_serv_list::register_host_serv( _data[host].insert(service_description); } -void host_serv_list::unregister_host_serv( - const std::string& host, - const std::string& service_description) { +void host_serv_list::remove(const std::string& host, + const std::string& service_description) { absl::WriterMutexLock l(&_data_m); auto host_search = _data.find(host); if (host_search != _data.end()) { @@ -55,8 +54,8 @@ void host_serv_list::unregister_host_serv( * @return true found * @return false not found */ -bool host_serv_list::is_allowed(const std::string& host, - const std::string& service_description) const { +bool host_serv_list::contains(const std::string& host, + const std::string& service_description) const { absl::ReaderMutexLock l(&_data_m); auto host_search = _data.find(host); if (host_search != _data.end()) { diff --git a/engine/src/configuration/applier/command.cc b/engine/src/configuration/applier/command.cc index ee8ae3809a3..c8bd72bdf67 100644 --- a/engine/src/configuration/applier/command.cc +++ b/engine/src/configuration/applier/command.cc @@ -22,7 +22,7 @@ #include "com/centreon/engine/checks/checker.hh" #include "com/centreon/engine/commands/connector.hh" #include "com/centreon/engine/commands/forward.hh" -#include "com/centreon/engine/commands/otel_command.hh" +#include "com/centreon/engine/commands/otel_connector.hh" #include "com/centreon/engine/commands/raw.hh" #include "com/centreon/engine/configuration/applier/state.hh" #include "com/centreon/engine/exceptions/error.hh" @@ -70,8 +70,8 @@ void applier::command::add_object(configuration::command const& obj) { obj.command_name(), obj.command_line(), found_con->second)}; commands::command::commands[forward->get_name()] = forward; } else { - std::shared_ptr otel_cmd = - commands::otel_command::get_otel_command(obj.connector()); + std::shared_ptr otel_cmd = + commands::otel_connector::get_otel_connector(obj.connector()); if (otel_cmd) { std::shared_ptr forward{ std::make_shared(obj.command_name(), @@ -149,8 +149,8 @@ void applier::command::modify_object(configuration::command const& obj) { obj.command_name(), obj.command_line(), found_con->second)}; commands::command::commands[forward->get_name()] = forward; } else { - std::shared_ptr otel_cmd = - commands::otel_command::get_otel_command(obj.connector()); + std::shared_ptr otel_cmd = + commands::otel_connector::get_otel_connector(obj.connector()); if (otel_cmd) { std::shared_ptr forward{ std::make_shared(obj.command_name(), @@ -214,7 +214,7 @@ void applier::command::resolve_object(configuration::command const& obj) { connector_map::iterator found{ commands::connector::connectors.find(obj.connector())}; if (found == commands::connector::connectors.end() || !found->second) { - if (!commands::otel_command::get_otel_command(obj.connector())) + if (!commands::otel_connector::get_otel_connector(obj.connector())) throw engine_error() << "unknow command " << obj.connector(); } } diff --git a/engine/src/configuration/applier/connector.cc b/engine/src/configuration/applier/connector.cc index a5fcfd47d77..0fdf87f9c40 100644 --- a/engine/src/configuration/applier/connector.cc +++ b/engine/src/configuration/applier/connector.cc @@ -18,7 +18,7 @@ */ #include "com/centreon/engine/commands/connector.hh" #include "com/centreon/engine/checks/checker.hh" -#include "com/centreon/engine/commands/otel_command.hh" +#include "com/centreon/engine/commands/otel_connector.hh" #include "com/centreon/engine/configuration/applier/connector.hh" #include "com/centreon/engine/configuration/applier/state.hh" #include "com/centreon/engine/exceptions/error.hh" @@ -60,7 +60,7 @@ void applier::connector::add_object(configuration::connector const& obj) { size_t otel_pos = processed_cmd.find(_otel_fake_exe); if (otel_pos < end_path) { - commands::otel_command::create( + commands::otel_connector::create( obj.connector_name(), boost::algorithm::trim_copy( processed_cmd.substr(otel_pos + _otel_fake_exe.length())), @@ -121,12 +121,12 @@ void applier::connector::modify_object(configuration::connector const& obj) { std::string otel_cmdline = boost::algorithm::trim_copy( processed_cmd.substr(otel_pos + _otel_fake_exe.length())); - if (!commands::otel_command::update(obj.key(), processed_cmd)) { + if (!commands::otel_connector::update(obj.key(), processed_cmd)) { // connector object become an otel fake connector if (exist_connector != commands::connector::connectors.end()) { commands::connector::connectors.erase(exist_connector); - commands::otel_command::create(obj.key(), processed_cmd, - &checks::checker::instance()); + commands::otel_connector::create(obj.key(), processed_cmd, + &checks::checker::instance()); } else { throw com::centreon::exceptions::msg_fmt( "unknown open telemetry command to update: {}", obj.key()); @@ -137,8 +137,8 @@ void applier::connector::modify_object(configuration::connector const& obj) { // Set the new command line. exist_connector->second->set_command_line(processed_cmd); } else { - // old otel_command => connector - if (commands::otel_command::remove(obj.key())) { + // old otel_connector => connector + if (commands::otel_connector::remove(obj.key())) { auto cmd = std::make_shared( obj.connector_name(), processed_cmd, &checks::checker::instance()); commands::connector::connectors[obj.connector_name()] = cmd; @@ -174,7 +174,7 @@ void applier::connector::remove_object(configuration::connector const& obj) { commands::connector::connectors.erase(it); } - commands::otel_command::remove(obj.key()); + commands::otel_connector::remove(obj.key()); // Remove connector from the global configuration set. config->connectors().erase(obj); diff --git a/engine/src/configuration/applier/state.cc b/engine/src/configuration/applier/state.cc index c7cbb337439..c145c0d3ee2 100644 --- a/engine/src/configuration/applier/state.cc +++ b/engine/src/configuration/applier/state.cc @@ -21,7 +21,7 @@ #include "com/centreon/engine/broker.hh" #include "com/centreon/engine/commands/connector.hh" -#include "com/centreon/engine/commands/otel_command.hh" +#include "com/centreon/engine/commands/otel_connector.hh" #include "com/centreon/engine/config.hh" #include "com/centreon/engine/configuration/applier/anomalydetection.hh" #include "com/centreon/engine/configuration/applier/command.hh" @@ -150,7 +150,7 @@ void applier::state::clear() { engine::hostgroup::hostgroups.clear(); engine::commands::command::commands.clear(); engine::commands::connector::connectors.clear(); - engine::commands::otel_command::clear(); + engine::commands::otel_connector::clear(); engine::service::services.clear(); engine::service::services_by_id.clear(); engine::servicedependency::servicedependencies.clear(); @@ -189,7 +189,7 @@ applier::state::~state() noexcept { engine::hostgroup::hostgroups.clear(); engine::commands::command::commands.clear(); engine::commands::connector::connectors.clear(); - engine::commands::otel_command::clear(); + engine::commands::otel_connector::clear(); engine::service::services.clear(); engine::service::services_by_id.clear(); engine::servicedependency::servicedependencies.clear(); diff --git a/engine/tests/opentelemetry/host_serv_extractor_test.cc b/engine/tests/opentelemetry/host_serv_extractor_test.cc index 4090ccca5f8..1e20e23d69a 100644 --- a/engine/tests/opentelemetry/host_serv_extractor_test.cc +++ b/engine/tests/opentelemetry/host_serv_extractor_test.cc @@ -33,8 +33,8 @@ TEST(otl_host_serv_extractor_test, empty_request) { std::make_shared<::opentelemetry::proto::collector::metrics::v1:: ExportMetricsServiceRequest>(); - data_point::extract_data_points( - request, [](const data_point& data_pt) { ASSERT_TRUE(false); }); + otl_data_point::extract_data_points( + request, [](const otl_data_point& data_pt) { ASSERT_TRUE(false); }); } class otl_host_serv_attributes_extractor_test : public ::testing::Test { @@ -83,8 +83,9 @@ TEST_F(otl_host_serv_attributes_extractor_test, resource_attrib) { unsigned data_point_extracted_cpt = 0; - data_point::extract_data_points( - request, [this, &data_point_extracted_cpt](const data_point& data_pt) { + otl_data_point::extract_data_points( + request, + [this, &data_point_extracted_cpt](const otl_data_point& data_pt) { ++data_point_extracted_cpt; commands::otel::host_serv_list::pointer host_srv_list = std::make_shared(); @@ -99,8 +100,9 @@ TEST_F(otl_host_serv_attributes_extractor_test, resource_attrib) { ASSERT_EQ(data_point_extracted_cpt, 1); - data_point::extract_data_points( - request, [this, &data_point_extracted_cpt](const data_point& data_pt) { + otl_data_point::extract_data_points( + request, + [this, &data_point_extracted_cpt](const otl_data_point& data_pt) { ++data_point_extracted_cpt; commands::otel::host_serv_list::pointer host_srv_list = std::make_shared(); @@ -110,8 +112,9 @@ TEST_F(otl_host_serv_attributes_extractor_test, resource_attrib) { ASSERT_TRUE(to_test.host.empty()); }); - data_point::extract_data_points( - request, [this, &data_point_extracted_cpt](const data_point& data_pt) { + otl_data_point::extract_data_points( + request, + [this, &data_point_extracted_cpt](const otl_data_point& data_pt) { ++data_point_extracted_cpt; commands::otel::host_serv_list::pointer host_srv_list = std::make_shared(); @@ -124,8 +127,9 @@ TEST_F(otl_host_serv_attributes_extractor_test, resource_attrib) { auto serv = resources->mutable_resource()->mutable_attributes()->Add(); serv->set_key("service"); serv->mutable_value()->set_string_value("my_serv"); - data_point::extract_data_points( - request, [this, &data_point_extracted_cpt](const data_point& data_pt) { + otl_data_point::extract_data_points( + request, + [this, &data_point_extracted_cpt](const otl_data_point& data_pt) { ++data_point_extracted_cpt; commands::otel::host_serv_list::pointer host_srv_list = std::make_shared(); @@ -137,8 +141,9 @@ TEST_F(otl_host_serv_attributes_extractor_test, resource_attrib) { ASSERT_EQ(to_test.metric, "metric cpu"); }); - data_point::extract_data_points( - request, [this, &data_point_extracted_cpt](const data_point& data_pt) { + otl_data_point::extract_data_points( + request, + [this, &data_point_extracted_cpt](const otl_data_point& data_pt) { ++data_point_extracted_cpt; commands::otel::host_serv_list::pointer host_srv_list = std::make_shared(); @@ -149,8 +154,9 @@ TEST_F(otl_host_serv_attributes_extractor_test, resource_attrib) { ASSERT_EQ(to_test.service, "my_serv"); ASSERT_EQ(to_test.metric, "metric cpu"); }); - data_point::extract_data_points( - request, [this, &data_point_extracted_cpt](const data_point& data_pt) { + otl_data_point::extract_data_points( + request, + [this, &data_point_extracted_cpt](const otl_data_point& data_pt) { ++data_point_extracted_cpt; commands::otel::host_serv_list::pointer host_srv_list = std::make_shared(); @@ -163,8 +169,9 @@ TEST_F(otl_host_serv_attributes_extractor_test, resource_attrib) { auto serv2 = resources->mutable_resource()->mutable_attributes()->Add(); serv2->set_key("service"); serv2->mutable_value()->set_string_value("my_serv2"); - data_point::extract_data_points( - request, [this, &data_point_extracted_cpt](const data_point& data_pt) { + otl_data_point::extract_data_points( + request, + [this, &data_point_extracted_cpt](const otl_data_point& data_pt) { ++data_point_extracted_cpt; commands::otel::host_serv_list::pointer host_srv_list = std::make_shared(); @@ -201,8 +208,9 @@ TEST_F(otl_host_serv_attributes_extractor_test, scope_attrib) { unsigned data_point_extracted_cpt = 0; - data_point::extract_data_points( - request, [this, &data_point_extracted_cpt](const data_point& data_pt) { + otl_data_point::extract_data_points( + request, + [this, &data_point_extracted_cpt](const otl_data_point& data_pt) { ++data_point_extracted_cpt; commands::otel::host_serv_list::pointer host_srv_list = std::make_shared(); @@ -217,8 +225,9 @@ TEST_F(otl_host_serv_attributes_extractor_test, scope_attrib) { ASSERT_EQ(data_point_extracted_cpt, 1); - data_point::extract_data_points( - request, [this, &data_point_extracted_cpt](const data_point& data_pt) { + otl_data_point::extract_data_points( + request, + [this, &data_point_extracted_cpt](const otl_data_point& data_pt) { ++data_point_extracted_cpt; commands::otel::host_serv_list::pointer host_srv_list = std::make_shared(); @@ -228,8 +237,9 @@ TEST_F(otl_host_serv_attributes_extractor_test, scope_attrib) { ASSERT_TRUE(to_test.host.empty()); }); - data_point::extract_data_points( - request, [this, &data_point_extracted_cpt](const data_point& data_pt) { + otl_data_point::extract_data_points( + request, + [this, &data_point_extracted_cpt](const otl_data_point& data_pt) { ++data_point_extracted_cpt; commands::otel::host_serv_list::pointer host_srv_list = std::make_shared(); @@ -242,8 +252,9 @@ TEST_F(otl_host_serv_attributes_extractor_test, scope_attrib) { auto serv = scope->mutable_scope()->mutable_attributes()->Add(); serv->set_key("service"); serv->mutable_value()->set_string_value("my_serv"); - data_point::extract_data_points( - request, [this, &data_point_extracted_cpt](const data_point& data_pt) { + otl_data_point::extract_data_points( + request, + [this, &data_point_extracted_cpt](const otl_data_point& data_pt) { ++data_point_extracted_cpt; commands::otel::host_serv_list::pointer host_srv_list = std::make_shared(); @@ -276,8 +287,9 @@ TEST_F(otl_host_serv_attributes_extractor_test, data_point_attrib) { unsigned data_point_extracted_cpt = 0; - data_point::extract_data_points( - request, [this, &data_point_extracted_cpt](const data_point& data_pt) { + otl_data_point::extract_data_points( + request, + [this, &data_point_extracted_cpt](const otl_data_point& data_pt) { ++data_point_extracted_cpt; commands::otel::host_serv_list::pointer host_srv_list = std::make_shared(); @@ -291,8 +303,9 @@ TEST_F(otl_host_serv_attributes_extractor_test, data_point_attrib) { ASSERT_EQ(data_point_extracted_cpt, 1); - data_point::extract_data_points( - request, [this, &data_point_extracted_cpt](const data_point& data_pt) { + otl_data_point::extract_data_points( + request, + [this, &data_point_extracted_cpt](const otl_data_point& data_pt) { ++data_point_extracted_cpt; commands::otel::host_serv_list::pointer host_srv_list = std::make_shared(); @@ -302,8 +315,9 @@ TEST_F(otl_host_serv_attributes_extractor_test, data_point_attrib) { ASSERT_TRUE(to_test.host.empty()); }); - data_point::extract_data_points( - request, [this, &data_point_extracted_cpt](const data_point& data_pt) { + otl_data_point::extract_data_points( + request, + [this, &data_point_extracted_cpt](const otl_data_point& data_pt) { ++data_point_extracted_cpt; commands::otel::host_serv_list::pointer host_srv_list = std::make_shared(); @@ -313,8 +327,9 @@ TEST_F(otl_host_serv_attributes_extractor_test, data_point_attrib) { ASSERT_TRUE(to_test.host.empty()); }); - data_point::extract_data_points( - request, [this, &data_point_extracted_cpt](const data_point& data_pt) { + otl_data_point::extract_data_points( + request, + [this, &data_point_extracted_cpt](const otl_data_point& data_pt) { ++data_point_extracted_cpt; commands::otel::host_serv_list::pointer host_srv_list = std::make_shared(); @@ -327,8 +342,9 @@ TEST_F(otl_host_serv_attributes_extractor_test, data_point_attrib) { auto serv = point->mutable_attributes()->Add(); serv->set_key("service"); serv->mutable_value()->set_string_value("my_serv"); - data_point::extract_data_points( - request, [this, &data_point_extracted_cpt](const data_point& data_pt) { + otl_data_point::extract_data_points( + request, + [this, &data_point_extracted_cpt](const otl_data_point& data_pt) { ++data_point_extracted_cpt; commands::otel::host_serv_list::pointer host_srv_list = std::make_shared(); diff --git a/engine/tests/opentelemetry/opentelemetry_test.cc b/engine/tests/opentelemetry/opentelemetry_test.cc index c06aa5579dc..d26d169ff87 100644 --- a/engine/tests/opentelemetry/opentelemetry_test.cc +++ b/engine/tests/opentelemetry/opentelemetry_test.cc @@ -163,10 +163,11 @@ TEST_F(open_telemetry_test, data_available) { nagios_macros macros; macros.host_ptr = host::hosts.begin()->second.get(); macros.service_ptr = service::services.begin()->second.get(); - ASSERT_TRUE(instance->check( - "nagios_telegraf", - instance->create_converter_config("--processor=nagios_telegraf"), 1, - macros, 1, res, [](const commands::result&) {})); + ASSERT_TRUE(instance->check("nagios_telegraf", + instance->create_check_result_builder_config( + "--processor=nagios_telegraf"), + 1, macros, 1, res, + [](const commands::result&) {})); ASSERT_EQ(res.command_id, 1); ASSERT_EQ(res.start_time.to_useconds(), 1707744430000000); ASSERT_EQ(res.end_time.to_useconds(), 1707744430000000); @@ -196,13 +197,14 @@ TEST_F(open_telemetry_test, timeout) { macros.service_ptr = service::services.begin()->second.get(); std::condition_variable cv; std::mutex cv_m; - ASSERT_FALSE(instance->check( - "nagios_telegraf", - instance->create_converter_config("--processor=nagios_telegraf"), 1, - macros, 1, res, [&res, &cv](const commands::result& async_res) { - res = async_res; - cv.notify_one(); - })); + ASSERT_FALSE(instance->check("nagios_telegraf", + instance->create_check_result_builder_config( + "--processor=nagios_telegraf"), + 1, macros, 1, res, + [&res, &cv](const commands::result& async_res) { + res = async_res; + cv.notify_one(); + })); std::unique_lock l(cv_m); ASSERT_EQ(cv.wait_for(l, std::chrono::seconds(3)), @@ -232,8 +234,8 @@ TEST_F(open_telemetry_test, wait_for_data) { std::mutex cv_m; std::condition_variable cv; bool data_available = instance->check( - "nagios_telegraf", instance->create_converter_config(otl_conf), 1, macros, - 1, res, [&res, &cv](const commands::result& async_res) { + "nagios_telegraf", instance->create_check_result_builder_config(otl_conf), + 1, macros, 1, res, [&res, &cv](const commands::result& async_res) { res = async_res; cv.notify_one(); }); diff --git a/engine/tests/opentelemetry/otl_converter_test.cc b/engine/tests/opentelemetry/otl_converter_test.cc index 65b3ea539b6..8ebc07f4282 100644 --- a/engine/tests/opentelemetry/otl_converter_test.cc +++ b/engine/tests/opentelemetry/otl_converter_test.cc @@ -37,8 +37,8 @@ #include "opentelemetry/proto/metrics/v1/metrics.pb.h" #include "com/centreon/engine/modules/opentelemetry/data_point_fifo_container.hh" -#include "com/centreon/engine/modules/opentelemetry/otl_converter.hh" -#include "com/centreon/engine/modules/opentelemetry/telegraf/nagios_converter.hh" +#include "com/centreon/engine/modules/opentelemetry/otl_check_result_builder.hh" +#include "com/centreon/engine/modules/opentelemetry/telegraf/nagios_check_result_builder.hh" #include "helper.hh" #include "test_engine.hh" @@ -81,7 +81,7 @@ void otl_converter_test::TearDown() { TEST_F(otl_converter_test, empty_fifo) { data_point_fifo_container empty; - telegraf::nagios_converter conv( + telegraf::nagios_check_result_builder conv( "", 1, *host::hosts.begin()->second, service::services.begin()->second.get(), std::chrono::system_clock::time_point(), [&](const commands::result&) {}, @@ -581,12 +581,13 @@ TEST_F(otl_converter_test, nagios_telegraf) { ::google::protobuf::util::JsonStringToMessage(telegraf_example, request.get()); - data_point::extract_data_points(request, [&](const data_point& data_pt) { - received.add_data_point("localhost", "check_icmp", - data_pt.get_metric().name(), data_pt); - }); + otl_data_point::extract_data_points( + request, [&](const otl_data_point& data_pt) { + received.add_data_point("localhost", "check_icmp", + data_pt.get_metric().name(), data_pt); + }); - telegraf::nagios_converter conv( + telegraf::nagios_check_result_builder conv( "", 1, *host::hosts.begin()->second, service::services.begin()->second.get(), std::chrono::system_clock::time_point(), [&](const commands::result&) {}, @@ -616,12 +617,13 @@ TEST_F(otl_converter_test, nagios_telegraf_le_ge) { ::google::protobuf::util::JsonStringToMessage(example, request.get()); - data_point::extract_data_points(request, [&](const data_point& data_pt) { - received.add_data_point("localhost", "check_icmp", - data_pt.get_metric().name(), data_pt); - }); + otl_data_point::extract_data_points( + request, [&](const otl_data_point& data_pt) { + received.add_data_point("localhost", "check_icmp", + data_pt.get_metric().name(), data_pt); + }); - telegraf::nagios_converter conv( + telegraf::nagios_check_result_builder conv( "", 1, *host::hosts.begin()->second, service::services.begin()->second.get(), std::chrono::system_clock::time_point(), [&](const commands::result&) {}, @@ -649,12 +651,13 @@ TEST_F(otl_converter_test, nagios_telegraf_max) { ::google::protobuf::util::JsonStringToMessage(example, request.get()); - data_point::extract_data_points(request, [&](const data_point& data_pt) { - received.add_data_point("localhost", "check_icmp", - data_pt.get_metric().name(), data_pt); - }); + otl_data_point::extract_data_points( + request, [&](const otl_data_point& data_pt) { + received.add_data_point("localhost", "check_icmp", + data_pt.get_metric().name(), data_pt); + }); - telegraf::nagios_converter conv( + telegraf::nagios_check_result_builder conv( "", 1, *host::hosts.begin()->second, service::services.begin()->second.get(), std::chrono::system_clock::time_point(), [&](const commands::result&) {}, diff --git a/tests/resources/opentelemetry/telegraf1.conf b/tests/resources/opentelemetry/telegraf1.conf deleted file mode 100644 index 413e25eeb85..00000000000 --- a/tests/resources/opentelemetry/telegraf1.conf +++ /dev/null @@ -1,36 +0,0 @@ -# Centreon telegraf configuration -# This telegraf configuration is generated by centreon centengine -[agent] - ## Default data collection interval for all inputs - interval = "60s" - -[[outputs.opentelemetry]] - service_address = "127.0.0.1:4317" - - -[[inputs.exec]] - name_override = "host_1__service_2" - commands = ["/usr/lib/nagios/plugins/check_icmp 127.0.0.2"] - data_format = "nagios" - [inputs.exec.tags] - host = "host_1" - service = "service_2" - - -[[inputs.exec]] - name_override = "host_1__service_1" - commands = ["/usr/lib/nagios/plugins/check_icmp 127.0.0.1"] - data_format = "nagios" - [inputs.exec.tags] - host = "host_1" - service = "service_1" - - -[[inputs.exec]] - name_override = "host_1__" - commands = ["/usr/lib/nagios/plugins/check_icmp 127.0.0.10"] - data_format = "nagios" - [inputs.exec.tags] - host = "host_1" - service = "" - diff --git a/tests/resources/opentelemetry/telegraf2.conf b/tests/resources/opentelemetry/telegraf2.conf deleted file mode 100644 index 17f0d8a7f6f..00000000000 --- a/tests/resources/opentelemetry/telegraf2.conf +++ /dev/null @@ -1,27 +0,0 @@ -# Centreon telegraf configuration -# This telegraf configuration is generated by centreon centengine -[agent] - ## Default data collection interval for all inputs - interval = "60s" - -[[outputs.opentelemetry]] - service_address = "127.0.0.1:4317" - - -[[inputs.exec]] - name_override = "host_3__service_5" - commands = ["/usr/lib/nagios/plugins/check_icmp 127.0.0.5"] - data_format = "nagios" - [inputs.exec.tags] - host = "host_3" - service = "service_5" - - -[[inputs.exec]] - name_override = "host_2__" - commands = ["/usr/lib/nagios/plugins/check_icmp 127.0.0.20"] - data_format = "nagios" - [inputs.exec.tags] - host = "host_2" - service = "" -