Skip to content

Commit

Permalink
Merge branch 'main' into marc_cpp_maintainer
Browse files Browse the repository at this point in the history
  • Loading branch information
marcalff authored Apr 14, 2023
2 parents beb03cf + 6a3ee16 commit a2da096
Show file tree
Hide file tree
Showing 13 changed files with 259 additions and 60 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,22 @@ jobs:
sudo ./ci/setup_grpc.sh
./ci/do_ci.sh cmake.do_not_install.test
cmake_otprotocol_shared_libs_with_static_grpc_test:
name: CMake test (build shared libraries with otlp-exporter and static gRPC)
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: setup
run: |
sudo ./ci/setup_cmake.sh
sudo ./ci/setup_ci_environment.sh
- name: run otlp exporter tests
run: |
sudo ./ci/setup_grpc.sh -T
./ci/do_ci.sh cmake.exporter.otprotocol.shared_libs.with_static_grpc.test
plugin_test:
name: Plugin -> CMake
runs-on: ubuntu-latest
Expand Down
5 changes: 4 additions & 1 deletion bazel/repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ def opentelemetry_cpp_deps():
build_file = "@io_opentelemetry_cpp//bazel:curl.BUILD",
sha256 = "ba98332752257b47b9dea6d8c0ad25ec1745c20424f1dd3ff2c99ab59e97cf91",
strip_prefix = "curl-7.73.0",
urls = ["https://curl.haxx.se/download/curl-7.73.0.tar.gz"],
urls = [
"https://curl.haxx.se/download/curl-7.73.0.tar.gz",
"https://github.com/curl/curl/releases/download/curl-7_73_0/curl-7.73.0.tar.gz",
],
)

# libthrift (optional)
Expand Down
14 changes: 14 additions & 0 deletions ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,20 @@ elif [[ "$1" == "cmake.exporter.otprotocol.test" ]]; then
make -j $(nproc)
cd exporters/otlp && make test
exit 0
elif [[ "$1" == "cmake.exporter.otprotocol.shared_libs.with_static_grpc.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
cmake -DCMAKE_BUILD_TYPE=Debug \
-DWITH_OTLP=ON \
-DWITH_OTLP_HTTP=ON \
-DBUILD_SHARED_LIBS=ON \
"${SRC_DIR}"
grpc_cpp_plugin=`which grpc_cpp_plugin`
proto_make_file="CMakeFiles/opentelemetry_proto.dir/build.make"
sed -i "s~gRPC_CPP_PLUGIN_EXECUTABLE-NOTFOUND~$grpc_cpp_plugin~" ${proto_make_file} #fixme
make -j $(nproc)
cd exporters/otlp && make test
exit 0
elif [[ "$1" == "cmake.exporter.otprotocol.with_async_export.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
Expand Down
49 changes: 35 additions & 14 deletions ci/setup_grpc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ new_grpc_version='v1.49.2'
gcc_version_for_new_grpc='5.1'
std_version='14'
install_grpc_version=${new_grpc_version}
grpc_version='v1.39.0'
install_dir='/usr/local/'
build_shared_libs=''
usage() { echo "Usage: $0 [-v <gcc-version>] [-i <install_dir>"] 1>&2; exit 1;}

while getopts ":v:i:r:s:" o; do
while getopts ":v:i:r:s:TH" o; do
case "${o}" in
v)
gcc_version=${OPTARG}
Expand All @@ -28,6 +28,12 @@ while getopts ":v:i:r:s:" o; do
s)
std_version=${OPTARG}
;;
T)
build_shared_libs="OFF"
;;
H)
build_shared_libs="ON"
;;
*)
usage
;;
Expand All @@ -54,19 +60,34 @@ pushd grpc
git submodule init
git submodule update --depth 1
mkdir -p "third_party/abseil-cpp/build" && pushd "third_party/abseil-cpp/build"
cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_POSITION_INDEPENDENT_CODE=TRUE \
-DCMAKE_INSTALL_PREFIX=$INSTALL_DIR ..
make -j${nproc} install && popd
set -x

