Skip to content

Commit

Permalink
[Code Health] Include what you use, part 7 (open-telemetry#3238)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcalff authored Jan 13, 2025
1 parent d693e95 commit 62b7197
Show file tree
Hide file tree
Showing 48 changed files with 476 additions and 143 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/iwyu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ jobs:
libgtest-dev \
libbenchmark-dev
- name: setup grpc
run: |
sudo ./ci/setup_grpc.sh
- name: Prepare CMake
run: |
TOPDIR=`pwd`
Expand All @@ -41,12 +45,14 @@ jobs:
-DCMAKE_CXX_INCLUDE_WHAT_YOU_USE="include-what-you-use;-w;-Xiwyu;--mapping_file=${TOPDIR}/.iwyu.imp;" \
-DBUILD_TESTING=ON \
-DBUILD_W3CTRACECONTEXT_TEST=ON \
-DWITH_OTLP_GRPC=OFF \
-DWITH_OTLP_GRPC=ON \
-DWITH_OTLP_HTTP=ON \
-DWITH_OTLP_FILE=ON \
-DWITH_OPENTRACING=ON \
-DWITH_OTLP_HTTP_COMPRESSION=ON \
-DWITH_THREAD_INSTRUMENTATION=ON \
-DWITH_ZIPKIN=ON \
-DWITH_PROMETHEUS=OFF \
-DWITH_PROMETHEUS=ON \
..
- name: iwyu_tool
Expand All @@ -67,7 +73,7 @@ jobs:
readonly WARNING_COUNT=`grep -c "include-what-you-use reported diagnostics:" iwyu.log`
echo "include-what-you-use reported ${WARNING_COUNT} warning(s)"
# Acceptable limit, to decrease over time down to 0
readonly WARNING_LIMIT=180
readonly WARNING_LIMIT=10
# FAIL the build if WARNING_COUNT > WARNING_LIMIT
if [ $WARNING_COUNT -gt $WARNING_LIMIT ] ; then
exit 1
Expand Down
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,16 @@ if(WITH_PROMETHEUS)
if(EXISTS ${PROJECT_SOURCE_DIR}/third_party/prometheus-cpp/.git)
set(SAVED_ENABLE_TESTING ${ENABLE_TESTING})
set(SAVED_CMAKE_CXX_CLANG_TIDY ${CMAKE_CXX_CLANG_TIDY})
set(SAVED_CMAKE_CXX_INCLUDE_WHAT_YOU_USE
${CMAKE_CXX_INCLUDE_WHAT_YOU_USE})
set(ENABLE_TESTING OFF)
set(CMAKE_CXX_CLANG_TIDY "")
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "")
add_subdirectory(third_party/prometheus-cpp)
set(ENABLE_TESTING ${SAVED_ENABLE_TESTING})
set(CMAKE_CXX_CLANG_TIDY ${SAVED_CMAKE_CXX_CLANG_TIDY})
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
${SAVED_CMAKE_CXX_INCLUDE_WHAT_YOU_USE})
else()
message(
FATAL_ERROR
Expand Down Expand Up @@ -715,8 +720,13 @@ if(WITH_OPENTRACING)
if(EXISTS "${PROJECT_SOURCE_DIR}/${OPENTRACING_DIR}/.git")
set(SAVED_BUILD_TESTING ${BUILD_TESTING})
set(BUILD_TESTING OFF)
set(SAVED_CMAKE_CXX_INCLUDE_WHAT_YOU_USE
${CMAKE_CXX_INCLUDE_WHAT_YOU_USE})
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "")
add_subdirectory(${OPENTRACING_DIR})
set(BUILD_TESTING ${SAVED_BUILD_TESTING})
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
${SAVED_CMAKE_CXX_INCLUDE_WHAT_YOU_USE})
else()
message(
FATAL_ERROR
Expand Down
20 changes: 0 additions & 20 deletions ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,9 @@ mkdir -p "${BUILD_DIR}"
[ -z "${PLUGIN_DIR}" ] && export PLUGIN_DIR=$HOME/plugin
mkdir -p "${PLUGIN_DIR}"

IWYU=""
MAKE_COMMAND="make -k -j \$(nproc)"

# Temporarily disable the IWYU build.
# It fails in Ubuntu 24-04 CI with:
# Error running 'iwyu': Segmentation fault
#
# if [[ "${CXX}" == *clang* ]]; then
# MAKE_COMMAND="make -k CXX=include-what-you-use CXXFLAGS=\"-Xiwyu --error_always\" -j \$(nproc)"
# IWYU="-DCMAKE_CXX_INCLUDE_WHAT_YOU_USE=iwyu"
# fi

echo "make command: ${MAKE_COMMAND}"
echo "IWYU option: ${IWYU}"

BAZEL_OPTIONS_DEFAULT="--copt=-DENABLE_METRICS_EXEMPLAR_PREVIEW"
BAZEL_OPTIONS="$BAZEL_OPTIONS_DEFAULT"
Expand Down Expand Up @@ -132,7 +121,6 @@ elif [[ "$1" == "cmake.maintainer.sync.test" ]]; then
-DWITH_NO_DEPRECATED_CODE=ON \
-DWITH_OTLP_HTTP_COMPRESSION=ON \
-DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON \
${IWYU} \
"${SRC_DIR}"
eval "$MAKE_COMMAND"
make test
Expand All @@ -155,7 +143,6 @@ elif [[ "$1" == "cmake.maintainer.async.test" ]]; then
-DWITH_NO_DEPRECATED_CODE=ON \
-DWITH_OTLP_HTTP_COMPRESSION=ON \
-DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON \
${IWYU} \
"${SRC_DIR}"
eval "$MAKE_COMMAND"
make test
Expand Down Expand Up @@ -203,7 +190,6 @@ elif [[ "$1" == "cmake.maintainer.abiv2.test" ]]; then
-DWITH_ABI_VERSION_2=ON \
-DWITH_OTLP_HTTP_COMPRESSION=ON \
-DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON \
${IWYU} \
"${SRC_DIR}"
eval "$MAKE_COMMAND"
make test
Expand Down Expand Up @@ -251,7 +237,6 @@ elif [[ "$1" == "cmake.c++20.test" ]]; then
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
-DWITH_STL=CXX20 \
${IWYU} \
"${SRC_DIR}"
eval "$MAKE_COMMAND"
make test
Expand All @@ -263,7 +248,6 @@ elif [[ "$1" == "cmake.c++23.test" ]]; then
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
-DWITH_STL=CXX23 \
${IWYU} \
"${SRC_DIR}"
eval "$MAKE_COMMAND"
make test
Expand All @@ -276,7 +260,6 @@ elif [[ "$1" == "cmake.c++14.stl.test" ]]; then
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
-DWITH_STL=CXX14 \
${IWYU} \
"${SRC_DIR}"
eval "$MAKE_COMMAND"
make test
Expand All @@ -289,7 +272,6 @@ elif [[ "$1" == "cmake.c++17.stl.test" ]]; then
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
-DWITH_STL=CXX17 \
${IWYU} \
"${SRC_DIR}"
eval "$MAKE_COMMAND"
make test
Expand All @@ -302,7 +284,6 @@ elif [[ "$1" == "cmake.c++20.stl.test" ]]; then
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
-DWITH_STL=CXX20 \
${IWYU} \
"${SRC_DIR}"
eval "$MAKE_COMMAND"
make test
Expand All @@ -315,7 +296,6 @@ elif [[ "$1" == "cmake.c++23.stl.test" ]]; then
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
-DWITH_STL=CXX23 \
${IWYU} \
"${SRC_DIR}"
eval "$MAKE_COMMAND"
make test
Expand Down
3 changes: 3 additions & 0 deletions cmake/opentelemetry-proto.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ if(WITH_OTLP_GRPC)
${LOGS_SERVICE_GRPC_PB_CPP_FILE} ${METRICS_SERVICE_GRPC_PB_CPP_FILE})
set_target_version(opentelemetry_proto_grpc)

