From 392e8fcab530c8c77214df4d05bcd11d0d1cf0f2 Mon Sep 17 00:00:00 2001 From: Jean Christophe Roques Date: Tue, 21 May 2024 06:40:21 +0200 Subject: [PATCH] add opentelemetry bbdo message --- .github/scripts/collect-test-robot.sh | 3 + CMakeLists.txt | 18 +++++ bbdo/CMakeLists.txt | 32 +++++++++ bbdo/events.hh | 3 + broker/grpc/CMakeLists.txt | 3 + broker/grpc/generate_proto.py | 29 ++++++++ .../broker/http_tsdb/line_protocol_query.hh | 18 ++--- broker/http_tsdb/src/line_protocol_query.cc | 68 +++++++++---------- broker/http_tsdb/src/stream.cc | 2 - broker/lua/src/broker_utils.cc | 20 ++++++ broker/neb/CMakeLists.txt | 13 ++-- .../inc/com/centreon/broker/neb/callbacks.hh | 2 + .../inc/com/centreon/broker/neb/internal.hh | 5 ++ broker/neb/src/broker.cc | 4 +- broker/neb/src/callbacks.cc | 58 +++++++++++++++- broker/victoria_metrics/src/factory.cc | 4 +- common/src/hex_dump.cc | 32 ++++----- engine/inc/com/centreon/engine/log_v2.hh | 7 +- .../inc/com/centreon/engine/nebcallbacks.hh | 3 +- tests/README.md | 11 +++ tests/init-proto.sh | 9 ++- tests/update-doc.py | 11 +++ 22 files changed, 281 insertions(+), 74 deletions(-) diff --git a/.github/scripts/collect-test-robot.sh b/.github/scripts/collect-test-robot.sh index fae6945272a..5f78ed1a907 100755 --- a/.github/scripts/collect-test-robot.sh +++ b/.github/scripts/collect-test-robot.sh @@ -62,6 +62,9 @@ echo '/tmp/core.%p' > /proc/sys/kernel/core_pattern #remove git dubious ownership /usr/bin/git config --global --add safe.directory $PWD +echo "###### git clone opentelemetry-proto #######" +git clone --depth=1 --single-branch https://github.com/open-telemetry/opentelemetry-proto.git opentelemetry-proto + echo "##### Starting tests #####" cd tests ./init-proto.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 29a44ba4e79..22f208b6765 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -178,6 +178,24 @@ set(OTLP_LIB_DIR ${opentelemetry-cpp_DIR}/../../lib) set(VCPKG_INCLUDE_DIR ${Protobuf_INCLUDE_DIR}) include(GNUInstallDirs) +#import opentelemetry-proto +add_custom_command( + OUTPUT ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/collector/metrics/v1/metrics_service.proto + ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/metrics/v1/metrics.proto + ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/common/v1/common.proto + ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/resource/v1/resource.proto + COMMENT "get opentelemetry proto files from git repository" + COMMAND /bin/rm -rf ${CMAKE_SOURCE_DIR}/opentelemetry-proto + COMMAND git ARGS clone --depth=1 --single-branch https://github.com/open-telemetry/opentelemetry-proto.git ${CMAKE_SOURCE_DIR}/opentelemetry-proto + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} +) + +add_custom_target(opentelemetry-proto-files DEPENDS ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/collector/metrics/v1/metrics_service.proto + ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/metrics/v1/metrics.proto + ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/common/v1/common.proto + ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/resource/v1/resource.proto +) + # var directories. set(BROKER_VAR_LOG_DIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/centreon-broker") diff --git a/bbdo/CMakeLists.txt b/bbdo/CMakeLists.txt index 17eded04020..0bab457aa4e 100644 --- a/bbdo/CMakeLists.txt +++ b/bbdo/CMakeLists.txt @@ -92,6 +92,38 @@ add_dependencies(pb_remove_graph_message_lib target_remove_graph_message set_target_properties(pb_remove_graph_message_lib PROPERTIES POSITION_INDEPENDENT_CODE ON) +set(otl_protobuf_files + opentelemetry/proto/collector/metrics/v1/metrics_service + opentelemetry/proto/metrics/v1/metrics + opentelemetry/proto/common/v1/common + opentelemetry/proto/resource/v1/resource +) +foreach(name IN LISTS otl_protobuf_files) + set(proto_file "${name}.proto") + add_custom_command( + OUTPUT "${CMAKE_SOURCE_DIR}/bbdo/${name}.pb.cc" + COMMENT "Generating interface files of the otl file ${proto_file}" + #DEPENDS ${CMAKE_BINARY_DIR}/opentelemetry-proto/${proto_file} + DEPENDS opentelemetry-proto-files + COMMAND + ${Protobuf_PROTOC_EXECUTABLE} ARGS --cpp_out=${CMAKE_SOURCE_DIR}/bbdo + --proto_path=${CMAKE_SOURCE_DIR}/opentelemetry-proto ${proto_file} + VERBATIM) +endforeach() + +add_library(pb_open_telemetry_lib STATIC +${CMAKE_SOURCE_DIR}/bbdo/opentelemetry/proto/collector/metrics/v1/metrics_service.pb.cc +${CMAKE_SOURCE_DIR}/bbdo/opentelemetry/proto/metrics/v1/metrics.pb.cc +${CMAKE_SOURCE_DIR}/bbdo/opentelemetry/proto/common/v1/common.pb.cc +${CMAKE_SOURCE_DIR}/bbdo/opentelemetry/proto/resource/v1/resource.pb.cc +) + +target_include_directories(pb_open_telemetry_lib BEFORE PRIVATE ${CMAKE_SOURCE_DIR}/bbdo) + + +set_target_properties(pb_open_telemetry_lib + PROPERTIES POSITION_INDEPENDENT_CODE ON) + macro(get_protobuf_files name) set_source_files_properties("${CMAKE_SOURCE_DIR}/bbdo/${name}.pb.cc" PROPERTIES GENERATED TRUE) diff --git a/bbdo/events.hh b/bbdo/events.hh index d43972d4cab..d4bd387e5c0 100644 --- a/bbdo/events.hh +++ b/bbdo/events.hh @@ -166,6 +166,9 @@ enum data_element { de_pb_status = 10, de_pb_index_mapping = 11, de_pb_metric_mapping = 12, + de_pb_otl_metrics = + 13 // contain an + // ::opentelemetry::proto::collector::metrics::v1::ExportMetricsServiceRequest }; } namespace bam { diff --git a/broker/grpc/CMakeLists.txt b/broker/grpc/CMakeLists.txt index 695202e81f5..e56adfbc1fa 100644 --- a/broker/grpc/CMakeLists.txt +++ b/broker/grpc/CMakeLists.txt @@ -55,6 +55,7 @@ target_link_libraries( pb_tag_lib pb_bam_lib pb_extcmd_lib + pb_open_telemetry_lib pb_rebuild_message_lib pb_remove_graph_message_lib pb_header_lib @@ -85,6 +86,7 @@ add_custom_command( COMMAND ${Protobuf_PROTOC_EXECUTABLE} ARGS --cpp_out=${SRC_DIR} --proto_path=${MODULE_DIR} --proto_path=${CMAKE_SOURCE_DIR}/bbdo + --proto_path=${CMAKE_SOURCE_DIR}/opentelemetry-proto grpc_stream.proto VERBATIM) @@ -96,6 +98,7 @@ add_custom_command( ${Protobuf_PROTOC_EXECUTABLE} ARGS --grpc_out=${SRC_DIR} --plugin=protoc-gen-grpc=${GRPC_CPP_PLUGIN} --proto_path=${MODULE_DIR} --proto_path=${CMAKE_SOURCE_DIR}/bbdo + --proto_path=${CMAKE_SOURCE_DIR}/opentelemetry-proto grpc_stream.proto VERBATIM WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) diff --git a/broker/grpc/generate_proto.py b/broker/grpc/generate_proto.py index b1b71cf9948..9887305813c 100755 --- a/broker/grpc/generate_proto.py +++ b/broker/grpc/generate_proto.py @@ -25,6 +25,7 @@ file_begin_content = """syntax = "proto3"; +import "opentelemetry/proto/collector/metrics/v1/metrics_service.proto"; """ file_message_centreon_event = """ @@ -213,6 +214,34 @@ class received_protobuf : public io::protobuf { """ +#The following message is not in bbdo protobuff files so we need to add manually. + +file_message_centreon_event += f" opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest ExportMetricsServiceRequest_ = {one_of_index};\n" + +cc_file_protobuf_to_event_function += """ + case ::stream::CentreonEvent::kExportMetricsServiceRequest: + return std::make_shared>( + stream_content, &grpc_event_type::exportmetricsservicerequest_, + &grpc_event_type::mutable_exportmetricsservicerequest_); +""" + +cc_file_create_event_with_data_function += """ + case make_type(io::storage, storage::de_pb_otl_metrics): + ret = std::make_shared( + event, reinterpret_cast( + &grpc_event_type::release_exportmetricsservicerequest_)); + ret->grpc_event.set_allocated_exportmetricsservicerequest_( + &std::static_pointer_cast>(event) + ->mut_obj()); + break; +""" + with open(args.proto_file, 'w', encoding="utf-8") as fp: fp.write(file_begin_content) fp.write(""" diff --git a/broker/http_tsdb/inc/com/centreon/broker/http_tsdb/line_protocol_query.hh b/broker/http_tsdb/inc/com/centreon/broker/http_tsdb/line_protocol_query.hh index a05c86d39e6..822bfd33617 100644 --- a/broker/http_tsdb/inc/com/centreon/broker/http_tsdb/line_protocol_query.hh +++ b/broker/http_tsdb/inc/com/centreon/broker/http_tsdb/line_protocol_query.hh @@ -122,13 +122,13 @@ class line_protocol_query { std::ostream& is) const; void _get_tag_host_cat_id(io::data const& d, - unsigned& string_index, + unsigned&, std::ostream& is) const { _get_tag_host_id(d, TagType::HOSTCATEGORY, is); } void _get_tag_host_group_id(io::data const& d, - unsigned& string_index, + unsigned&, std::ostream& is) const { _get_tag_host_id(d, TagType::HOSTGROUP, is); } @@ -138,13 +138,13 @@ class line_protocol_query { std::ostream& is) const; void _get_tag_host_cat_name(io::data const& d, - unsigned& string_index, + unsigned&, std::ostream& is) const { _get_tag_host_name(d, TagType::HOSTCATEGORY, is); } void _get_tag_host_group_name(io::data const& d, - unsigned& string_index, + unsigned&, std::ostream& is) const { _get_tag_host_name(d, TagType::HOSTGROUP, is); } @@ -154,13 +154,13 @@ class line_protocol_query { std::ostream& is) const; void _get_tag_serv_cat_id(io::data const& d, - unsigned& string_index, + unsigned&, std::ostream& is) const { _get_tag_serv_id(d, TagType::SERVICECATEGORY, is); } void _get_tag_serv_group_id(io::data const& d, - unsigned& string_index, + unsigned&, std::ostream& is) const { _get_tag_serv_id(d, TagType::SERVICEGROUP, is); } @@ -170,13 +170,13 @@ class line_protocol_query { std::ostream& is) const; void _get_tag_serv_cat_name(io::data const& d, - unsigned& string_index, + unsigned&, std::ostream& is) const { _get_tag_serv_name(d, TagType::SERVICECATEGORY, is); } void _get_tag_serv_group_name(io::data const& d, - unsigned& string_index, + unsigned&, std::ostream& is) const { _get_tag_serv_name(d, TagType::SERVICEGROUP, is); } @@ -212,6 +212,6 @@ class line_protocol_query { }; } // namespace http_tsdb -} +} // namespace com::centreon::broker #endif // !CCB_HTTP_TSDB_LINE_PROTOCOL_QUERY_HH diff --git a/broker/http_tsdb/src/line_protocol_query.cc b/broker/http_tsdb/src/line_protocol_query.cc index f4617b299e4..79c07534985 100644 --- a/broker/http_tsdb/src/line_protocol_query.cc +++ b/broker/http_tsdb/src/line_protocol_query.cc @@ -1,20 +1,20 @@ /** -* Copyright 2015-2017 Centreon -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* -* For more information : contact@centreon.com -*/ + * Copyright 2015-2017 Centreon + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * For more information : contact@centreon.com + */ #include "com/centreon/broker/http_tsdb/line_protocol_query.hh" #include "com/centreon/broker/cache/global_cache.hh" @@ -387,7 +387,7 @@ void line_protocol_query::_get_string(io::data const& d, * @param[in] is The stream. */ void line_protocol_query::_get_dollar_sign(io::data const& d, - unsigned& string_index, + unsigned&, std::ostream& is) const { (void)d; is << "$"; @@ -429,7 +429,7 @@ uint64_t line_protocol_query::_get_index_id(io::data const& d) const { * @param[out] is The stream. */ void line_protocol_query::_get_index_id(io::data const& d, - unsigned& string_index, + unsigned&, std::ostream& is) const { cache::global_cache::lock l; is << _get_index_id(d); @@ -442,7 +442,7 @@ void line_protocol_query::_get_index_id(io::data const& d, * @param is The stream. */ void line_protocol_query::_get_host(io::data const& d, - unsigned& string_index, + unsigned&, std::ostream& is) const { uint64_t host_id = d.type() == storage::pb_metric::static_type() @@ -477,7 +477,7 @@ uint64_t line_protocol_query::_get_host_id(io::data const& d) const { * @param is The stream. */ void line_protocol_query::_get_host_id(io::data const& d, - unsigned& string_index, + unsigned&, std::ostream& is) const { is << _get_host_id(d); } @@ -489,7 +489,7 @@ void line_protocol_query::_get_host_id(io::data const& d, * @param is The stream. */ void line_protocol_query::_get_service(io::data const& d, - unsigned& string_index, + unsigned&, std::ostream& is) const { cache::host_serv_pair host_serv = _get_service_id(d); cache::global_cache::lock l; @@ -524,7 +524,7 @@ cache::host_serv_pair line_protocol_query::_get_service_id( * @param is The stream. */ void line_protocol_query::_get_service_id(io::data const& d, - unsigned& string_index, + unsigned&, std::ostream& is) const { is << _get_service_id(d).second; } @@ -536,7 +536,7 @@ void line_protocol_query::_get_service_id(io::data const& d, * @param is The stream. */ void line_protocol_query::_get_instance(io::data const& d, - unsigned& string_index, + unsigned&, std::ostream& is) const { cache::global_cache::lock l; const cache::string* instance_name = @@ -554,7 +554,7 @@ void line_protocol_query::_get_instance(io::data const& d, * @param is */ void line_protocol_query::_get_host_group(io::data const& d, - unsigned& string_index, + unsigned&, std::ostream& is) const { cache::global_cache::lock l; cache::global_cache::instance_ptr()->append_host_group(_get_host_id(d), is); @@ -568,7 +568,7 @@ void line_protocol_query::_get_host_group(io::data const& d, * @param is */ void line_protocol_query::_get_service_group(io::data const& d, - unsigned& string_index, + unsigned&, std::ostream& is) const { cache::host_serv_pair host_serv = _get_service_id(d); cache::global_cache::lock l; @@ -584,7 +584,7 @@ void line_protocol_query::_get_service_group(io::data const& d, * @param is */ void line_protocol_query::_get_min(io::data const& d, - unsigned& string_index, + unsigned&, std::ostream& is) const { cache::global_cache::lock l; const cache::metric_info* infos = _get_metric_info(d); @@ -601,7 +601,7 @@ void line_protocol_query::_get_min(io::data const& d, * @param is */ void line_protocol_query::_get_max(io::data const& d, - unsigned& string_index, + unsigned&, std::ostream& is) const { cache::global_cache::lock l; const cache::metric_info* infos = _get_metric_info(d); @@ -618,7 +618,7 @@ void line_protocol_query::_get_max(io::data const& d, * @param is */ void line_protocol_query::_get_resource_id(io::data const& d, - unsigned& string_index, + unsigned&, std::ostream& is) const { cache::host_serv_pair host_serv = _get_service_id(d); cache::global_cache::lock l; @@ -723,7 +723,7 @@ void line_protocol_query::_get_tag_serv_name(io::data const& d, * @param is */ void line_protocol_query::_get_metric_name(io::data const& d, - unsigned& string_index, + unsigned&, std::ostream& is) const { is << static_cast(d).obj().name(); } @@ -735,7 +735,7 @@ void line_protocol_query::_get_metric_name(io::data const& d, * @param is */ void line_protocol_query::_get_metric_id(io::data const& d, - unsigned& string_index, + unsigned&, std::ostream& is) const { is << static_cast(d).obj().metric_id(); } @@ -747,7 +747,7 @@ void line_protocol_query::_get_metric_id(io::data const& d, * @param is */ void line_protocol_query::_get_metric_value(io::data const& d, - unsigned& string_index, + unsigned&, std::ostream& is) const { is << static_cast(d).obj().value(); } @@ -759,7 +759,7 @@ void line_protocol_query::_get_metric_value(io::data const& d, * @param is */ void line_protocol_query::_get_metric_time(io::data const& d, - unsigned& string_index, + unsigned&, std::ostream& is) const { is << static_cast(d).obj().time(); } @@ -771,7 +771,7 @@ void line_protocol_query::_get_metric_time(io::data const& d, * @param is */ void line_protocol_query::_get_status_state(io::data const& d, - unsigned& string_index, + unsigned&, std::ostream& is) const { is << static_cast(d).obj().state(); } @@ -783,7 +783,7 @@ void line_protocol_query::_get_status_state(io::data const& d, * @param is */ void line_protocol_query::_get_status_time(io::data const& d, - unsigned& string_index, + unsigned&, std::ostream& is) const { is << static_cast(d).obj().time(); } diff --git a/broker/http_tsdb/src/stream.cc b/broker/http_tsdb/src/stream.cc index dc78b102350..103fe09f242 100644 --- a/broker/http_tsdb/src/stream.cc +++ b/broker/http_tsdb/src/stream.cc @@ -185,8 +185,6 @@ bool stream::read(std::shared_ptr& d, time_t) { * @param tree */ void stream::statistics(nlohmann::json& tree) const { - time_t now = time(nullptr); - auto extract_stat = [&](const char* label, const stat_average& data) { if (!data.empty()) { tree[label] = data.get_average(); diff --git a/broker/lua/src/broker_utils.cc b/broker/lua/src/broker_utils.cc index 9c03b1759fa..f800e1ffc90 100644 --- a/broker/lua/src/broker_utils.cc +++ b/broker/lua/src/broker_utils.cc @@ -37,6 +37,7 @@ #include "com/centreon/broker/log_v2.hh" #include "com/centreon/broker/mapping/entry.hh" #include "com/centreon/broker/misc/misc.hh" +#include "com/centreon/common/hex_dump.hh" #include "com/centreon/exceptions/msg_fmt.hh" using namespace com::centreon::broker; @@ -189,6 +190,7 @@ static void _message_to_json(std::ostringstream& oss, } oss << ']'; break; + case google::protobuf::FieldDescriptor::TYPE_SFIXED64: case google::protobuf::FieldDescriptor::TYPE_INT64: oss << fmt::format("\"{}\":[", entry_name); for (size_t j = 0; j < s; j++) { @@ -198,6 +200,7 @@ static void _message_to_json(std::ostringstream& oss, } oss << ']'; break; + case google::protobuf::FieldDescriptor::TYPE_FIXED64: case google::protobuf::FieldDescriptor::TYPE_UINT64: oss << fmt::format("\"{}\":[", entry_name); for (size_t j = 0; j < s; j++) { @@ -237,6 +240,16 @@ static void _message_to_json(std::ostringstream& oss, } oss << ']'; break; + case google::protobuf::FieldDescriptor::TYPE_BYTES: + oss << fmt::format("\"{}\":[", entry_name); + for (size_t j = 0; j < s; j++) { + if (j > 0) + oss << ','; + tmpl = refl->GetRepeatedStringReference(*p, f, j, &tmpl); + oss << '"' << com::centreon::common::hex_dump(tmpl, 0) << '"'; + } + oss << ']'; + break; default: // Error, a type not handled throw msg_fmt( "protobuf {} type ID is not handled in the broker json converter", @@ -258,9 +271,11 @@ static void _message_to_json(std::ostringstream& oss, case google::protobuf::FieldDescriptor::TYPE_UINT32: oss << fmt::format("\"{}\":{}", entry_name, refl->GetUInt32(*p, f)); break; + case google::protobuf::FieldDescriptor::TYPE_SFIXED64: case google::protobuf::FieldDescriptor::TYPE_INT64: oss << fmt::format("\"{}\":{}", entry_name, refl->GetInt64(*p, f)); break; + case google::protobuf::FieldDescriptor::TYPE_FIXED64: case google::protobuf::FieldDescriptor::TYPE_UINT64: oss << fmt::format("\"{}\":{}", entry_name, refl->GetUInt64(*p, f)); break; @@ -277,6 +292,11 @@ static void _message_to_json(std::ostringstream& oss, _message_to_json(oss, &refl->GetMessage(*p, f)); oss << '}'; break; + case google::protobuf::FieldDescriptor::TYPE_BYTES: + tmpl = refl->GetStringReference(*p, f, &tmpl); + oss << fmt::format(R"("{}":"{}")", entry_name, + com::centreon::common::hex_dump(tmpl, 0)); + break; default: // Error, a type not handled throw msg_fmt( "protobuf {} type ID is not handled in the broker json converter", diff --git a/broker/neb/CMakeLists.txt b/broker/neb/CMakeLists.txt index 5c9476c114d..27d2ac94edc 100644 --- a/broker/neb/CMakeLists.txt +++ b/broker/neb/CMakeLists.txt @@ -100,11 +100,14 @@ add_dependencies(nebbase pb_header_lib ) -target_link_libraries(nebbase - -L${PROTOBUF_LIB_DIR} - pb_severity_lib pb_tag_lib - protobuf - pb_neb_lib pb_header_lib) +target_link_libraries(nebbase + -L${PROTOBUF_LIB_DIR} + protobuf + pb_severity_lib + pb_tag_lib + pb_neb_lib + pb_header_lib + pb_open_telemetry_lib) set(NEBBASE_CXXFLAGS "${NEBBASE_CXXFLAGS} -fPIC") set_property(TARGET nebbase PROPERTY COMPILE_FLAGS ${NEBBASE_CXXFLAGS}) diff --git a/broker/neb/inc/com/centreon/broker/neb/callbacks.hh b/broker/neb/inc/com/centreon/broker/neb/callbacks.hh index d9b325a7a45..c23fca85780 100644 --- a/broker/neb/inc/com/centreon/broker/neb/callbacks.hh +++ b/broker/neb/inc/com/centreon/broker/neb/callbacks.hh @@ -66,6 +66,8 @@ int callback_tag(int callback_type, void* data) noexcept; int callback_pb_bench(int callback_type, void* data); +int callback_otl_metrics(int callback_type, void* data); + void unregister_callbacks(); } // namespace com::centreon::broker::neb diff --git a/broker/neb/inc/com/centreon/broker/neb/internal.hh b/broker/neb/inc/com/centreon/broker/neb/internal.hh index 79e05061537..ac1a00ae8e7 100644 --- a/broker/neb/inc/com/centreon/broker/neb/internal.hh +++ b/broker/neb/inc/com/centreon/broker/neb/internal.hh @@ -27,6 +27,7 @@ #include "com/centreon/broker/io/protobuf.hh" #include "com/centreon/broker/multiplexing/publisher.hh" #include "com/centreon/broker/neb/callback.hh" +#include "opentelemetry/proto/collector/metrics/v1/metrics_service.pb.h" namespace com::centreon::broker { @@ -127,6 +128,10 @@ using pb_instance_configuration = io::protobuf; +using pb_otl_metrics = io::protobuf< + opentelemetry::proto::collector::metrics::v1::ExportMetricsServiceRequest, + make_type(io::storage, storage::de_pb_otl_metrics)>; + } // namespace neb } // namespace com::centreon::broker diff --git a/broker/neb/src/broker.cc b/broker/neb/src/broker.cc index 0e1e1d218ba..7f3641bc259 100644 --- a/broker/neb/src/broker.cc +++ b/broker/neb/src/broker.cc @@ -226,13 +226,13 @@ void broker_module_init(void const* arg) { e.register_event( neb::pb_service_group_member::static_type(), "ServiceGroupMember", &neb::pb_service_group_member::operations, "services_servicegroups"); - e.register_event(neb::pb_host_parent::static_type(), "HostParent", &neb::pb_host_parent::operations, "hosts_hosts_parents"); - e.register_event(neb::pb_instance_configuration::static_type(), "InstanceConfiguration", &neb::pb_instance_configuration::operations, "no_table"); + e.register_event(neb::pb_otl_metrics::static_type(), "OTLMetrics", + &neb::pb_otl_metrics::operations, "otl_metrics"); } } } diff --git a/broker/neb/src/callbacks.cc b/broker/neb/src/callbacks.cc index 60e1fd431a7..38e40617e1d 100644 --- a/broker/neb/src/callbacks.cc +++ b/broker/neb/src/callbacks.cc @@ -22,6 +22,8 @@ #include #include "bbdo/neb.pb.h" +#include "opentelemetry/proto/collector/metrics/v1/metrics_service.pb.h" + #include "com/centreon/broker/bbdo/internal.hh" #include "com/centreon/broker/config/applier/state.hh" #include "com/centreon/broker/config/parser.hh" @@ -109,7 +111,8 @@ static struct { {NEBCALLBACK_SERVICE_CHECK_DATA, &neb::callback_pb_service_check}, {NEBCALLBACK_SERVICE_STATUS_DATA, &neb::callback_pb_service_status}, {NEBCALLBACK_ADAPTIVE_SEVERITY_DATA, &neb::callback_severity}, - {NEBCALLBACK_ADAPTIVE_TAG_DATA, &neb::callback_tag}}; + {NEBCALLBACK_ADAPTIVE_TAG_DATA, &neb::callback_tag}, + {NEBCALLBACK_OTL_METRICS, &neb::callback_otl_metrics}}; // List of Engine-specific callbacks. static struct { @@ -4026,6 +4029,59 @@ int neb::callback_pb_bench(int, void* data) { return 0; } +namespace com::centreon::broker::neb::otl_detail { +/** + * @brief the goal of this little class is to avoid copy of an + * ExportMetricsServiceRequest as callback_otl_metrics receives a + * shared_ptr + * + */ +class otl_protobuf + : public io::protobuf { + std::shared_ptr< + opentelemetry::proto::collector::metrics::v1::ExportMetricsServiceRequest> + _obj; + + public: + otl_protobuf(void* pointer_to_shared_ptr) + : _obj(*static_cast< + std::shared_ptr*>( + pointer_to_shared_ptr)) {} + + const opentelemetry::proto::collector::metrics::v1:: + ExportMetricsServiceRequest& + obj() const override { + return *_obj; + } + + opentelemetry::proto::collector::metrics::v1::ExportMetricsServiceRequest& + mut_obj() override { + return *_obj; + } + + void set_obj(opentelemetry::proto::collector::metrics::v1:: + ExportMetricsServiceRequest&& obj) override { + throw com::centreon::exceptions::msg_fmt("unauthorized usage {}", + typeid(*this).name()); + } +}; + +} // namespace com::centreon::broker::neb::otl_detail + +/** + * @brief send an ExportMetricsServiceRequest to broker + * + * @param data pointer to a shared_ptr + * @return int 0 + */ +int neb::callback_otl_metrics(int, void* data) { + gl_publisher.write(std::make_shared(data)); + return 0; +} + /** * Unregister callbacks. */ diff --git a/broker/victoria_metrics/src/factory.cc b/broker/victoria_metrics/src/factory.cc index 79f3aaa3d37..11a8c2e4743 100644 --- a/broker/victoria_metrics/src/factory.cc +++ b/broker/victoria_metrics/src/factory.cc @@ -56,7 +56,7 @@ factory::factory() io::endpoint* factory::new_endpoint( config::endpoint& cfg, bool& is_acceptor, - std::shared_ptr cache) const { + std::shared_ptr ) const { is_acceptor = false; std::shared_ptr conf( @@ -82,4 +82,4 @@ io::endpoint* factory::new_endpoint( } return new connector(conf, account_id); -} \ No newline at end of file +} diff --git a/common/src/hex_dump.cc b/common/src/hex_dump.cc index 9a2c34caf51..5f879a90e15 100644 --- a/common/src/hex_dump.cc +++ b/common/src/hex_dump.cc @@ -1,20 +1,20 @@ /** -* Copyright 2023 Centreon -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* -* For more information : contact@centreon.com -*/ + * Copyright 2023 Centreon + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * For more information : contact@centreon.com + */ #include "hex_dump.hh" diff --git a/engine/inc/com/centreon/engine/log_v2.hh b/engine/inc/com/centreon/engine/log_v2.hh index 8423065635c..f9d68b737c5 100644 --- a/engine/inc/com/centreon/engine/log_v2.hh +++ b/engine/inc/com/centreon/engine/log_v2.hh @@ -26,7 +26,7 @@ class state; } class log_v2 : public log_v2_base { - std::array, 13> _log; + std::array, 14> _log; std::atomic_bool _running; asio::system_timer _flush_timer; std::mutex _flush_timer_m; @@ -49,6 +49,7 @@ class log_v2 : public log_v2_base { log_macros, log_process, log_runtime, + log_otl }; log_v2(const std::shared_ptr& io_context); @@ -119,6 +120,10 @@ class log_v2 : public log_v2_base { static inline std::shared_ptr runtime() { return _instance->get_logger(log_v2::log_runtime, "runtime"); } + + static inline std::shared_ptr otl() { + return _instance->get_logger(log_v2::log_otl, "otl"); + } }; } // namespace com::centreon::engine diff --git a/engine/inc/com/centreon/engine/nebcallbacks.hh b/engine/inc/com/centreon/engine/nebcallbacks.hh index 299beab0620..d382b6950f7 100644 --- a/engine/inc/com/centreon/engine/nebcallbacks.hh +++ b/engine/inc/com/centreon/engine/nebcallbacks.hh @@ -74,7 +74,8 @@ #define NEBCALLBACK_ADAPTIVE_TAG_DATA 44 #define NEBCALLBACK_BENCH_DATA 45 -#define NEBCALLBACK_NUMITEMS 46 /* Total number of callback types we have. */ +#define NEBCALLBACK_OTL_METRICS 46 +#define NEBCALLBACK_NUMITEMS 47 /* Total number of callback types we have. */ #ifdef __cplusplus extern "C" { diff --git a/tests/README.md b/tests/README.md index a916da59042..148fe569fcc 100644 --- a/tests/README.md +++ b/tests/README.md @@ -22,6 +22,17 @@ yum install "Development Tools" python3-devel -y pip3 install grpcio==1.33.2 grpcio_tools==1.33.2 +#you need also to provide opentelemetry proto files at the project root with this command +git clone https://github.com/open-telemetry/opentelemetry-proto.git opentelemetry-proto + +#Then you must have something like that: +#root directory/bbdo +# /broker +# /engine +# /opentelemetry-proto +# /tests + + ./init-proto.sh ./init-sql.sh ``` diff --git a/tests/init-proto.sh b/tests/init-proto.sh index b4999b72646..33be9f6daa7 100755 --- a/tests/init-proto.sh +++ b/tests/init-proto.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e + cd resources python3 -m grpc_tools.protoc -I../../engine/enginerpc -I../../common/src --python_out=. --grpc_python_out=. engine.proto python3 -m grpc_tools.protoc -I../../broker/core/src -I../../common/src --python_out=. --grpc_python_out=. broker.proto @@ -9,5 +11,10 @@ do python3 -m grpc_tools.protoc -I../../bbdo --python_out=. --grpc_python_out=. `basename $file` done python3 ../../broker/grpc/generate_proto.py -f grpc_stream.proto -c /tmp/not_used.cc -d ../../bbdo -python3 -m grpc_tools.protoc -I. -I../../bbdo --python_out=. --grpc_python_out=. grpc_stream.proto +python3 -m grpc_tools.protoc -I. -I../../bbdo -I../../opentelemetry-proto --python_out=. --grpc_python_out=. grpc_stream.proto + +python3 -m grpc_tools.protoc -I../../opentelemetry-proto --python_out=. --grpc_python_out=. opentelemetry/proto/collector/metrics/v1/metrics_service.proto +python3 -m grpc_tools.protoc -I../../opentelemetry-proto --python_out=. --grpc_python_out=. opentelemetry/proto/metrics/v1/metrics.proto +python3 -m grpc_tools.protoc -I../../opentelemetry-proto --python_out=. --grpc_python_out=. opentelemetry/proto/common/v1/common.proto +python3 -m grpc_tools.protoc -I../../opentelemetry-proto --python_out=. --grpc_python_out=. opentelemetry/proto/resource/v1/resource.proto cd .. diff --git a/tests/update-doc.py b/tests/update-doc.py index 906afaa9e88..1335840e447 100755 --- a/tests/update-doc.py +++ b/tests/update-doc.py @@ -68,6 +68,17 @@ def parse_dir(d): pip3 install grpcio==1.33.2 grpcio_tools==1.33.2 +#you need also to provide opentelemetry proto files at the project root with this command +git clone https://github.com/open-telemetry/opentelemetry-proto.git opentelemetry-proto + +#Then you must have something like that: +#root directory/bbdo +# /broker +# /engine +# /opentelemetry-proto +# /tests + + ./init-proto.sh ./init-sql.sh ```