ABSEIL_CPP_BUILD_OPTIONS=(
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_POSITION_INDEPENDENT_CODE=TRUE
-DCMAKE_INSTALL_PREFIX=$INSTALL_DIR
)
if [ ! -z "$build_shared_libs" ]; then
ABSEIL_CPP_BUILD_OPTIONS=(${ABSEIL_CPP_BUILD_OPTIONS[@]} "-DBUILD_SHARED_LIBS=$build_shared_libs")
fi
cmake ${ABSEIL_CPP_BUILD_OPTIONS[@]} ..
cmake --build . -j${nproc} --target install && popd
mkdir -p build && pushd build
cmake -DgRPC_INSTALL=ON \
-DCMAKE_CXX_STANDARD=${std_version} \
-DgRPC_BUILD_TESTS=OFF \
-DCMAKE_INSTALL_PREFIX=$INSTALL_DIR \
-DCMAKE_PREFIX_PATH=$INSTALL_DIR \
..
make -j $(nproc)
make install

GRPC_BUILD_OPTIONS=(
-DgRPC_INSTALL=ON
-DCMAKE_CXX_STANDARD=${std_version}
-DgRPC_BUILD_TESTS=OFF
-DCMAKE_INSTALL_PREFIX=$INSTALL_DIR
-DCMAKE_PREFIX_PATH=$INSTALL_DIR
)
if [ ! -z "$build_shared_libs" ]; then
GRPC_BUILD_OPTIONS=(${GRPC_BUILD_OPTIONS[@]} "-DBUILD_SHARED_LIBS=$build_shared_libs")
fi

cmake ${GRPC_BUILD_OPTIONS[@]} ..
cmake --build . -j$(nproc)
cmake --install .
popd
popd

Expand Down
5 changes: 4 additions & 1 deletion exporters/otlp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ cc_library(
"//sdk/src/common:global_log_handler",
"@com_github_grpc_grpc//:grpc++",
"@com_github_opentelemetry_proto//:common_proto_cc",
"@com_github_opentelemetry_proto//:logs_service_grpc_cc",
"@com_github_opentelemetry_proto//:metrics_service_grpc_cc",
"@com_github_opentelemetry_proto//:trace_service_grpc_cc",
],
)

Expand Down Expand Up @@ -268,7 +271,6 @@ cc_library(
":otlp_grpc_client",
"//ext:headers",
"//sdk/src/logs",
"@com_github_opentelemetry_proto//:logs_service_proto_cc",
# For gRPC
"@com_github_opentelemetry_proto//:logs_service_grpc_cc",
],
Expand Down Expand Up @@ -407,6 +409,7 @@ cc_test(
"test",
],
deps = [
":otlp_grpc_exporter",
":otlp_grpc_log_record_exporter",
"//api",
"//sdk/src/logs",
Expand Down
11 changes: 8 additions & 3 deletions exporters/otlp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,14 @@ if(BUILD_TESTING)
add_executable(otlp_grpc_log_record_exporter_test
test/otlp_grpc_log_record_exporter_test.cc)
target_link_libraries(
otlp_grpc_log_record_exporter_test ${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT} ${GMOCK_LIB}
opentelemetry_exporter_otlp_grpc_log opentelemetry_logs)
otlp_grpc_log_record_exporter_test
${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
${GMOCK_LIB}
opentelemetry_exporter_otlp_grpc
opentelemetry_exporter_otlp_grpc_log
opentelemetry_trace
opentelemetry_logs)
gtest_add_tests(
TARGET otlp_grpc_log_record_exporter_test
TEST_PREFIX exporter.otlp.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@

#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h"

#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h"

#include "opentelemetry/proto/collector/metrics/v1/metrics_service.grpc.pb.h"
#include "opentelemetry/proto/collector/trace/v1/trace_service.grpc.pb.h"

#ifdef ENABLE_LOGS_PREVIEW
# include "opentelemetry/proto/collector/logs/v1/logs_service.grpc.pb.h"
#endif

#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
{
Expand All @@ -33,14 +44,49 @@ class OtlpGrpcClient
const OtlpGrpcExporterOptions &options);

/**
* Create service stub to communicate with the OpenTelemetry Collector.
* Create gRPC CompletionQueue to async call RPC.
*/
static std::unique_ptr<grpc::CompletionQueue> MakeCompletionQueue();

/**
* Create trace service stub to communicate with the OpenTelemetry Collector.
*/
static std::unique_ptr<proto::collector::trace::v1::TraceService::StubInterface>
MakeTraceServiceStub(const OtlpGrpcExporterOptions &options);

/**
* Create metrics service stub to communicate with the OpenTelemetry Collector.
*/
static std::unique_ptr<proto::collector::metrics::v1::MetricsService::StubInterface>
MakeMetricsServiceStub(const OtlpGrpcExporterOptions &options);

#ifdef ENABLE_LOGS_PREVIEW
/**
* Create logs service stub to communicate with the OpenTelemetry Collector.
*/
template <class ServiceType>
static std::unique_ptr<typename ServiceType::Stub> MakeServiceStub(
const OtlpGrpcExporterOptions &options)
{
return ServiceType::NewStub(MakeChannel(options));
}
static std::unique_ptr<proto::collector::logs::v1::LogsService::StubInterface>
MakeLogsServiceStub(const OtlpGrpcExporterOptions &options);
#endif

static grpc::Status DelegateExport(
proto::collector::trace::v1::TraceService::StubInterface *stub,
grpc::ClientContext *context,
const proto::collector::trace::v1::ExportTraceServiceRequest &request,
proto::collector::trace::v1::ExportTraceServiceResponse *response);

static grpc::Status DelegateExport(
proto::collector::metrics::v1::MetricsService::StubInterface *stub,
grpc::ClientContext *context,
const proto::collector::metrics::v1::ExportMetricsServiceRequest &request,
proto::collector::metrics::v1::ExportMetricsServiceResponse *response);

#ifdef ENABLE_LOGS_PREVIEW
static grpc::Status DelegateExport(
proto::collector::logs::v1::LogsService::StubInterface *stub,
grpc::ClientContext *context,
const proto::collector::logs::v1::ExportLogsServiceRequest &request,
proto::collector::logs::v1::ExportLogsServiceResponse *response);
#endif
};
} // namespace otlp
} // namespace exporter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class OtlpGrpcExporter final : public opentelemetry::sdk::trace::SpanExporter