# Disable include-what-you-use on generated code.
set_target_properties(opentelemetry_proto_grpc PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "")

list(APPEND OPENTELEMETRY_PROTO_TARGETS opentelemetry_proto_grpc)
target_link_libraries(opentelemetry_proto_grpc PUBLIC opentelemetry_proto)

Expand Down
3 changes: 3 additions & 0 deletions examples/grpc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ add_library(example_grpc_proto ${example_grpc_srcs} ${example_grpc_hdrs}

patch_protobuf_targets(example_grpc_proto)

# Disable include-what-you-use on generated code.
set_target_properties(example_grpc_proto PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "")

include_directories(
${CMAKE_SOURCE_DIR}/exporters/ostream/include ${CMAKE_SOURCE_DIR}/ext/include
${CMAKE_SOURCE_DIR}/api/include/ ${CMAKE_SOURCE_DIR/})
Expand Down
24 changes: 20 additions & 4 deletions examples/grpc/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,32 @@
// ambiguity with `nostd::variant` if compiled with Visual Studio 2015. Other
// modern compilers are unaffected.
#include <grpcpp/grpcpp.h>
#include <grpcpp/security/credentials.h>
#include <grpcpp/support/status.h>

#include <stdint.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <utility>
#include "opentelemetry/context/propagation/global_propagator.h"
#include "opentelemetry/context/propagation/text_map_propagator.h"
#include "opentelemetry/context/runtime_context.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/trace/propagation/http_trace_context.h"
#include "opentelemetry/trace/span.h"
#include "opentelemetry/trace/span_metadata.h"
#include "opentelemetry/trace/span_startoptions.h"
#include "opentelemetry/trace/tracer.h"

#ifdef BAZEL_BUILD
# include "examples/grpc/protos/messages.grpc.pb.h"
# include "examples/grpc/protos/messages.pb.h"
#else
# include "messages.grpc.pb.h"
# include "messages.pb.h"
#endif

#include <iostream>
#include <memory>
#include <string>

#include "opentelemetry/semconv/incubating/rpc_attributes.h"
#include "opentelemetry/semconv/network_attributes.h"
#include "tracer_common.h"
Expand Down
46 changes: 29 additions & 17 deletions examples/grpc/server.cc
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#ifdef BAZEL_BUILD
# include "examples/grpc/protos/messages.grpc.pb.h"
#else
# include "messages.grpc.pb.h"
#endif

#include "opentelemetry/semconv/incubating/rpc_attributes.h"
#include "opentelemetry/trace/context.h"
#include "opentelemetry/trace/span_context_kv_iterable_view.h"
#include "tracer_common.h"

#include <grpcpp/grpcpp.h>
#include <grpcpp/security/server_credentials.h>
#include <grpcpp/server.h>
#include <grpcpp/server_builder.h>
#include <grpcpp/server_context.h>

#include <chrono>
#include <fstream>
#include <grpcpp/support/status.h>
#include <grpcpp/support/string_ref.h>
#include <stdint.h>
#include <stdlib.h>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <thread>
#include <utility>

#include "opentelemetry/context/propagation/global_propagator.h"
#include "opentelemetry/context/propagation/text_map_propagator.h"
#include "opentelemetry/context/runtime_context.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/nostd/variant.h"
#include "opentelemetry/semconv/incubating/rpc_attributes.h"
#include "opentelemetry/trace/context.h"
#include "opentelemetry/trace/span.h"
#include "opentelemetry/trace/span_context.h"
#include "opentelemetry/trace/span_metadata.h"
#include "opentelemetry/trace/span_startoptions.h"
#include "opentelemetry/trace/tracer.h"
#include "tracer_common.h"

#ifdef BAZEL_BUILD
# include "examples/grpc/protos/messages.grpc.pb.h"
# include "examples/grpc/protos/messages.pb.h"
#else
# include "messages.grpc.pb.h"
# include "messages.pb.h"
#endif

using grpc::Server;
using grpc::ServerBuilder;
Expand Down
15 changes: 9 additions & 6 deletions examples/otlp/http_instrumented_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#include <string>
#include <utility>

#include "opentelemetry/exporters/otlp/otlp_environment.h"
#include "opentelemetry/exporters/otlp/otlp_http.h"
#include "opentelemetry/exporters/otlp/otlp_http_exporter_factory.h"
#include "opentelemetry/exporters/otlp/otlp_http_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_http_exporter_runtime_options.h"
Expand All @@ -17,15 +15,13 @@
#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h"
#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_runtime_options.h"
#include "opentelemetry/logs/log_record.h"
#include "opentelemetry/logs/logger_provider.h"
#include "opentelemetry/logs/provider.h"
#include "opentelemetry/metrics/meter_provider.h"
#include "opentelemetry/metrics/provider.h"
#include "opentelemetry/sdk/logs/batch_log_record_processor_factory.h"
#include "opentelemetry/sdk/logs/logger_provider.h"
#include "opentelemetry/sdk/logs/logger_provider_factory.h"
#include "opentelemetry/sdk/logs/recordable.h"
#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_factory.h"
#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_options.h"
#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_runtime_options.h"
Expand All @@ -38,13 +34,20 @@
#include "opentelemetry/sdk/trace/batch_span_processor_options.h"
#include "opentelemetry/sdk/trace/batch_span_processor_runtime_options.h"
#include "opentelemetry/sdk/trace/processor.h"
#include "opentelemetry/sdk/trace/recordable.h"
#include "opentelemetry/sdk/trace/tracer_provider.h"
#include "opentelemetry/sdk/trace/tracer_provider_factory.h"
#include "opentelemetry/trace/provider.h"
#include "opentelemetry/trace/span_id.h"
#include "opentelemetry/trace/tracer_provider.h"

#include <chrono>
#include <mutex>
#include "opentelemetry/sdk/logs/batch_log_record_processor_options.h"
#include "opentelemetry/sdk/logs/batch_log_record_processor_runtime_options.h"
#include "opentelemetry/sdk/logs/exporter.h"
#include "opentelemetry/sdk/logs/processor.h"
#include "opentelemetry/sdk/metrics/meter_provider.h"
#include "opentelemetry/sdk/trace/exporter.h"

#ifdef BAZEL_BUILD
# include "examples/common/logs_foo_library/foo_library.h"
# include "examples/common/metrics_foo_library/foo_library.h"
Expand Down
13 changes: 10 additions & 3 deletions examples/prometheus/main.cc
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#include <cstdio>
#include <memory>
#include <string>
#include <thread>
#include <utility>

#include "opentelemetry/common/attribute_value.h"
#include "opentelemetry/exporters/prometheus/exporter_factory.h"
#include "opentelemetry/exporters/prometheus/exporter_options.h"
#include "opentelemetry/metrics/meter_provider.h"
#include "opentelemetry/metrics/provider.h"
#include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h"
#include "opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h"
#include "opentelemetry/sdk/metrics/meter.h"
#include "opentelemetry/sdk/metrics/instruments.h"
#include "opentelemetry/sdk/metrics/meter_provider.h"
#include "opentelemetry/sdk/metrics/meter_provider_factory.h"
#include "opentelemetry/sdk/metrics/metric_reader.h"
#include "opentelemetry/sdk/metrics/view/instrument_selector.h"
#include "opentelemetry/sdk/metrics/view/instrument_selector_factory.h"
#include "opentelemetry/sdk/metrics/view/meter_selector.h"
#include "opentelemetry/sdk/metrics/view/meter_selector_factory.h"
#include "opentelemetry/sdk/metrics/view/view.h"
#include "opentelemetry/sdk/metrics/view/view_factory.h"

#ifdef BAZEL_BUILD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@

#include <memory>

#include "opentelemetry/exporters/otlp/otlp_grpc_client.h"
#include "opentelemetry/exporters/otlp/otlp_grpc_client_options.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
{
namespace otlp
{

class OtlpGrpcClientReferenceGuard;
class OtlpGrpcClient;

/**
* Factory class for OtlpGrpcClient.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

#pragma once

#include <grpcpp/grpcpp.h>
#include <grpcpp/support/status.h>

#include "opentelemetry/sdk/version/version.h"
#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE

Expand Down
Loading

0 comments on commit 62b7197

Please sign in to comment.