Skip to content

Commit

Permalink
add opentelemetry bbdo message
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-christophe81 committed May 23, 2024
1 parent e8cf6bd commit 392e8fc
Show file tree
Hide file tree
Showing 22 changed files with 281 additions and 74 deletions.
3 changes: 3 additions & 0 deletions .github/scripts/collect-test-robot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
32 changes: 32 additions & 0 deletions bbdo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions bbdo/events.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions broker/grpc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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})
Expand Down
29 changes: 29 additions & 0 deletions broker/grpc/generate_proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

file_begin_content = """syntax = "proto3";
import "opentelemetry/proto/collector/metrics/v1/metrics_service.proto";
"""

file_message_centreon_event = """
Expand Down Expand Up @@ -213,6 +214,34 @@ class received_protobuf : public io::protobuf<T, Typ> {
"""

#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<detail::received_protobuf<
::opentelemetry::proto::collector::metrics::v1::
ExportMetricsServiceRequest,
make_type(io::storage, storage::de_pb_otl_metrics)>>(
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_with_data>(
event, reinterpret_cast<event_with_data::releaser_type>(
&grpc_event_type::release_exportmetricsservicerequest_));
ret->grpc_event.set_allocated_exportmetricsservicerequest_(
&std::static_pointer_cast<io::protobuf<
::opentelemetry::proto::collector::metrics::v1::
ExportMetricsServiceRequest,
make_type(io::storage, storage::de_pb_otl_metrics)>>(event)
->mut_obj());
break;
"""

with open(args.proto_file, 'w', encoding="utf-8") as fp:
fp.write(file_begin_content)
fp.write("""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -212,6 +212,6 @@ class line_protocol_query {
};
} // namespace http_tsdb

}
} // namespace com::centreon::broker

#endif // !CCB_HTTP_TSDB_LINE_PROTOCOL_QUERY_HH
Loading

0 comments on commit 392e8fc

Please sign in to comment.