// For testing
friend class OtlpGrpcExporterTestPeer;
friend class OtlpGrpcLogRecordExporterTestPeer;

// Store service stub internally. Useful for testing.
std::unique_ptr<proto::collector::trace::v1::TraceService::StubInterface> trace_service_stub_;
Expand Down
54 changes: 54 additions & 0 deletions exporters/otlp/src/otlp_grpc_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,60 @@ std::unique_ptr<grpc::ClientContext> OtlpGrpcClient::MakeClientContext(
return context;
}

std::unique_ptr<grpc::CompletionQueue> OtlpGrpcClient::MakeCompletionQueue()
{
return std::unique_ptr<grpc::CompletionQueue>(new grpc::CompletionQueue());
}

std::unique_ptr<proto::collector::trace::v1::TraceService::StubInterface>
OtlpGrpcClient::MakeTraceServiceStub(const OtlpGrpcExporterOptions &options)
{
return proto::collector::trace::v1::TraceService::NewStub(MakeChannel(options));
}

std::unique_ptr<proto::collector::metrics::v1::MetricsService::StubInterface>
OtlpGrpcClient::MakeMetricsServiceStub(const OtlpGrpcExporterOptions &options)
{
return proto::collector::metrics::v1::MetricsService::NewStub(MakeChannel(options));
}

#ifdef ENABLE_LOGS_PREVIEW
std::unique_ptr<proto::collector::logs::v1::LogsService::StubInterface>
OtlpGrpcClient::MakeLogsServiceStub(const OtlpGrpcExporterOptions &options)
{
return proto::collector::logs::v1::LogsService::NewStub(MakeChannel(options));
}
#endif

grpc::Status OtlpGrpcClient::DelegateExport(
proto::collector::trace::v1::TraceService::StubInterface *stub,
grpc::ClientContext *context,
const proto::collector::trace::v1::ExportTraceServiceRequest &request,
proto::collector::trace::v1::ExportTraceServiceResponse *response)
{
return stub->Export(context, request, response);
}

grpc::Status OtlpGrpcClient::DelegateExport(
proto::collector::metrics::v1::MetricsService::StubInterface *stub,
grpc::ClientContext *context,
const proto::collector::metrics::v1::ExportMetricsServiceRequest &request,
proto::collector::metrics::v1::ExportMetricsServiceResponse *response)
{
return stub->Export(context, request, response);
}

