Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CMake OTELCPP_MAINTAINER_MODE #1650

Merged
merged 33 commits into from
Oct 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5871e92
Fixes #1648
marcalff Oct 3, 2022
7ec5536
Format, versions used in github.
marcalff Oct 3, 2022
37f0d2c
Fixed format.
marcalff Oct 3, 2022
9ad340c
Added MSVC MAINTAINER_MODE
marcalff Oct 3, 2022
52e47df
Add a MSVC build in maintainer mode, in CI.
marcalff Oct 3, 2022
d900a42
Fix review comments.
marcalff Oct 3, 2022
3c562b9
Fix review comments.
marcalff Oct 4, 2022
4c412a4
Renamed to OTELCPP_MAINTAINER_MODE, to avoid collisions with other code.
marcalff Oct 5, 2022
62aef50
Merge branch 'open-telemetry:main' into fix_wall_werr_1648
marcalff Oct 5, 2022
ea6e74f
Upgrade CI to gcc 11, clang 14.
marcalff Oct 5, 2022
57e8919
Revert:
marcalff Oct 5, 2022
ee7f15e
Upgrade CI to gcc 10, clang 12.
marcalff Oct 5, 2022
d1a158a
clang fixup
marcalff Oct 5, 2022
c5b9595
Enforce OTELCPP_MAINTAINER_MODE
marcalff Oct 5, 2022
50793c2
Move warning cleanup (work in progress)
marcalff Oct 5, 2022
4e81f46
More warning cleanup (thrift, logs)
marcalff Oct 5, 2022
33754e8
Merge branch 'open-telemetry:main' into fix_wall_werr_1648
marcalff Oct 6, 2022
f4c80ed
Merge branch 'main' into fix_wall_werr_1648
esigo Oct 6, 2022
67cb8c0
Merge branch 'open-telemetry:main' into fix_wall_werr_1648
marcalff Oct 10, 2022
01834ac
Warning cleanup for Thrift-gen
marcalff Oct 10, 2022
8f5c762
Move maintainer mode later in CMakeList.txt,
marcalff Oct 10, 2022
a79f13d
More warning cleanup
marcalff Oct 11, 2022
6b1c23a
Merge branch 'open-telemetry:main' into fix_wall_werr_1648
marcalff Oct 11, 2022
e422bd1
More cleanup
marcalff Oct 11, 2022
525b5de
Merge branch 'main' into fix_wall_werr_1648
marcalff Oct 13, 2022
18ed349
Fix last 4 warnings known.
marcalff Oct 13, 2022
e7310b2
Cleanup
marcalff Oct 13, 2022
cd3b8f8
Relax MSVC warning
marcalff Oct 13, 2022
895b871
Cleanup, variable hides parameter.
marcalff Oct 13, 2022
7555a07
Cleanup, data parameter hides function param.
marcalff Oct 13, 2022
3c4f273
Merge branch 'open-telemetry:main' into fix_wall_werr_1648
marcalff Oct 14, 2022
531104b
Merge branch 'open-telemetry:main' into fix_wall_werr_1648
marcalff Oct 14, 2022
97ad7ae
Fixed code review comments.
marcalff Oct 15, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,52 @@ jobs:
sudo ./ci/setup_thrift.sh
./ci/do_ci.sh cmake.test

cmake_gcc_maintainer_test:
name: CMake gcc (maintainer mode)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: setup
run: |
sudo CC=/usr/bin/gcc-10 CXX=/usr/bin/g++-10 ./ci/setup_cmake.sh
sudo CC=/usr/bin/gcc-10 CXX=/usr/bin/g++-10 ./ci/setup_ci_environment.sh
- name: run cmake gcc (maintainer mode)
run: |
sudo CC=/usr/bin/gcc-10 CXX=/usr/bin/g++-10 ./ci/setup_thrift.sh
CC=/usr/bin/gcc-10 CXX=/usr/bin/g++-10 ./ci/do_ci.sh cmake.maintainer.test

