Skip to content

Commit 62b7197

Browse files
authored
[Code Health] Include what you use, part 7 (#3238)
1 parent d693e95 commit 62b7197

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+476
-143
lines changed

.github/workflows/iwyu.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ jobs:
3131
libgtest-dev \
3232
libbenchmark-dev
3333
34+
- name: setup grpc
35+
run: |
36+
sudo ./ci/setup_grpc.sh
37+
3438
- name: Prepare CMake
3539
run: |
3640
TOPDIR=`pwd`
@@ -41,12 +45,14 @@ jobs:
4145
-DCMAKE_CXX_INCLUDE_WHAT_YOU_USE="include-what-you-use;-w;-Xiwyu;--mapping_file=${TOPDIR}/.iwyu.imp;" \
4246
-DBUILD_TESTING=ON \
4347
-DBUILD_W3CTRACECONTEXT_TEST=ON \
44-
-DWITH_OTLP_GRPC=OFF \
48+
-DWITH_OTLP_GRPC=ON \
4549
-DWITH_OTLP_HTTP=ON \
4650
-DWITH_OTLP_FILE=ON \
51+
-DWITH_OPENTRACING=ON \
4752
-DWITH_OTLP_HTTP_COMPRESSION=ON \
53+
-DWITH_THREAD_INSTRUMENTATION=ON \
4854
-DWITH_ZIPKIN=ON \
49-
-DWITH_PROMETHEUS=OFF \
55+
-DWITH_PROMETHEUS=ON \
5056
..
5157
5258
- name: iwyu_tool
@@ -67,7 +73,7 @@ jobs:
6773
readonly WARNING_COUNT=`grep -c "include-what-you-use reported diagnostics:" iwyu.log`
6874
echo "include-what-you-use reported ${WARNING_COUNT} warning(s)"
6975
# Acceptable limit, to decrease over time down to 0
70-
readonly WARNING_LIMIT=180
76+
readonly WARNING_LIMIT=10
7177
# FAIL the build if WARNING_COUNT > WARNING_LIMIT
7278
if [ $WARNING_COUNT -gt $WARNING_LIMIT ] ; then
7379
exit 1

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,11 +369,16 @@ if(WITH_PROMETHEUS)
369369
if(EXISTS ${PROJECT_SOURCE_DIR}/third_party/prometheus-cpp/.git)
370370
set(SAVED_ENABLE_TESTING ${ENABLE_TESTING})
371371
set(SAVED_CMAKE_CXX_CLANG_TIDY ${CMAKE_CXX_CLANG_TIDY})
372+
set(SAVED_CMAKE_CXX_INCLUDE_WHAT_YOU_USE
373+
${CMAKE_CXX_INCLUDE_WHAT_YOU_USE})
372374
set(ENABLE_TESTING OFF)
373375
set(CMAKE_CXX_CLANG_TIDY "")
376+
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "")
374377
add_subdirectory(third_party/prometheus-cpp)
375378
set(ENABLE_TESTING ${SAVED_ENABLE_TESTING})
376379
set(CMAKE_CXX_CLANG_TIDY ${SAVED_CMAKE_CXX_CLANG_TIDY})
380+
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
381+
${SAVED_CMAKE_CXX_INCLUDE_WHAT_YOU_USE})
377382
else()
378383
message(
379384
FATAL_ERROR
@@ -715,8 +720,13 @@ if(WITH_OPENTRACING)
715720
if(EXISTS "${PROJECT_SOURCE_DIR}/${OPENTRACING_DIR}/.git")
716721
set(SAVED_BUILD_TESTING ${BUILD_TESTING})
717722
set(BUILD_TESTING OFF)
723+
set(SAVED_CMAKE_CXX_INCLUDE_WHAT_YOU_USE
724+
${CMAKE_CXX_INCLUDE_WHAT_YOU_USE})
725+
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "")
718726
add_subdirectory(${OPENTRACING_DIR})
719727
set(BUILD_TESTING ${SAVED_BUILD_TESTING})
728+
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
729+
${SAVED_CMAKE_CXX_INCLUDE_WHAT_YOU_USE})
720730
else()
721731
message(
722732
FATAL_ERROR

ci/do_ci.sh

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,9 @@ mkdir -p "${BUILD_DIR}"
6363
[ -z "${PLUGIN_DIR}" ] && export PLUGIN_DIR=$HOME/plugin
6464
mkdir -p "${PLUGIN_DIR}"
6565

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

69-
# Temporarily disable the IWYU build.
70-
# It fails in Ubuntu 24-04 CI with:
71-
# Error running 'iwyu': Segmentation fault
72-
#
73-
# if [[ "${CXX}" == *clang* ]]; then
74-
# MAKE_COMMAND="make -k CXX=include-what-you-use CXXFLAGS=\"-Xiwyu --error_always\" -j \$(nproc)"
75-
# IWYU="-DCMAKE_CXX_INCLUDE_WHAT_YOU_USE=iwyu"
76-
# fi
77-
7868
echo "make command: ${MAKE_COMMAND}"
79-
echo "IWYU option: ${IWYU}"
8069

8170
BAZEL_OPTIONS_DEFAULT="--copt=-DENABLE_METRICS_EXEMPLAR_PREVIEW"
8271
BAZEL_OPTIONS="$BAZEL_OPTIONS_DEFAULT"
@@ -132,7 +121,6 @@ elif [[ "$1" == "cmake.maintainer.sync.test" ]]; then
132121
-DWITH_NO_DEPRECATED_CODE=ON \
133122
-DWITH_OTLP_HTTP_COMPRESSION=ON \
134123
-DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON \
135-
${IWYU} \
136124
"${SRC_DIR}"
137125
eval "$MAKE_COMMAND"
138126
make test
@@ -155,7 +143,6 @@ elif [[ "$1" == "cmake.maintainer.async.test" ]]; then
155143
-DWITH_NO_DEPRECATED_CODE=ON \
156144
-DWITH_OTLP_HTTP_COMPRESSION=ON \
157145
-DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON \
158-
${IWYU} \
159146
"${SRC_DIR}"
160147
eval "$MAKE_COMMAND"
161148
make test
@@ -203,7 +190,6 @@ elif [[ "$1" == "cmake.maintainer.abiv2.test" ]]; then
203190
-DWITH_ABI_VERSION_2=ON \
204191
-DWITH_OTLP_HTTP_COMPRESSION=ON \
205192
-DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON \
206-
${IWYU} \
207193
"${SRC_DIR}"
208194
eval "$MAKE_COMMAND"
209195
make test
@@ -251,7 +237,6 @@ elif [[ "$1" == "cmake.c++20.test" ]]; then
251237
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
252238
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
253239
-DWITH_STL=CXX20 \
254-
${IWYU} \
255240
"${SRC_DIR}"
256241
eval "$MAKE_COMMAND"
257242
make test
@@ -263,7 +248,6 @@ elif [[ "$1" == "cmake.c++23.test" ]]; then
263248
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
264249
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
265250
-DWITH_STL=CXX23 \
266-
${IWYU} \
267251
"${SRC_DIR}"
268252
eval "$MAKE_COMMAND"
269253
make test
@@ -276,7 +260,6 @@ elif [[ "$1" == "cmake.c++14.stl.test" ]]; then
276260
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
277261
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
278262
-DWITH_STL=CXX14 \
279-
${IWYU} \
280263
"${SRC_DIR}"
281264
eval "$MAKE_COMMAND"
282265
make test
@@ -289,7 +272,6 @@ elif [[ "$1" == "cmake.c++17.stl.test" ]]; then
289272
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
290273
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
291274
-DWITH_STL=CXX17 \
292-
${IWYU} \
293275
"${SRC_DIR}"
294276
eval "$MAKE_COMMAND"
295277
make test
@@ -302,7 +284,6 @@ elif [[ "$1" == "cmake.c++20.stl.test" ]]; then
302284
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
303285
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
304286
-DWITH_STL=CXX20 \
305-
${IWYU} \
306287
"${SRC_DIR}"
307288
eval "$MAKE_COMMAND"
308289
make test
@@ -315,7 +296,6 @@ elif [[ "$1" == "cmake.c++23.stl.test" ]]; then
315296
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
316297
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
317298
-DWITH_STL=CXX23 \
318-
${IWYU} \
319299
"${SRC_DIR}"
320300
eval "$MAKE_COMMAND"
321301
make test

cmake/opentelemetry-proto.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,9 @@ if(WITH_OTLP_GRPC)
342342
${LOGS_SERVICE_GRPC_PB_CPP_FILE} ${METRICS_SERVICE_GRPC_PB_CPP_FILE})
343343
set_target_version(opentelemetry_proto_grpc)
344344