#ifdef ENABLE_LOGS_PREVIEW
grpc::Status OtlpGrpcClient::DelegateExport(
proto::collector::logs::v1::LogsService::StubInterface *stub,
grpc::ClientContext *context,
const proto::collector::logs::v1::ExportLogsServiceRequest &request,
proto::collector::logs::v1::ExportLogsServiceResponse *response)
{
return stub->Export(context, request, response);
}
#endif

} // namespace otlp
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE
7 changes: 3 additions & 4 deletions exporters/otlp/src/otlp_grpc_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ namespace otlp
OtlpGrpcExporter::OtlpGrpcExporter() : OtlpGrpcExporter(OtlpGrpcExporterOptions()) {}

OtlpGrpcExporter::OtlpGrpcExporter(const OtlpGrpcExporterOptions &options)
: options_(options),
trace_service_stub_(
OtlpGrpcClient::MakeServiceStub<proto::collector::trace::v1::TraceService>(options))
: options_(options), trace_service_stub_(OtlpGrpcClient::MakeTraceServiceStub(options))
{}

OtlpGrpcExporter::OtlpGrpcExporter(
Expand Down Expand Up @@ -60,7 +58,8 @@ sdk::common::ExportResult OtlpGrpcExporter::Export(
auto context = OtlpGrpcClient::MakeClientContext(options_);
proto::collector::trace::v1::ExportTraceServiceResponse response;

grpc::Status status = trace_service_stub_->Export(context.get(), request, &response);
grpc::Status status =
OtlpGrpcClient::DelegateExport(trace_service_stub_.get(), context.get(), request, &response);

if (!status.ok())
{
Expand Down
7 changes: 3 additions & 4 deletions exporters/otlp/src/otlp_grpc_log_record_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ OtlpGrpcLogRecordExporter::OtlpGrpcLogRecordExporter()
{}

OtlpGrpcLogRecordExporter::OtlpGrpcLogRecordExporter(const OtlpGrpcExporterOptions &options)
: options_(options),
log_service_stub_(
OtlpGrpcClient::MakeServiceStub<proto::collector::logs::v1::LogsService>(options))
: options_(options), log_service_stub_(OtlpGrpcClient::MakeLogsServiceStub(options))
{}

OtlpGrpcLogRecordExporter::OtlpGrpcLogRecordExporter(
Expand Down Expand Up @@ -74,7 +72,8 @@ opentelemetry::sdk::common::ExportResult OtlpGrpcLogRecordExporter::Export(
auto context = OtlpGrpcClient::MakeClientContext(options_);
proto::collector::logs::v1::ExportLogsServiceResponse response;

grpc::Status status = log_service_stub_->Export(context.get(), request, &response);
grpc::Status status =
OtlpGrpcClient::DelegateExport(log_service_stub_.get(), context.get(), request, &response);

if (!status.ok())
{
Expand Down
6 changes: 3 additions & 3 deletions exporters/otlp/src/otlp_grpc_metric_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ OtlpGrpcMetricExporter::OtlpGrpcMetricExporter(const OtlpGrpcMetricExporterOptio
: options_(options),
aggregation_temporality_selector_{
OtlpMetricUtils::ChooseTemporalitySelector(options_.aggregation_temporality)},
metrics_service_stub_(
OtlpGrpcClient::MakeServiceStub<proto::collector::metrics::v1::MetricsService>(options))
metrics_service_stub_(OtlpGrpcClient::MakeMetricsServiceStub(options))
{}

OtlpGrpcMetricExporter::OtlpGrpcMetricExporter(
Expand Down Expand Up @@ -67,7 +66,8 @@ opentelemetry::sdk::common::ExportResult OtlpGrpcMetricExporter::Export(
auto context = OtlpGrpcClient::MakeClientContext(options_);
proto::collector::metrics::v1::ExportMetricsServiceResponse response;

grpc::Status status = metrics_service_stub_->Export(context.get(), request, &response);
grpc::Status status = OtlpGrpcClient::DelegateExport(metrics_service_stub_.get(), context.get(),
request, &response);

if (!status.ok())
{
Expand Down
Loading

0 comments on commit a2da096

Please sign in to comment.