cmake_clang_maintainer_test:
name: CMake clang (maintainer mode)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: setup
run: |
sudo CC=/usr/bin/clang-12 CXX=/usr/bin/clang++-12 ./ci/setup_cmake.sh
sudo CC=/usr/bin/clang-12 CXX=/usr/bin/clang++-12 ./ci/setup_ci_environment.sh
- name: run cmake clang (maintainer mode)
run: |
sudo CC=/usr/bin/clang-12 CXX=/usr/bin/clang++-12 ./ci/setup_thrift.sh
CC=/usr/bin/clang-12 CXX=/usr/bin/clang++-12 ./ci/do_ci.sh cmake.maintainer.test

cmake_msvc_maintainer_test:
name: CMake msvc (maintainer mode)
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: setup
run: |
./ci/setup_windows_cmake.ps1
./ci/setup_windows_ci_environment.ps1
- name: run tests
run: ./ci/do_ci.ps1 cmake.maintainer.test

cmake_deprecated_metrics_test:
name: CMake test (without otlp-exporter and with deprecated metrics)
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Increment the:

## [Unreleased]

* [BUILD] Add CMake OTELCPP_MAINTAINER_MODE [#1650](https://github.com/open-telemetry/opentelemetry-cpp/pull/1650)

## [1.6.1] 2022-09-22

* [BUILD] Upgrade opentelemetry-proto to v0.19.0 [#1579](https://github.com/open-telemetry/opentelemetry-cpp/pull/1579)
Expand Down
84 changes: 84 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ option(BUILD_TESTING "Whether to enable tests" ON)

option(BUILD_W3CTRACECONTEXT_TEST "Whether to build w3c trace context" OFF)

option(OTELCPP_MAINTAINER_MODE "Build in maintainer mode (-Wall -Werror)" OFF)

if(WIN32)
if(BUILD_TESTING)
if(MSVC)
Expand Down Expand Up @@ -358,6 +360,88 @@ if((NOT WITH_API_ONLY) AND USE_NLOHMANN_JSON)
endif()
endif()

if(OTELCPP_MAINTAINER_MODE)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
message("Building with gcc in maintainer mode.")

add_compile_options(-Wall)
add_compile_options(-Werror)
add_compile_options(-Wextra)

# Tested with GCC 9.4 on github.
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 9.4)
message("Building with additional warnings for gcc.")

# Relaxed warnings

# Enforced warnings

# C++ options only
add_compile_options($<$<STREQUAL:$<COMPILE_LANGUAGE>,CXX>:-Wextra-semi>)
add_compile_options(
$<$<STREQUAL:$<COMPILE_LANGUAGE>,CXX>:-Woverloaded-virtual>)
add_compile_options(
$<$<STREQUAL:$<COMPILE_LANGUAGE>,CXX>:-Wsuggest-override>)

# C and C++
add_compile_options(-Wcast-qual)
add_compile_options(-Wformat-security)
add_compile_options(-Wlogical-op)
add_compile_options(-Wmissing-include-dirs)
add_compile_options(-Wstringop-truncation)
add_compile_options(-Wundef)
add_compile_options(-Wvla)
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
message("Building with clang in maintainer mode.")

add_compile_options(-Wall)
add_compile_options(-Werror)
add_compile_options(-Wextra)

# Tested with Clang 11.0 on github.
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 11.0)
message("Building with additional warnings for clang.")

# Relaxed warnings
add_compile_options(-Wno-error=unused-private-field)

# Enforced warnings
add_compile_options(-Wcast-qual)
add_compile_options(-Wconditional-uninitialized)
add_compile_options(-Wextra-semi)
add_compile_options(-Wformat-security)
add_compile_options(-Wheader-hygiene)
add_compile_options(-Winconsistent-missing-destructor-override)
add_compile_options(-Winconsistent-missing-override)
add_compile_options(-Wnewline-eof)
add_compile_options(-Wnon-virtual-dtor)
add_compile_options(-Woverloaded-virtual)
add_compile_options(-Wrange-loop-analysis)
add_compile_options(-Wundef)
add_compile_options(-Wundefined-reinterpret-cast)
add_compile_options(-Wvla)
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
message("Building with msvc in maintainer mode.")