345+
# Disable include-what-you-use on generated code.
346+
set_target_properties(opentelemetry_proto_grpc PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "")
347+
345348
list(APPEND OPENTELEMETRY_PROTO_TARGETS opentelemetry_proto_grpc)
346349
target_link_libraries(opentelemetry_proto_grpc PUBLIC opentelemetry_proto)
347350

examples/grpc/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ add_library(example_grpc_proto ${example_grpc_srcs} ${example_grpc_hdrs}
2525

2626
patch_protobuf_targets(example_grpc_proto)
2727

28+
# Disable include-what-you-use on generated code.
29+
set_target_properties(example_grpc_proto PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "")
30+
2831
include_directories(
2932
${CMAKE_SOURCE_DIR}/exporters/ostream/include ${CMAKE_SOURCE_DIR}/ext/include
3033
${CMAKE_SOURCE_DIR}/api/include/ ${CMAKE_SOURCE_DIR/})

examples/grpc/client.cc

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,32 @@
55
// ambiguity with `nostd::variant` if compiled with Visual Studio 2015. Other
66
// modern compilers are unaffected.
77
#include <grpcpp/grpcpp.h>
8+
#include <grpcpp/security/credentials.h>
9+
#include <grpcpp/support/status.h>
10+
11+
#include <stdint.h>
12+
#include <stdlib.h>
13+
#include <iostream>
14+
#include <string>
15+
#include <utility>
16+
#include "opentelemetry/context/propagation/global_propagator.h"
17+
#include "opentelemetry/context/propagation/text_map_propagator.h"
18+
#include "opentelemetry/context/runtime_context.h"
19+
#include "opentelemetry/nostd/shared_ptr.h"
20+
#include "opentelemetry/trace/propagation/http_trace_context.h"
21+
#include "opentelemetry/trace/span.h"
22+
#include "opentelemetry/trace/span_metadata.h"
23+
#include "opentelemetry/trace/span_startoptions.h"
24+
#include "opentelemetry/trace/tracer.h"
25+
826
#ifdef BAZEL_BUILD
927
# include "examples/grpc/protos/messages.grpc.pb.h"
28+
# include "examples/grpc/protos/messages.pb.h"
1029
#else
1130
# include "messages.grpc.pb.h"
31+
# include "messages.pb.h"
1232
#endif
1333

14-
#include <iostream>
15-
#include <memory>
16-
#include <string>
17-
1834
#include "opentelemetry/semconv/incubating/rpc_attributes.h"
1935
#include "opentelemetry/semconv/network_attributes.h"
2036
#include "tracer_common.h"

examples/grpc/server.cc

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,40 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4-
#ifdef BAZEL_BUILD
5-
# include "examples/grpc/protos/messages.grpc.pb.h"
6-
#else
7-
# include "messages.grpc.pb.h"
8-
#endif
9-
10-
#include "opentelemetry/semconv/incubating/rpc_attributes.h"
11-
#include "opentelemetry/trace/context.h"
12-
#include "opentelemetry/trace/span_context_kv_iterable_view.h"
13-
#include "tracer_common.h"
14-
15-
#include <grpcpp/grpcpp.h>
4+
#include <grpcpp/security/server_credentials.h>
165
#include <grpcpp/server.h>
176
#include <grpcpp/server_builder.h>
187
#include <grpcpp/server_context.h>
19-
20-
#include <chrono>
21-
#include <fstream>
8+
#include <grpcpp/support/status.h>
9+
#include <grpcpp/support/string_ref.h>
10+
#include <stdint.h>
11+
#include <stdlib.h>
12+
#include <iostream>
2213
#include <map>
23-
#include <sstream>
2414
#include <string>
25-
#include <thread>
15+
#include <utility>
16+
17+
#include "opentelemetry/context/propagation/global_propagator.h"
18+
#include "opentelemetry/context/propagation/text_map_propagator.h"
19+
#include "opentelemetry/context/runtime_context.h"
20+
#include "opentelemetry/nostd/shared_ptr.h"
21+
#include "opentelemetry/nostd/variant.h"
22+
#include "opentelemetry/semconv/incubating/rpc_attributes.h"
23+
#include "opentelemetry/trace/context.h"
24+
#include "opentelemetry/trace/span.h"
25+
#include "opentelemetry/trace/span_context.h"
26+
#include "opentelemetry/trace/span_metadata.h"
27+
#include "opentelemetry/trace/span_startoptions.h"
28+
#include "opentelemetry/trace/tracer.h"
29+
#include "tracer_common.h"
30+
31+
#ifdef BAZEL_BUILD
32+
# include "examples/grpc/protos/messages.grpc.pb.h"
33+
# include "examples/grpc/protos/messages.pb.h"
34+
#else
35+
# include "messages.grpc.pb.h"
36+
# include "messages.pb.h"
37+
#endif
2638

2739
using grpc::Server;
2840
using grpc::ServerBuilder;

examples/otlp/http_instrumented_main.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
#include <string>
77
#include <utility>
88

9-
#include "opentelemetry/exporters/otlp/otlp_environment.h"
10-
#include "opentelemetry/exporters/otlp/otlp_http.h"
119
#include "opentelemetry/exporters/otlp/otlp_http_exporter_factory.h"
1210
#include "opentelemetry/exporters/otlp/otlp_http_exporter_options.h"
1311
#include "opentelemetry/exporters/otlp/otlp_http_exporter_runtime_options.h"
@@ -17,15 +15,13 @@
1715
#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h"
1816
#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h"
1917
#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_runtime_options.h"
20-
#include "opentelemetry/logs/log_record.h"
2118
#include "opentelemetry/logs/logger_provider.h"
2219
#include "opentelemetry/logs/provider.h"
2320
#include "opentelemetry/metrics/meter_provider.h"
2421
#include "opentelemetry/metrics/provider.h"
2522
#include "opentelemetry/sdk/logs/batch_log_record_processor_factory.h"
2623
#include "opentelemetry/sdk/logs/logger_provider.h"
2724
#include "opentelemetry/sdk/logs/logger_provider_factory.h"
28-
#include "opentelemetry/sdk/logs/recordable.h"
2925
#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_factory.h"
3026
#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_options.h"
3127
#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_runtime_options.h"
@@ -38,13 +34,20 @@
3834
#include "opentelemetry/sdk/trace/batch_span_processor_options.h"
3935
#include "opentelemetry/sdk/trace/batch_span_processor_runtime_options.h"
4036
#include "opentelemetry/sdk/trace/processor.h"
41-
#include "opentelemetry/sdk/trace/recordable.h"
4237
#include "opentelemetry/sdk/trace/tracer_provider.h"
4338
#include "opentelemetry/sdk/trace/tracer_provider_factory.h"
4439
#include "opentelemetry/trace/provider.h"
45-
#include "opentelemetry/trace/span_id.h"
4640
#include "opentelemetry/trace/tracer_provider.h"
4741

42+
#include <chrono>
43+
#include <mutex>
44+
#include "opentelemetry/sdk/logs/batch_log_record_processor_options.h"
45+
#include "opentelemetry/sdk/logs/batch_log_record_processor_runtime_options.h"
46+
#include "opentelemetry/sdk/logs/exporter.h"
47+
#include "opentelemetry/sdk/logs/processor.h"
48+
#include "opentelemetry/sdk/metrics/meter_provider.h"
49+
#include "opentelemetry/sdk/trace/exporter.h"
50+
4851
#ifdef BAZEL_BUILD
4952
# include "examples/common/logs_foo_library/foo_library.h"
5053
# include "examples/common/metrics_foo_library/foo_library.h"

examples/prometheus/main.cc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4+
#include <cstdio>
45
#include <memory>
6+
#include <string>
57
#include <thread>
8+
#include <utility>
69

10+
#include "opentelemetry/common/attribute_value.h"
711
#include "opentelemetry/exporters/prometheus/exporter_factory.h"
812
#include "opentelemetry/exporters/prometheus/exporter_options.h"
13+
#include "opentelemetry/metrics/meter_provider.h"
914
#include "opentelemetry/metrics/provider.h"
10-
#include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h"
11-
#include "opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h"
12-
#include "opentelemetry/sdk/metrics/meter.h"
15+
#include "opentelemetry/sdk/metrics/instruments.h"
1316
#include "opentelemetry/sdk/metrics/meter_provider.h"
1417
#include "opentelemetry/sdk/metrics/meter_provider_factory.h"
18+
#include "opentelemetry/sdk/metrics/metric_reader.h"
19+
#include "opentelemetry/sdk/metrics/view/instrument_selector.h"
1520
#include "opentelemetry/sdk/metrics/view/instrument_selector_factory.h"
21+
#include "opentelemetry/sdk/metrics/view/meter_selector.h"
1622
#include "opentelemetry/sdk/metrics/view/meter_selector_factory.h"
23+
#include "opentelemetry/sdk/metrics/view/view.h"
1724
#include "opentelemetry/sdk/metrics/view/view_factory.h"
1825

1926
#ifdef BAZEL_BUILD

exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client_factory.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,16 @@
55

66
#include <memory>
77

8+
#include "opentelemetry/exporters/otlp/otlp_grpc_client.h"
89
#include "opentelemetry/exporters/otlp/otlp_grpc_client_options.h"
9-
#include "opentelemetry/nostd/shared_ptr.h"
10+
#include "opentelemetry/version.h"
1011

1112
OPENTELEMETRY_BEGIN_NAMESPACE
1213
namespace exporter
1314
{
1415
namespace otlp
1516
{
1617

17-
class OtlpGrpcClientReferenceGuard;
18-
class OtlpGrpcClient;
19-
2018
/**
2119
* Factory class for OtlpGrpcClient.
2220
*/

exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_utils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
#pragma once
55

6-
#include <grpcpp/grpcpp.h>
6+
#include <grpcpp/support/status.h>
77

8-
#include "opentelemetry/sdk/version/version.h"
8+
#include "opentelemetry/version.h"
99

1010
OPENTELEMETRY_BEGIN_NAMESPACE
1111

0 commit comments

Comments
 (0)