Skip to content

Commit

Permalink
Fix gRPC static build script
Browse files Browse the repository at this point in the history
Signed-off-by: owent <admin@owent.net>
  • Loading branch information
owent committed Mar 20, 2023
1 parent dff5da5 commit e497b24
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 41 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,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 @@ -217,6 +217,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
1 change: 1 addition & 0 deletions exporters/otlp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -409,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 @@ -67,6 +67,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
84 changes: 61 additions & 23 deletions exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@

# include <unordered_map>

# include "opentelemetry/exporters/otlp/otlp_grpc_exporter.h"
# include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h"

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

# include "opentelemetry/proto/collector/logs/v1/logs_service_mock.grpc.pb.h"
# include "opentelemetry/proto/collector/trace/v1/trace_service_mock.grpc.pb.h"

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

Expand All @@ -18,6 +20,10 @@
# include "opentelemetry/sdk/logs/exporter.h"
# include "opentelemetry/sdk/logs/logger_provider.h"
# include "opentelemetry/sdk/resource/resource.h"
# include "opentelemetry/sdk/trace/exporter.h"
# include "opentelemetry/sdk/trace/simple_processor_factory.h"
# include "opentelemetry/sdk/trace/tracer_provider_factory.h"
# include "opentelemetry/trace/provider.h"

# include <gtest/gtest.h>

Expand Down Expand Up @@ -45,6 +51,13 @@ class OtlpGrpcLogRecordExporterTestPeer : public ::testing::Test
new OtlpGrpcLogRecordExporter(std::move(stub_interface)));
}

std::unique_ptr<sdk::trace::SpanExporter> GetExporter(
std::unique_ptr<proto::collector::trace::v1::TraceService::StubInterface> &stub_interface)
{
return std::unique_ptr<sdk::trace::SpanExporter>(
new OtlpGrpcExporter(std::move(stub_interface)));
}

// Get the options associated with the given exporter.
const OtlpGrpcExporterOptions &GetOptions(std::unique_ptr<OtlpGrpcLogRecordExporter> &exporter)
{
Expand Down Expand Up @@ -135,29 +148,54 @@ TEST_F(OtlpGrpcLogRecordExporterTestPeer, ExportIntegrationTest)
'3', '2', '1', '0'};
opentelemetry::trace::SpanId span_id{span_id_bin};

const std::string schema_url{"https://opentelemetry.io/schemas/1.11.0"};
auto logger = provider->GetLogger("test", "opentelelemtry_library", "", schema_url, true,
{{"scope_key1", "scope_value"}, {"scope_key2", 2}});
std::unordered_map<std::string, opentelemetry::v1::common::AttributeValue> attributes;
attributes["service.name"] = "unit_test_service";
attributes["tenant.id"] = "test_user";
attributes["bool_value"] = true;
attributes["int32_value"] = static_cast<int32_t>(1);
attributes["uint32_value"] = static_cast<uint32_t>(2);
attributes["int64_value"] = static_cast<int64_t>(0x1100000000LL);
attributes["uint64_value"] = static_cast<uint64_t>(0x1200000000ULL);
attributes["double_value"] = static_cast<double>(3.1);
attributes["vec_bool_value"] = attribute_storage_bool_value;
attributes["vec_int32_value"] = attribute_storage_int32_value;
attributes["vec_uint32_value"] = attribute_storage_uint32_value;
attributes["vec_int64_value"] = attribute_storage_int64_value;
attributes["vec_uint64_value"] = attribute_storage_uint64_value;
attributes["vec_double_value"] = attribute_storage_double_value;
attributes["vec_string_value"] = attribute_storage_string_value;
logger->EmitLogRecord(
opentelemetry::logs::Severity::kInfo, "Log message", attributes, trace_id, span_id,
opentelemetry::trace::TraceFlags{opentelemetry::trace::TraceFlags::kIsSampled},
std::chrono::system_clock::now());
auto trace_mock_stub = new proto::collector::trace::v1::MockTraceServiceStub();
std::unique_ptr<proto::collector::trace::v1::TraceService::StubInterface> trace_stub_interface(
trace_mock_stub);

auto trace_provider = opentelemetry::nostd::shared_ptr<opentelemetry::v1::trace::TracerProvider>(
opentelemetry::sdk::trace::TracerProviderFactory::Create(
opentelemetry::sdk::trace::SimpleSpanProcessorFactory::Create(
GetExporter(trace_stub_interface))));

// Trace and Logs should both receive datas when links static gRPC on ELF ABI.
EXPECT_CALL(*trace_mock_stub, Export(_, _, _))
.Times(AtLeast(1))
.WillRepeatedly(Return(grpc::Status::OK));

{
const std::string schema_url{"https://opentelemetry.io/schemas/1.11.0"};

auto tracer = trace_provider->GetTracer("opentelelemtry_library", "", schema_url);
opentelemetry::trace::Provider::SetTracerProvider(std::move(trace_provider));
auto trace_span = tracer->StartSpan("test_log");
opentelemetry::trace::Scope trace_scope{trace_span};

auto logger = provider->GetLogger("test", "opentelelemtry_library", "", schema_url, true,
{{"scope_key1", "scope_value"}, {"scope_key2", 2}});
std::unordered_map<std::string, opentelemetry::v1::common::AttributeValue> attributes;
attributes["service.name"] = "unit_test_service";
attributes["tenant.id"] = "test_user";
attributes["bool_value"] = true;
attributes["int32_value"] = static_cast<int32_t>(1);
attributes["uint32_value"] = static_cast<uint32_t>(2);
attributes["int64_value"] = static_cast<int64_t>(0x1100000000LL);
attributes["uint64_value"] = static_cast<uint64_t>(0x1200000000ULL);
attributes["double_value"] = static_cast<double>(3.1);
attributes["vec_bool_value"] = attribute_storage_bool_value;
attributes["vec_int32_value"] = attribute_storage_int32_value;
attributes["vec_uint32_value"] = attribute_storage_uint32_value;
attributes["vec_int64_value"] = attribute_storage_int64_value;
attributes["vec_uint64_value"] = attribute_storage_uint64_value;
attributes["vec_double_value"] = attribute_storage_double_value;
attributes["vec_string_value"] = attribute_storage_string_value;
logger->EmitLogRecord(opentelemetry::logs::Severity::kInfo, "Log message", attributes,
trace_span->GetContext(), std::chrono::system_clock::now());
}

opentelemetry::trace::Provider::SetTracerProvider(
opentelemetry::nostd::shared_ptr<opentelemetry::trace::TracerProvider>(
new opentelemetry::trace::NoopTracerProvider()));
trace_provider = opentelemetry::nostd::shared_ptr<opentelemetry::v1::trace::TracerProvider>();
}

} // namespace otlp
Expand Down

0 comments on commit e497b24

Please sign in to comment.