diff --git a/CMakeLists.txt b/CMakeLists.txt index 8faf34698dd..da7f86b73c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -224,7 +224,7 @@ set(gRPC_ABSL_USED_TARGETS absl_meta ) -# The OpenTelemetry plugin support "package" build only at present. +# The OpenTelemetry plugin supports "package" build only at present. set(gRPC_OPENTELEMETRY_PROVIDER "package") # set(gRPC_OPENTELEMETRY_PROVIDER "module" CACHE STRING "Provider of opentelemetry library") # set_property(CACHE gRPC_OPENTELEMETRY_PROVIDER PROPERTY STRINGS "module" "package") @@ -1211,6 +1211,7 @@ if(gRPC_BUILD_TESTS) add_dependencies(buildtests_cxx orca_service_end2end_test) add_dependencies(buildtests_cxx orphanable_test) add_dependencies(buildtests_cxx osa_distance_test) + add_dependencies(buildtests_cxx otel_plugin_test) add_dependencies(buildtests_cxx out_of_bounds_bad_client_test) add_dependencies(buildtests_cxx outlier_detection_lb_config_parser_test) add_dependencies(buildtests_cxx outlier_detection_test) @@ -20581,6 +20582,72 @@ target_link_libraries(osa_distance_test ) +endif() +if(gRPC_BUILD_TESTS) + +add_executable(otel_plugin_test + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.grpc.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_messages.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_messages.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_messages.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_messages.grpc.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/simple_messages.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/simple_messages.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/simple_messages.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/simple_messages.grpc.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/xds/v3/orca_load_report.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/xds/v3/orca_load_report.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/xds/v3/orca_load_report.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/xds/v3/orca_load_report.grpc.pb.h + src/cpp/ext/otel/otel_client_filter.cc + src/cpp/ext/otel/otel_plugin.cc + src/cpp/ext/otel/otel_server_call_tracer.cc + test/cpp/end2end/test_service_impl.cc + test/cpp/ext/otel/otel_plugin_test.cc + test/cpp/ext/otel/otel_test_library.cc +) +if(WIN32 AND MSVC) + if(BUILD_SHARED_LIBS) + target_compile_definitions(otel_plugin_test + PRIVATE + "GPR_DLL_IMPORTS" + "GRPC_DLL_IMPORTS" + "GRPCXX_DLL_IMPORTS" + ) + endif() +endif() +target_compile_features(otel_plugin_test PUBLIC cxx_std_14) +target_include_directories(otel_plugin_test + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} + ${_gRPC_RE2_INCLUDE_DIR} + ${_gRPC_SSL_INCLUDE_DIR} + ${_gRPC_UPB_GENERATED_DIR} + ${_gRPC_UPB_GRPC_GENERATED_DIR} + ${_gRPC_UPB_INCLUDE_DIR} + ${_gRPC_XXHASH_INCLUDE_DIR} + ${_gRPC_ZLIB_INCLUDE_DIR} + third_party/googletest/googletest/include + third_party/googletest/googletest + third_party/googletest/googlemock/include + third_party/googletest/googlemock + ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(otel_plugin_test + ${_gRPC_ALLTARGETS_LIBRARIES} + gtest + opentelemetry-cpp::api + opentelemetry-cpp::metrics + grpc++_test_util +) + + endif() if(gRPC_BUILD_TESTS) diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index 967ad017f7d..3cb6888bbe3 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -13189,6 +13189,34 @@ targets: - test/core/util/osa_distance_test.cc deps: - gtest +- name: otel_plugin_test + gtest: true + build: test + language: c++ + headers: + - src/cpp/ext/otel/key_value_iterable.h + - src/cpp/ext/otel/otel_call_tracer.h + - src/cpp/ext/otel/otel_client_filter.h + - src/cpp/ext/otel/otel_plugin.h + - src/cpp/ext/otel/otel_server_call_tracer.h + - test/cpp/end2end/test_service_impl.h + - test/cpp/ext/otel/otel_test_library.h + src: + - src/proto/grpc/testing/echo.proto + - src/proto/grpc/testing/echo_messages.proto + - src/proto/grpc/testing/simple_messages.proto + - src/proto/grpc/testing/xds/v3/orca_load_report.proto + - src/cpp/ext/otel/otel_client_filter.cc + - src/cpp/ext/otel/otel_plugin.cc + - src/cpp/ext/otel/otel_server_call_tracer.cc + - test/cpp/end2end/test_service_impl.cc + - test/cpp/ext/otel/otel_plugin_test.cc + - test/cpp/ext/otel/otel_test_library.cc + deps: + - gtest + - opentelemetry-cpp::api + - opentelemetry-cpp::metrics + - grpc++_test_util - name: out_of_bounds_bad_client_test gtest: true build: test diff --git a/templates/CMakeLists.txt.template b/templates/CMakeLists.txt.template index e94c05d06c1..a074696e570 100644 --- a/templates/CMakeLists.txt.template +++ b/templates/CMakeLists.txt.template @@ -361,7 +361,7 @@ absl_meta ) - # The OpenTelemetry plugin support "package" build only at present. + # The OpenTelemetry plugin supports "package" build only at present. set(gRPC_OPENTELEMETRY_PROVIDER "package") # set(gRPC_OPENTELEMETRY_PROVIDER "module" CACHE STRING "Provider of opentelemetry library") # set_property(CACHE gRPC_OPENTELEMETRY_PROVIDER PROPERTY STRINGS "module" "package") diff --git a/test/cpp/ext/otel/otel_test_library.h b/test/cpp/ext/otel/otel_test_library.h index 8e800d1e30f..11d6d3117a2 100644 --- a/test/cpp/ext/otel/otel_test_library.h +++ b/test/cpp/ext/otel/otel_test_library.h @@ -19,6 +19,8 @@ #ifndef GRPC_TEST_CPP_EXT_OTEL_OTEL_TEST_LIBRARY_H #define GRPC_TEST_CPP_EXT_OTEL_OTEL_TEST_LIBRARY_H +#include + #include "absl/functional/any_invocable.h" #include "gmock/gmock.h" #include "gtest/gtest.h" diff --git a/tools/buildgen/extract_metadata_from_bazel_xml.py b/tools/buildgen/extract_metadata_from_bazel_xml.py index 85b168a9822..bcf57fab2c4 100755 --- a/tools/buildgen/extract_metadata_from_bazel_xml.py +++ b/tools/buildgen/extract_metadata_from_bazel_xml.py @@ -835,8 +835,7 @@ def _exclude_unwanted_cc_tests(tests: List[str]) -> List[str]: tests = [ test for test in tests - if not test.startswith("test/cpp/ext/otel:") - and not test.startswith("test/cpp/ext/csm:") + if not test.startswith("test/cpp/ext/csm:") and not test.startswith("test/cpp/interop:xds_interop") ] diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index 49f6bb44395..8965c31bb25 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -6455,6 +6455,30 @@ ], "uses_polling": true }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": true, + "language": "c++", + "name": "otel_plugin_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": true + }, { "args": [], "benchmark": false, diff --git a/tools/run_tests/helper_scripts/build_cxx.bat b/tools/run_tests/helper_scripts/build_cxx.bat index 63c1b641779..2f9d59115f7 100644 --- a/tools/run_tests/helper_scripts/build_cxx.bat +++ b/tools/run_tests/helper_scripts/build_cxx.bat @@ -16,11 +16,6 @@ setlocal cd /d %~dp0\..\..\.. -mkdir cmake -cd cmake -mkdir build -cd build - If "%GRPC_BUILD_ACTIVATE_VS_TOOLS%" == "2019" ( @rem set cl.exe build environment to build with VS2019 tooling @rem this is required for Ninja build to work @@ -49,20 +44,63 @@ If "%GRPC_CMAKE_GENERATOR%" == "Visual Studio 16 2019" ( If "%GRPC_CMAKE_GENERATOR%" == "Ninja" ( @rem Use ninja - @rem Select MSVC compiler (cl.exe) explicitly to make sure we don't end up gcc from mingw or cygwin @rem (both are on path in kokoro win workers) - cmake -G "%GRPC_CMAKE_GENERATOR%" -DCMAKE_C_COMPILER="cl.exe" -DCMAKE_CXX_COMPILER="cl.exe" -DgRPC_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE="%MSBUILD_CONFIG%" %* ../.. || goto :error + + @rem Install abseil-cpp since opentelemetry CMake uses find_package to find it. + cd third_party/abseil-cpp + mkdir build + cd build + cmake -G "%GRPC_CMAKE_GENERATOR%" -DCMAKE_C_COMPILER="cl.exe" -DCMAKE_CXX_COMPILER="cl.exe" -DABSL_BUILD_TESTING=OFF -DCMAKE_BUILD_TYPE="%MSBUILD_CONFIG%" %* .. || goto :error + ninja -j%GRPC_RUN_TESTS_JOBS% install || goto :error + + @rem Install opentelemetry-cpp since we only support "package" mode for opentelemetry at present. + cd ../../.. + cd third_party/opentelemetry-cpp + mkdir build + cd build + cmake -G "%GRPC_CMAKE_GENERATOR%" -DCMAKE_C_COMPILER="cl.exe" -DCMAKE_CXX_COMPILER="cl.exe" -DWITH_ABSEIL=ON -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE="%MSBUILD_CONFIG%" %* .. || goto :error + ninja -j%GRPC_RUN_TESTS_JOBS% install || goto :error + + cd ../../.. + + mkdir cmake + cd cmake + mkdir build + cd build + + cmake -G "%GRPC_CMAKE_GENERATOR%" -DCMAKE_C_COMPILER="cl.exe" -DCMAKE_CXX_COMPILER="cl.exe" -DgRPC_BUILD_GRPCPP_OTEL_PLUGIN=ON -DgRPC_ABSL_PROVIDER=package -DgRPC_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE="%MSBUILD_CONFIG%" %* ../.. || goto :error ninja -j%GRPC_RUN_TESTS_JOBS% buildtests_%GRPC_RUN_TESTS_CXX_LANGUAGE_SUFFIX% || goto :error ) else ( @rem Use one of the Visual Studio generators. - cmake -G "%GRPC_CMAKE_GENERATOR%" -A "%GRPC_CMAKE_ARCHITECTURE%" %CMAKE_SYSTEM_VERSION_ARG% -DCMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE=x64 -DgRPC_BUILD_TESTS=ON -DgRPC_BUILD_MSVC_MP_COUNT=%GRPC_RUN_TESTS_JOBS% %* ../.. || goto :error + @rem Install abseil-cpp since opentelemetry CMake uses find_package to find it. + cd third_party/abseil-cpp + mkdir build + cd build + cmake -G "%GRPC_CMAKE_GENERATOR%" -A "%GRPC_CMAKE_ARCHITECTURE%" %CMAKE_SYSTEM_VERSION_ARG% -DCMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE=x64 -DABSL_BUILD_TESTING=OFF .. || goto :error + cmake --build . --target install || goto :error + + @rem Install opentelemetry-cpp since we only support "package" mode for opentelemetry at present. + cd ../../.. + cd third_party/opentelemetry-cpp + mkdir build + cd build + cmake -G "%GRPC_CMAKE_GENERATOR%" -A "%GRPC_CMAKE_ARCHITECTURE%" %CMAKE_SYSTEM_VERSION_ARG% -DCMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE=x64 -DWITH_ABSEIL=ON -DBUILD_TESTING=OFF .. || goto :error + cmake --build . --target install -j%GRPC_RUN_TESTS_JOBS% || goto :error + + cd ../../.. + mkdir cmake + cd cmake + mkdir build + cd build + + cmake -G "%GRPC_CMAKE_GENERATOR%" -A "%GRPC_CMAKE_ARCHITECTURE%" %CMAKE_SYSTEM_VERSION_ARG% -DCMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE=x64 -DgRPC_BUILD_GRPCPP_OTEL_PLUGIN=ON -DgRPC_ABSL_PROVIDER=package -DgRPC_BUILD_TESTS=ON -DgRPC_BUILD_MSVC_MP_COUNT=%GRPC_RUN_TESTS_JOBS% %* ../.. || goto :error @rem GRPC_RUN_TESTS_CXX_LANGUAGE_SUFFIX will be set to either "c" or "cxx" - cmake --build . --target buildtests_%GRPC_RUN_TESTS_CXX_LANGUAGE_SUFFIX% --config %MSBUILD_CONFIG% || goto :error + cmake --build . --target buildtests_%GRPC_RUN_TESTS_CXX_LANGUAGE_SUFFIX% --config %MSBUILD_CONFIG% -j%GRPC_RUN_TESTS_JOBS% || goto :error ) endlocal diff --git a/tools/run_tests/helper_scripts/build_cxx.sh b/tools/run_tests/helper_scripts/build_cxx.sh index 310da2e9ae0..882123e4093 100755 --- a/tools/run_tests/helper_scripts/build_cxx.sh +++ b/tools/run_tests/helper_scripts/build_cxx.sh @@ -15,13 +15,32 @@ set -ex +# Set install path to avoid installing to system paths cd "$(dirname "$0")/../../.." +mkdir -p cmake/install +INSTALL_PATH="$(pwd)/cmake/install" +# Install abseil-cpp since opentelemetry CMake uses find_package to find it. +cd third_party/abseil-cpp +mkdir build +cd build +cmake -DCMAKE_CXX_STANDARD=14 -DABSL_BUILD_TESTING=OFF -DCMAKE_BUILD_TYPE="${MSBUILD_CONFIG}" -DCMAKE_INSTALL_PREFIX="${INSTALL_PATH}" "$@" .. +make -j"${GRPC_RUN_TESTS_JOBS}" install + +# Install opentelemetry-cpp since we only support "package" mode for opentelemetry at present. +cd ../../.. +cd third_party/opentelemetry-cpp +mkdir build +cd build +cmake -DCMAKE_CXX_STANDARD=14 -DWITH_ABSEIL=ON -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE="${MSBUILD_CONFIG}" -DCMAKE_INSTALL_PREFIX="${INSTALL_PATH}" "$@" .. +make -j"${GRPC_RUN_TESTS_JOBS}" install + +cd ../../.. mkdir -p cmake/build cd cmake/build # MSBUILD_CONFIG's values are suitable for cmake as well -cmake -DgRPC_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE="${MSBUILD_CONFIG}" "$@" ../.. +cmake -DCMAKE_CXX_STANDARD=14 -DgRPC_BUILD_GRPCPP_OTEL_PLUGIN=ON -DgRPC_ABSL_PROVIDER=package -DgRPC_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE="${MSBUILD_CONFIG}" -DCMAKE_INSTALL_PREFIX="${INSTALL_PATH}" "$@" ../.. # GRPC_RUN_TESTS_CXX_LANGUAGE_SUFFIX will be set to either "c" or "cxx" make -j"${GRPC_RUN_TESTS_JOBS}" "buildtests_${GRPC_RUN_TESTS_CXX_LANGUAGE_SUFFIX}" "tools_${GRPC_RUN_TESTS_CXX_LANGUAGE_SUFFIX}"