add_compile_options(/WX)
add_compile_options(/W4)

# Relaxed warnings
add_compile_options(/wd4100)
add_compile_options(/wd4125)
add_compile_options(/wd4566)
add_compile_options(/wd4127)
add_compile_options(/wd4512)
add_compile_options(/wd4267)

# Enforced warnings
elseif()
message(FATAL_ERROR "Building with unknown compiler in maintainer mode.")
endif()
endif(OTELCPP_MAINTAINER_MODE)

list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}")

include(CTest)
Expand Down
2 changes: 1 addition & 1 deletion api/test/nostd/unique_ptr_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ TEST(UniquePtrTest, Reset)
{
bool was_destructed1;
unique_ptr<A> ptr{new A{was_destructed1}};
bool was_destructed2;
bool was_destructed2 = true;
ptr.reset(new A{was_destructed2});
EXPECT_TRUE(was_destructed1);
EXPECT_FALSE(was_destructed2);
Expand Down
4 changes: 2 additions & 2 deletions api/test/trace/span_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ void BM_SpanCreationWitContextPropagation(benchmark::State &state)
nostd::shared_ptr<trace_api::Span>(new trace_api::DefaultSpan(outer_span_context));
trace_api::SetSpan(current_ctx, outer_span);
auto inner_child = tracer->StartSpan("inner");
auto scope = tracer->WithActiveSpan(inner_child);
auto inner_scope = tracer->WithActiveSpan(inner_child);
{
auto innermost_child = tracer->StartSpan("innermost");
auto scope = tracer->WithActiveSpan(innermost_child);
auto innermost_scope = tracer->WithActiveSpan(innermost_child);
innermost_child->End();
}
inner_child->End();
Expand Down
1 change: 1 addition & 0 deletions ci/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CI tests can be run on docker by invoking the script `./ci/run_docker.sh
./ci/do_ci.sh {TARGET}` where the targets are:

* `cmake.test`: build cmake targets and run tests.
* `cmake.maintainer.test`: build with cmake and test, in maintainer mode.
* `cmake.legacy.test`: build cmake targets with gcc 4.8 and run tests.
* `cmake.c++20.test`: build cmake targets with the C++20 standard and run tests.
* `cmake.test_example_plugin`: build and test an example OpenTelemetry plugin.
Expand Down
21 changes: 21 additions & 0 deletions ci/do_ci.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,27 @@ switch ($action) {
exit $exit
}
}
"cmake.maintainer.test" {
cd "$BUILD_DIR"
cmake $SRC_DIR `
-DOTELCPP_MAINTAINER_MODE=ON `
-DVCPKG_TARGET_TRIPLET=x64-windows `
"-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake"
$exit = $LASTEXITCODE
if ($exit -ne 0) {
exit $exit
}
cmake --build .
$exit = $LASTEXITCODE
if ($exit -ne 0) {
exit $exit
}
ctest -C Debug
$exit = $LASTEXITCODE
if ($exit -ne 0) {
exit $exit
}
}
"cmake.with_async_export.test" {
cd "$BUILD_DIR"
cmake $SRC_DIR `
Expand Down
16 changes: 16 additions & 0 deletions ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@ if [[ "$1" == "cmake.test" ]]; then
make
make test
exit 0
elif [[ "$1" == "cmake.maintainer.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
cmake -DCMAKE_BUILD_TYPE=Debug \
-DWITH_PROMETHEUS=ON \
-DWITH_ZIPKIN=ON \
-DWITH_JAEGER=ON \
-DWITH_ELASTICSEARCH=ON \
-DWITH_LOGS_PREVIEW=ON \
-DWITH_METRICS_PREVIEW=OFF \
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
-DOTELCPP_MAINTAINER_MODE=ON \
"${SRC_DIR}"
make -k
make test
exit 0
elif [[ "$1" == "cmake.with_async_export.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class HistogramExemplarReservoir : public FixedSizeExemplarReservoir
const MetricAttributes & /* attributes */,
const opentelemetry::context::Context & /* context */) override
{
for (size_t i = 0; i < boundaries_.size(); ++i)
int max_size = boundaries_.size();
for (int i = 0; i < max_size; ++i)
{
if (value <= boundaries_[i])
{
Expand Down
50 changes: 25 additions & 25 deletions sdk/test/metrics/async_metric_storage_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,24 @@ TEST_P(WritableMetricStorageTestFixture, TestAggregation)
storage.RecordLong(measurements1,
opentelemetry::common::SystemTimestamp(std::chrono::system_clock::now()));

storage.Collect(collector.get(), collectors, sdk_start_ts, collection_ts,
[&](const MetricData data) {
for (auto data_attr : data.point_data_attr_)
{
auto data = opentelemetry::nostd::get<SumPointData>(data_attr.point_data);
if (opentelemetry::nostd::get<std::string>(
data_attr.attributes.find("RequestType")->second) == "GET")
{
EXPECT_EQ(opentelemetry::nostd::get<long>(data.value_), get_count1);
}
else if (opentelemetry::nostd::get<std::string>(
data_attr.attributes.find("RequestType")->second) == "PUT")
{
EXPECT_EQ(opentelemetry::nostd::get<long>(data.value_), put_count1);
}
}
return true;
});
storage.Collect(
collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData &metric_data) {
for (const auto &data_attr : metric_data.point_data_attr_)
{
const auto &data = opentelemetry::nostd::get<SumPointData>(data_attr.point_data);
if (opentelemetry::nostd::get<std::string>(
data_attr.attributes.find("RequestType")->second) == "GET")
{
EXPECT_EQ(opentelemetry::nostd::get<long>(data.value_), get_count1);
}
else if (opentelemetry::nostd::get<std::string>(
data_attr.attributes.find("RequestType")->second) == "PUT")
{
EXPECT_EQ(opentelemetry::nostd::get<long>(data.value_), put_count1);
}
}
return true;
});
// subsequent recording after collection shouldn't fail
// monotonic increasing values;
long get_count2 = 50l;
Expand All @@ -105,10 +105,10 @@ TEST_P(WritableMetricStorageTestFixture, TestAggregation)
storage.RecordLong(measurements2,
opentelemetry::common::SystemTimestamp(std::chrono::system_clock::now()));
storage.Collect(
collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData data) {
for (auto data_attr : data.point_data_attr_)
collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData &metric_data) {
for (const auto &data_attr : metric_data.point_data_attr_)
{
auto data = opentelemetry::nostd::get<SumPointData>(data_attr.point_data);
const auto &data = opentelemetry::nostd::get<SumPointData>(data_attr.point_data);
if (opentelemetry::nostd::get<std::string>(
data_attr.attributes.find("RequestType")->second) == "GET")
{
Expand Down Expand Up @@ -171,8 +171,8 @@ TEST_P(WritableMetricStorageTestObservableGaugeFixture, TestAggregation)
opentelemetry::common::SystemTimestamp(std::chrono::system_clock::now()));

storage.Collect(
collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData data) {
for (auto data_attr : data.point_data_attr_)
collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData metric_data) {
for (auto data_attr : metric_data.point_data_attr_)
{
auto data = opentelemetry::nostd::get<LastValuePointData>(data_attr.point_data);
if (opentelemetry::nostd::get<std::string>(data_attr.attributes.find("CPU")->second) ==
Expand All @@ -197,8 +197,8 @@ TEST_P(WritableMetricStorageTestObservableGaugeFixture, TestAggregation)
storage.RecordLong(measurements2,
opentelemetry::common::SystemTimestamp(std::chrono::system_clock::now()));
storage.Collect(
collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData data) {
for (auto data_attr : data.point_data_attr_)
collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData metric_data) {
for (auto data_attr : metric_data.point_data_attr_)
{
auto data = opentelemetry::nostd::get<LastValuePointData>(data_attr.point_data);
if (opentelemetry::nostd::get<std::string>(data_attr.attributes.find("CPU")->second) ==
Expand Down
Loading