From f448b2c3de42a89521a2d44850e8a82aa0878d84 Mon Sep 17 00:00:00 2001 From: Gregor Jasny Date: Wed, 3 Mar 2021 21:35:26 +0100 Subject: [PATCH] feat(iwyu): Organize includes with include-what-you-use --- .github/workflows/linting.yml | 40 +++++++++++ CMakeLists.txt | 20 ++++++ cmake/civetweb-3rdparty-config.cmake | 5 ++ cmake/googlemock-3rdparty-config.cmake | 7 +- cmake/googletest.imp | 4 ++ cmake/project-import/sample_client.cc | 66 +------------------ core/benchmarks/benchmark_helpers.cc | 4 +- core/benchmarks/benchmark_helpers.h | 3 +- core/benchmarks/counter_bench.cc | 8 ++- core/benchmarks/gauge_bench.cc | 8 ++- core/benchmarks/histogram_bench.cc | 8 ++- core/benchmarks/registry_bench.cc | 5 +- core/benchmarks/summary_bench.cc | 10 ++- core/include/prometheus/counter.h | 2 +- core/include/prometheus/detail/builder.h | 7 +- .../prometheus/detail/ckms_quantiles.h | 2 + .../prometheus/detail/time_window_quantiles.h | 4 +- core/include/prometheus/family.h | 11 ++-- core/include/prometheus/gauge.h | 2 +- core/include/prometheus/histogram.h | 2 +- core/include/prometheus/registry.h | 3 +- core/include/prometheus/summary.h | 2 +- core/include/prometheus/text_serializer.h | 1 - core/src/check_names.cc | 2 + core/src/detail/builder.cc | 1 + core/src/detail/ckms_quantiles.cc | 3 +- core/src/detail/time_window_quantiles.cc | 5 +- core/src/detail/utils.cc | 2 +- core/src/family.cc | 6 ++ core/src/histogram.cc | 4 +- core/src/registry.cc | 4 ++ core/src/serializer.cc | 2 +- core/src/summary.cc | 2 + core/src/text_serializer.cc | 5 ++ core/tests/builder_test.cc | 11 +++- core/tests/check_names_test.cc | 2 +- core/tests/counter_test.cc | 2 +- core/tests/family_test.cc | 2 + core/tests/gauge_test.cc | 2 +- core/tests/histogram_test.cc | 4 +- core/tests/registry_test.cc | 4 +- core/tests/serializer_test.cc | 5 ++ core/tests/summary_test.cc | 4 +- core/tests/text_serializer_test.cc | 7 +- core/tests/utils_test.cc | 3 +- pull/include/prometheus/exposer.h | 4 +- pull/src/basic_auth.cc | 3 +- pull/src/basic_auth.h | 3 +- pull/src/detail/base64.h | 1 + pull/src/endpoint.cc | 2 + pull/src/endpoint.h | 4 +- pull/src/exposer.cc | 7 +- pull/src/handler.cc | 12 +++- pull/src/handler.h | 2 + pull/src/metrics_collector.cc | 2 + pull/tests/integration/integration_test.cc | 10 ++- pull/tests/integration/sample_server.cc | 10 +-- pull/tests/integration/sample_server_auth.cc | 11 ++-- pull/tests/integration/sample_server_multi.cc | 11 ++-- pull/tests/unit/exposer_test.cc | 2 +- push/include/prometheus/gateway.h | 5 +- push/src/gateway.cc | 8 ++- push/tests/integration/sample_client.cc | 12 ++-- 63 files changed, 264 insertions(+), 151 deletions(-) create mode 100644 .github/workflows/linting.yml create mode 100644 cmake/googletest.imp mode change 100644 => 120000 cmake/project-import/sample_client.cc diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml new file mode 100644 index 00000000..557edeaa --- /dev/null +++ b/.github/workflows/linting.yml @@ -0,0 +1,40 @@ +name: Linting +on: [push, pull_request] + +jobs: + build: + name: Include What You Use + runs-on: ubuntu-20.04 + steps: + - name: Checkout source + uses: actions/checkout@v2 + + - name: Checkout submodules + shell: bash + run: | + auth_header="$(git config --local --get http.https://github.com/.extraheader)" + git submodule sync --recursive + git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1 + + - name: Install dependencies + run: | + sudo apt-get remove -y --purge man-db # avoid time-consuming trigger + sudo add-apt-repository ppa:gjasny/iwyu + sudo apt-get update + sudo apt-get install -y clang-11 iwyu libbenchmark-dev libcurl4-openssl-dev ninja-build zlib1g-dev + + - name: "CMake Configure" + run: cmake -GNinja -DRUN_IWYU=ON -S ${{ github.workspace }} -B ${{ github.workspace }}/_build + + - name: Build + run: cmake --build ${{ github.workspace }}/_build 2>&1 | tee ${{ github.workspace }}/output.txt + + - name: Check build output + run: if egrep -q 'should (add|remove) these lines' ${{ github.workspace }}/output.txt; then exit 1; fi + + #- name: "CMake Configure" + # run: cmake -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -S ${{ github.workspace }} -B ${{ github.workspace }}/_build + + #- name: "Run IWYU" + # run: iwyu_tool -p ${{ github.workspace }}/_build core push pull -- -Xiwyu --mapping_file=${{ github.workspace }}/cmake/googletest.imp -Xiwyu --no_fwd_decls 2>&1 | tee ${{ github.workspace }}/output.txt + diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ac303a3..372e9434 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,7 @@ option(ENABLE_TESTING "Build tests" ON) option(USE_THIRDPARTY_LIBRARIES "Use 3rdParty submodules" ON) option(THIRDPARTY_CIVETWEB_WITH_SSL "Enable SSL support for embedded civetweb source code") option(OVERRIDE_CXX_STANDARD_FLAGS "Force building with -std=c++11 even if the CXXLFAGS are configured differently" ON) +option(RUN_IWYU "Run include-what-you-use" OFF) if(OVERRIDE_CXX_STANDARD_FLAGS) set(CMAKE_CXX_STANDARD 11) @@ -53,6 +54,24 @@ endif() set(CMAKE_THREAD_PREFER_PTHREAD TRUE) find_package(Threads) +# include-what-you-use + +if(RUN_IWYU) + find_program(IWYU_EXECUTABLE NAMES include-what-you-use iwyu) + if(NOT IWYU_EXECUTABLE) + message(FATAL_ERROR "Include-what-you-use not found") + endif() + + set(IWYU_ARGS + "${IWYU_EXECUTABLE}" + "-Xiwyu" "--no_fwd_decls" + "-Xiwyu" "--mapping_file=${CMAKE_CURRENT_SOURCE_DIR}/cmake/googletest.imp" + ) + + set(CMAKE_C_INCLUDE_WHAT_YOU_USE ${IWYU_ARGS}) + set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${IWYU_ARGS}) +endif() + # check for required libatomic include(CheckAtomic) @@ -148,4 +167,5 @@ include(FeatureSummary) add_feature_info("Pull" "${ENABLE_PULL}" "support for pulling metrics") add_feature_info("Push" "${ENABLE_PUSH}" "support for pushing metrics to a push-gateway") add_feature_info("Compression" "${ENABLE_COMPRESSION}" "support for zlib compression of metrics") +add_feature_info("IYWU" "${RUN_IWYU}" "include-what-you-use") feature_summary(WHAT ALL) diff --git a/cmake/civetweb-3rdparty-config.cmake b/cmake/civetweb-3rdparty-config.cmake index d684361d..242509e5 100644 --- a/cmake/civetweb-3rdparty-config.cmake +++ b/cmake/civetweb-3rdparty-config.cmake @@ -60,3 +60,8 @@ if(BUILD_SHARED_LIBS) VISIBILITY_INLINES_HIDDEN ON ) endif() + +set_target_properties(civetweb PROPERTIES + C_INCLUDE_WHAT_YOU_USE "" + CXX_INCLUDE_WHAT_YOU_USE "" +) diff --git a/cmake/googlemock-3rdparty-config.cmake b/cmake/googlemock-3rdparty-config.cmake index c7bc4428..66defd2f 100644 --- a/cmake/googlemock-3rdparty-config.cmake +++ b/cmake/googlemock-3rdparty-config.cmake @@ -8,7 +8,7 @@ add_library(gmock_main STATIC EXCLUDE_FROM_ALL ${_IMPORT_PREFIX}/googlemock/src/gmock_main.cc ) -target_include_directories(gmock_main +target_include_directories(gmock_main SYSTEM PUBLIC ${_IMPORT_PREFIX}/googletest/include ${_IMPORT_PREFIX}/googlemock/include @@ -22,3 +22,8 @@ target_link_libraries(gmock_main Threads::Threads ) add_library(GTest::gmock_main ALIAS gmock_main) + +set_target_properties(gmock_main PROPERTIES + C_INCLUDE_WHAT_YOU_USE "" + CXX_INCLUDE_WHAT_YOU_USE "" +) diff --git a/cmake/googletest.imp b/cmake/googletest.imp new file mode 100644 index 00000000..29875d06 --- /dev/null +++ b/cmake/googletest.imp @@ -0,0 +1,4 @@ +[ + { include: [ "@", private, "", public ] }, + { include: [ "@", private, "", public ] } +] diff --git a/cmake/project-import/sample_client.cc b/cmake/project-import/sample_client.cc deleted file mode 100644 index 03414fe9..00000000 --- a/cmake/project-import/sample_client.cc +++ /dev/null @@ -1,65 +0,0 @@ -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#ifdef _WIN32 -#include -#else -#include -#include -#endif - -static std::string GetHostName() { - char hostname[1024]; - - if (::gethostname(hostname, sizeof(hostname))) { - return {}; - } - return hostname; -} - -int main() { - using namespace prometheus; - - // create a push gateway - const auto labels = Gateway::GetInstanceLabel(GetHostName()); - - Gateway gateway{"127.0.0.1", "9091", "sample_client", labels}; - - // create a metrics registry with component=main labels applied to all its - // metrics - auto registry = std::make_shared(); - - // add a new counter family to the registry (families combine values with the - // same name, but distinct label dimensions) - auto& counter_family = BuildCounter() - .Name("time_running_seconds_total") - .Help("How many seconds is this server running?") - .Labels({{"label", "value"}}) - .Register(*registry); - - // add a counter to the metric family - auto& second_counter = counter_family.Add( - {{"another_label", "value"}, {"yet_another_label", "value"}}); - - // ask the pusher to push the metrics to the pushgateway - gateway.RegisterCollectable(registry); - - for (;;) { - std::this_thread::sleep_for(std::chrono::seconds(1)); - // increment the counter by one (second) - second_counter.Increment(); - - // push metrics - auto returnCode = gateway.Push(); - std::cout << "returnCode is " << returnCode << std::endl; - } - return 0; -} diff --git a/cmake/project-import/sample_client.cc b/cmake/project-import/sample_client.cc new file mode 120000 index 00000000..4c67af80 --- /dev/null +++ b/cmake/project-import/sample_client.cc @@ -0,0 +1 @@ +../../push/tests/integration/sample_client.cc \ No newline at end of file diff --git a/core/benchmarks/benchmark_helpers.cc b/core/benchmarks/benchmark_helpers.cc index 8585b204..dc6ccea4 100644 --- a/core/benchmarks/benchmark_helpers.cc +++ b/core/benchmarks/benchmark_helpers.cc @@ -3,10 +3,10 @@ #include #include -std::string GenerateRandomString(size_t length) { +std::string GenerateRandomString(std::size_t length) { auto randchar = []() -> char { const char charset[] = "abcdefghijklmnopqrstuvwxyz"; - const size_t max_index = (sizeof(charset) - 1); + const std::size_t max_index = (sizeof(charset) - 1); return charset[rand() % max_index]; }; std::string str(length, 0); diff --git a/core/benchmarks/benchmark_helpers.h b/core/benchmarks/benchmark_helpers.h index 0b449a67..99cbeb03 100644 --- a/core/benchmarks/benchmark_helpers.h +++ b/core/benchmarks/benchmark_helpers.h @@ -1,8 +1,9 @@ #pragma once +#include #include #include -std::string GenerateRandomString(size_t length); +std::string GenerateRandomString(std::size_t length); std::map GenerateRandomLabels( std::size_t number_of_labels); diff --git a/core/benchmarks/counter_bench.cc b/core/benchmarks/counter_bench.cc index 3bae0557..620546f9 100644 --- a/core/benchmarks/counter_bench.cc +++ b/core/benchmarks/counter_bench.cc @@ -1,6 +1,10 @@ #include -#include -#include + +#include + +#include "prometheus/counter.h" +#include "prometheus/family.h" +#include "prometheus/registry.h" static void BM_Counter_Increment(benchmark::State& state) { using prometheus::BuildCounter; diff --git a/core/benchmarks/gauge_bench.cc b/core/benchmarks/gauge_bench.cc index d5afc492..d0c61f53 100644 --- a/core/benchmarks/gauge_bench.cc +++ b/core/benchmarks/gauge_bench.cc @@ -1,6 +1,10 @@ #include -#include -#include + +#include + +#include "prometheus/family.h" +#include "prometheus/gauge.h" +#include "prometheus/registry.h" static void BM_Gauge_Increment(benchmark::State& state) { using prometheus::BuildGauge; diff --git a/core/benchmarks/histogram_bench.cc b/core/benchmarks/histogram_bench.cc index 54458e68..64729451 100644 --- a/core/benchmarks/histogram_bench.cc +++ b/core/benchmarks/histogram_bench.cc @@ -1,9 +1,13 @@ #include -#include -#include #include #include +#include +#include + +#include "prometheus/family.h" +#include "prometheus/histogram.h" +#include "prometheus/registry.h" using prometheus::Histogram; diff --git a/core/benchmarks/registry_bench.cc b/core/benchmarks/registry_bench.cc index 67054da0..b33ddc4d 100644 --- a/core/benchmarks/registry_bench.cc +++ b/core/benchmarks/registry_bench.cc @@ -1,10 +1,11 @@ #include -#include -#include #include #include "benchmark_helpers.h" +#include "prometheus/counter.h" +#include "prometheus/family.h" +#include "prometheus/registry.h" static void BM_Registry_CreateFamily(benchmark::State& state) { using prometheus::BuildCounter; diff --git a/core/benchmarks/summary_bench.cc b/core/benchmarks/summary_bench.cc index d19c4cdc..da80811f 100644 --- a/core/benchmarks/summary_bench.cc +++ b/core/benchmarks/summary_bench.cc @@ -1,9 +1,15 @@ #include -#include -#include +#include #include +#include #include +#include +#include + +#include "prometheus/family.h" +#include "prometheus/registry.h" +#include "prometheus/summary.h" using prometheus::Summary; diff --git a/core/include/prometheus/counter.h b/core/include/prometheus/counter.h index 6ec01dd8..c67ddde2 100644 --- a/core/include/prometheus/counter.h +++ b/core/include/prometheus/counter.h @@ -1,7 +1,7 @@ #pragma once #include "prometheus/client_metric.h" -#include "prometheus/detail/builder.h" +#include "prometheus/detail/builder.h" // IWYU pragma: export #include "prometheus/detail/core_export.h" #include "prometheus/gauge.h" #include "prometheus/metric_type.h" diff --git a/core/include/prometheus/detail/builder.h b/core/include/prometheus/detail/builder.h index 0278d993..f811498f 100644 --- a/core/include/prometheus/detail/builder.h +++ b/core/include/prometheus/detail/builder.h @@ -3,11 +3,14 @@ #include #include +// IWYU pragma: private +// IWYU pragma: no_include "prometheus/family.h" + namespace prometheus { template -class Family; -class Registry; +class Family; // IWYU pragma: keep +class Registry; // IWYU pragma: keep namespace detail { diff --git a/core/include/prometheus/detail/ckms_quantiles.h b/core/include/prometheus/detail/ckms_quantiles.h index da0950fc..dad7815c 100644 --- a/core/include/prometheus/detail/ckms_quantiles.h +++ b/core/include/prometheus/detail/ckms_quantiles.h @@ -7,6 +7,8 @@ #include "prometheus/detail/core_export.h" +// IWYU pragma: private, include "prometheus/summary.h" + namespace prometheus { namespace detail { diff --git a/core/include/prometheus/detail/time_window_quantiles.h b/core/include/prometheus/detail/time_window_quantiles.h index 3a3ac65c..498baed2 100644 --- a/core/include/prometheus/detail/time_window_quantiles.h +++ b/core/include/prometheus/detail/time_window_quantiles.h @@ -4,9 +4,11 @@ #include #include -#include "prometheus/detail/ckms_quantiles.h" +#include "prometheus/detail/ckms_quantiles.h" // IWYU pragma: export #include "prometheus/detail/core_export.h" +// IWYU pragma: private, include "prometheus/summary.h" + namespace prometheus { namespace detail { diff --git a/core/include/prometheus/family.h b/core/include/prometheus/family.h index df282f12..1c333a7a 100644 --- a/core/include/prometheus/family.h +++ b/core/include/prometheus/family.h @@ -1,25 +1,24 @@ #pragma once -#include -#include #include #include #include #include -#include #include #include -#include #include -#include "prometheus/check_names.h" #include "prometheus/client_metric.h" #include "prometheus/collectable.h" #include "prometheus/detail/core_export.h" #include "prometheus/detail/future_std.h" -#include "prometheus/detail/utils.h" #include "prometheus/metric_family.h" +// IWYU pragma: no_include "prometheus/counter.h" +// IWYU pragma: no_include "prometheus/gauge.h" +// IWYU pragma: no_include "prometheus/histogram.h" +// IWYU pragma: no_include "prometheus/summary.h" + namespace prometheus { /// \brief A metric of type T with a set of labeled dimensions. diff --git a/core/include/prometheus/gauge.h b/core/include/prometheus/gauge.h index 467115b2..62498376 100644 --- a/core/include/prometheus/gauge.h +++ b/core/include/prometheus/gauge.h @@ -3,7 +3,7 @@ #include #include "prometheus/client_metric.h" -#include "prometheus/detail/builder.h" +#include "prometheus/detail/builder.h" // IWYU pragma: export #include "prometheus/detail/core_export.h" #include "prometheus/metric_type.h" diff --git a/core/include/prometheus/histogram.h b/core/include/prometheus/histogram.h index c720609a..f8be2435 100644 --- a/core/include/prometheus/histogram.h +++ b/core/include/prometheus/histogram.h @@ -4,7 +4,7 @@ #include "prometheus/client_metric.h" #include "prometheus/counter.h" -#include "prometheus/detail/builder.h" +#include "prometheus/detail/builder.h" // IWYU pragma: export #include "prometheus/detail/core_export.h" #include "prometheus/gauge.h" #include "prometheus/metric_type.h" diff --git a/core/include/prometheus/registry.h b/core/include/prometheus/registry.h index c8fdeb20..ef83438c 100644 --- a/core/include/prometheus/registry.h +++ b/core/include/prometheus/registry.h @@ -8,7 +8,6 @@ #include "prometheus/collectable.h" #include "prometheus/detail/core_export.h" -#include "prometheus/detail/future_std.h" #include "prometheus/family.h" #include "prometheus/metric_family.h" @@ -22,7 +21,7 @@ class Summary; namespace detail { template -class Builder; +class Builder; // IWYU pragma: keep } /// \brief Manages the collection of a number of metrics. diff --git a/core/include/prometheus/summary.h b/core/include/prometheus/summary.h index 7f6a4556..87381344 100644 --- a/core/include/prometheus/summary.h +++ b/core/include/prometheus/summary.h @@ -6,7 +6,7 @@ #include #include "prometheus/client_metric.h" -#include "prometheus/detail/builder.h" +#include "prometheus/detail/builder.h" // IWYU pragma: export #include "prometheus/detail/ckms_quantiles.h" #include "prometheus/detail/core_export.h" #include "prometheus/detail/time_window_quantiles.h" diff --git a/core/include/prometheus/text_serializer.h b/core/include/prometheus/text_serializer.h index b1e22c00..315a164d 100644 --- a/core/include/prometheus/text_serializer.h +++ b/core/include/prometheus/text_serializer.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include "prometheus/detail/core_export.h" diff --git a/core/src/check_names.cc b/core/src/check_names.cc index 5a1443ae..284ec642 100644 --- a/core/src/check_names.cc +++ b/core/src/check_names.cc @@ -1,7 +1,9 @@ #include "prometheus/check_names.h" +#include #include +#include #if defined(__GLIBCXX__) && __GLIBCXX__ <= 20150623 #define STD_REGEX_IS_BROKEN diff --git a/core/src/detail/builder.cc b/core/src/detail/builder.cc index 2d82ad0d..72253834 100644 --- a/core/src/detail/builder.cc +++ b/core/src/detail/builder.cc @@ -1,6 +1,7 @@ #include "prometheus/detail/builder.h" #include "prometheus/counter.h" +#include "prometheus/detail/core_export.h" #include "prometheus/gauge.h" #include "prometheus/histogram.h" #include "prometheus/registry.h" diff --git a/core/src/detail/ckms_quantiles.cc b/core/src/detail/ckms_quantiles.cc index 63205dbc..7ab6f1f2 100644 --- a/core/src/detail/ckms_quantiles.cc +++ b/core/src/detail/ckms_quantiles.cc @@ -1,8 +1,9 @@ -#include "prometheus/detail/ckms_quantiles.h" +#include "prometheus/detail/ckms_quantiles.h" // IWYU pragma: export #include #include #include +#include namespace prometheus { namespace detail { diff --git a/core/src/detail/time_window_quantiles.cc b/core/src/detail/time_window_quantiles.cc index e767122d..57f1e1c6 100644 --- a/core/src/detail/time_window_quantiles.cc +++ b/core/src/detail/time_window_quantiles.cc @@ -1,4 +1,7 @@ -#include "prometheus/detail/time_window_quantiles.h" +#include "prometheus/detail/time_window_quantiles.h" // IWYU pragma: export + +#include +#include namespace prometheus { namespace detail { diff --git a/core/src/detail/utils.cc b/core/src/detail/utils.cc index 754ddc2d..c8b08ccb 100644 --- a/core/src/detail/utils.cc +++ b/core/src/detail/utils.cc @@ -1,6 +1,6 @@ #include "prometheus/detail/utils.h" -#include +#include #include "hash.h" diff --git a/core/src/family.cc b/core/src/family.cc index 7ed5a1dc..9d5ed362 100644 --- a/core/src/family.cc +++ b/core/src/family.cc @@ -1,8 +1,14 @@ #include "prometheus/family.h" +#include +#include #include +#include +#include +#include "prometheus/check_names.h" #include "prometheus/counter.h" +#include "prometheus/detail/utils.h" #include "prometheus/gauge.h" #include "prometheus/histogram.h" #include "prometheus/summary.h" diff --git a/core/src/histogram.cc b/core/src/histogram.cc index de2efeb0..9c05d066 100644 --- a/core/src/histogram.cc +++ b/core/src/histogram.cc @@ -4,8 +4,10 @@ #include #include #include -#include +#include #include +#include +#include namespace prometheus { diff --git a/core/src/registry.cc b/core/src/registry.cc index 7f91472e..ad565d35 100644 --- a/core/src/registry.cc +++ b/core/src/registry.cc @@ -1,8 +1,12 @@ #include "prometheus/registry.h" +#include #include +#include +#include #include "prometheus/counter.h" +#include "prometheus/detail/future_std.h" #include "prometheus/gauge.h" #include "prometheus/histogram.h" #include "prometheus/summary.h" diff --git a/core/src/serializer.cc b/core/src/serializer.cc index 4f86c455..69e6a580 100644 --- a/core/src/serializer.cc +++ b/core/src/serializer.cc @@ -1,6 +1,6 @@ #include "prometheus/serializer.h" -#include +#include // IWYU pragma: keep namespace prometheus { diff --git a/core/src/summary.cc b/core/src/summary.cc index 7ed9de61..5e309795 100644 --- a/core/src/summary.cc +++ b/core/src/summary.cc @@ -1,5 +1,7 @@ #include "prometheus/summary.h" +#include + namespace prometheus { Summary::Summary(const Quantiles& quantiles, diff --git a/core/src/text_serializer.cc b/core/src/text_serializer.cc index 858c6150..71af4ab9 100644 --- a/core/src/text_serializer.cc +++ b/core/src/text_serializer.cc @@ -5,6 +5,7 @@ #include #include #include +#include #if __cpp_lib_to_chars >= 201611L #include @@ -15,6 +16,10 @@ #include #endif +#include "prometheus/client_metric.h" +#include "prometheus/metric_family.h" +#include "prometheus/metric_type.h" + namespace prometheus { namespace { diff --git a/core/tests/builder_test.cc b/core/tests/builder_test.cc index 2bbc54c1..ce460d73 100644 --- a/core/tests/builder_test.cc +++ b/core/tests/builder_test.cc @@ -1,8 +1,17 @@ #include +#include #include - +#include +#include +#include +#include +#include +#include + +#include "prometheus/client_metric.h" #include "prometheus/counter.h" +#include "prometheus/family.h" #include "prometheus/gauge.h" #include "prometheus/histogram.h" #include "prometheus/registry.h" diff --git a/core/tests/check_names_test.cc b/core/tests/check_names_test.cc index aa6c77a9..3201c85b 100644 --- a/core/tests/check_names_test.cc +++ b/core/tests/check_names_test.cc @@ -1,6 +1,6 @@ #include "prometheus/check_names.h" -#include +#include namespace prometheus { namespace { diff --git a/core/tests/counter_test.cc b/core/tests/counter_test.cc index 1c5566cb..9087e9bd 100644 --- a/core/tests/counter_test.cc +++ b/core/tests/counter_test.cc @@ -1,6 +1,6 @@ #include "prometheus/counter.h" -#include +#include namespace prometheus { namespace { diff --git a/core/tests/family_test.cc b/core/tests/family_test.cc index d68a6a21..8da3cd64 100644 --- a/core/tests/family_test.cc +++ b/core/tests/family_test.cc @@ -1,10 +1,12 @@ #include "prometheus/family.h" #include +#include #include #include "prometheus/client_metric.h" +#include "prometheus/counter.h" #include "prometheus/detail/future_std.h" #include "prometheus/histogram.h" diff --git a/core/tests/gauge_test.cc b/core/tests/gauge_test.cc index f4f2b48a..690754b0 100644 --- a/core/tests/gauge_test.cc +++ b/core/tests/gauge_test.cc @@ -1,6 +1,6 @@ #include "prometheus/gauge.h" -#include +#include namespace prometheus { namespace { diff --git a/core/tests/histogram_test.cc b/core/tests/histogram_test.cc index 6c3b30df..86cc66a8 100644 --- a/core/tests/histogram_test.cc +++ b/core/tests/histogram_test.cc @@ -1,8 +1,10 @@ #include "prometheus/histogram.h" -#include +#include #include +#include +#include namespace prometheus { namespace { diff --git a/core/tests/registry_test.cc b/core/tests/registry_test.cc index 6a02981f..69937074 100644 --- a/core/tests/registry_test.cc +++ b/core/tests/registry_test.cc @@ -1,10 +1,12 @@ #include "prometheus/registry.h" -#include +#include +#include #include #include "prometheus/counter.h" +#include "prometheus/gauge.h" #include "prometheus/histogram.h" #include "prometheus/summary.h" diff --git a/core/tests/serializer_test.cc b/core/tests/serializer_test.cc index 528f649d..cdb5a9c5 100644 --- a/core/tests/serializer_test.cc +++ b/core/tests/serializer_test.cc @@ -1,11 +1,16 @@ #include +#include #include #include +#include +#include +#include #include "prometheus/counter.h" #include "prometheus/detail/future_std.h" #include "prometheus/family.h" +#include "prometheus/metric_family.h" #include "prometheus/text_serializer.h" #include "raii_locale.h" diff --git a/core/tests/summary_test.cc b/core/tests/summary_test.cc index 2efb4d7b..ffebd9bd 100644 --- a/core/tests/summary_test.cc +++ b/core/tests/summary_test.cc @@ -1,8 +1,10 @@ #include "prometheus/summary.h" -#include +#include #include +#include +#include #include namespace prometheus { diff --git a/core/tests/text_serializer_test.cc b/core/tests/text_serializer_test.cc index 6b9bc479..0ef68a0d 100644 --- a/core/tests/text_serializer_test.cc +++ b/core/tests/text_serializer_test.cc @@ -1,13 +1,16 @@ #include "prometheus/text_serializer.h" #include +#include #include #include +#include -#include "prometheus/family.h" -#include "prometheus/gauge.h" +#include "prometheus/client_metric.h" #include "prometheus/histogram.h" +#include "prometheus/metric_family.h" +#include "prometheus/metric_type.h" #include "prometheus/summary.h" namespace prometheus { diff --git a/core/tests/utils_test.cc b/core/tests/utils_test.cc index b1432e10..76451f65 100644 --- a/core/tests/utils_test.cc +++ b/core/tests/utils_test.cc @@ -1,8 +1,9 @@ #include "prometheus/detail/utils.h" -#include +#include #include +#include namespace prometheus { diff --git a/pull/include/prometheus/exposer.h b/pull/include/prometheus/exposer.h index e6ceb85f..3e4e01c4 100644 --- a/pull/include/prometheus/exposer.h +++ b/pull/include/prometheus/exposer.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include #include @@ -8,7 +8,6 @@ #include "prometheus/collectable.h" #include "prometheus/detail/pull_export.h" -#include "prometheus/registry.h" class CivetServer; @@ -16,7 +15,6 @@ namespace prometheus { namespace detail { class Endpoint; -class MetricsHandler; } // namespace detail class PROMETHEUS_CPP_PULL_EXPORT Exposer { diff --git a/pull/src/basic_auth.cc b/pull/src/basic_auth.cc index 7bae3ca4..a669c586 100644 --- a/pull/src/basic_auth.cc +++ b/pull/src/basic_auth.cc @@ -1,8 +1,9 @@ #include "basic_auth.h" +#include + #include "CivetServer.h" #include "detail/base64.h" -#include "prometheus/detail/future_std.h" namespace prometheus { diff --git a/pull/src/basic_auth.h b/pull/src/basic_auth.h index 87109dbf..3047b951 100644 --- a/pull/src/basic_auth.h +++ b/pull/src/basic_auth.h @@ -2,10 +2,9 @@ #include #include -#include #include "CivetServer.h" -#include "prometheus/detail/pull_export.h" +#include "civetweb.h" namespace prometheus { diff --git a/pull/src/detail/base64.h b/pull/src/detail/base64.h index 256dcc39..36233252 100644 --- a/pull/src/detail/base64.h +++ b/pull/src/detail/base64.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include diff --git a/pull/src/endpoint.cc b/pull/src/endpoint.cc index 68d42a4d..3e8ab3fb 100644 --- a/pull/src/endpoint.cc +++ b/pull/src/endpoint.cc @@ -1,5 +1,7 @@ #include "endpoint.h" +#include + #include "basic_auth.h" #include "handler.h" #include "prometheus/detail/future_std.h" diff --git a/pull/src/endpoint.h b/pull/src/endpoint.h index 2a58d847..e0605e35 100644 --- a/pull/src/endpoint.h +++ b/pull/src/endpoint.h @@ -3,14 +3,12 @@ #include #include #include -#include +#include "CivetServer.h" #include "basic_auth.h" #include "prometheus/collectable.h" #include "prometheus/registry.h" -class CivetServer; - namespace prometheus { namespace detail { class MetricsHandler; diff --git a/pull/src/exposer.cc b/pull/src/exposer.cc index b61737c0..ac53bc86 100644 --- a/pull/src/exposer.cc +++ b/pull/src/exposer.cc @@ -1,13 +1,12 @@ #include "prometheus/exposer.h" -#include +#include +#include #include -#include +#include #include "CivetServer.h" #include "endpoint.h" -#include "handler.h" -#include "prometheus/client_metric.h" #include "prometheus/detail/future_std.h" namespace prometheus { diff --git a/pull/src/handler.cc b/pull/src/handler.cc index 20a552a0..83eb19ea 100644 --- a/pull/src/handler.cc +++ b/pull/src/handler.cc @@ -1,17 +1,23 @@ #include "handler.h" #include +#include +#include #include - -#include "prometheus/counter.h" -#include "prometheus/summary.h" +#include +#include #ifdef HAVE_ZLIB +#include #include #endif +#include "civetweb.h" #include "metrics_collector.h" +#include "prometheus/counter.h" +#include "prometheus/metric_family.h" #include "prometheus/serializer.h" +#include "prometheus/summary.h" #include "prometheus/text_serializer.h" namespace prometheus { diff --git a/pull/src/handler.h b/pull/src/handler.h index 017e2a7e..10c90f9f 100644 --- a/pull/src/handler.h +++ b/pull/src/handler.h @@ -5,7 +5,9 @@ #include #include "CivetServer.h" +#include "prometheus/collectable.h" #include "prometheus/counter.h" +#include "prometheus/family.h" #include "prometheus/registry.h" #include "prometheus/summary.h" diff --git a/pull/src/metrics_collector.cc b/pull/src/metrics_collector.cc index 4235e6fd..0372d693 100644 --- a/pull/src/metrics_collector.cc +++ b/pull/src/metrics_collector.cc @@ -1,5 +1,7 @@ #include "metrics_collector.h" +#include + #include "prometheus/collectable.h" namespace prometheus { diff --git a/pull/tests/integration/integration_test.cc b/pull/tests/integration/integration_test.cc index e5832c1d..49c79176 100644 --- a/pull/tests/integration/integration_test.cc +++ b/pull/tests/integration/integration_test.cc @@ -1,13 +1,18 @@ #include #include +#include +#include #include #include +#include #include +#include #include "prometheus/counter.h" #include "prometheus/detail/future_std.h" #include "prometheus/exposer.h" +#include "prometheus/family.h" #include "prometheus/registry.h" namespace prometheus { @@ -154,7 +159,7 @@ TEST_F(IntegrationTest, acceptOptionalCompression) { EXPECT_THAT(metrics.body, HasSubstr(counter_name)); } -#if 0 // https://github.com/civetweb/civetweb/issues/954 +#if 0 // https://github.com/civetweb/civetweb/issues/954 TEST_F(IntegrationTest, shouldRejectRequestWithoutAuthorization) { const std::string counter_name = "example_total"; auto registry = RegisterSomeCounter(counter_name, default_metrics_path_); @@ -185,7 +190,8 @@ TEST_F(IntegrationTest, shouldPerformProperAuthentication) { }; exposer_->RegisterAuth( - [my_username, my_password](const std::string& user, const std::string& password) { + [my_username, my_password](const std::string& user, + const std::string& password) { return user == my_username && password == my_password; }, "Some Auth Realm", default_metrics_path_); diff --git a/pull/tests/integration/sample_server.cc b/pull/tests/integration/sample_server.cc index 55ce0163..742a365c 100644 --- a/pull/tests/integration/sample_server.cc +++ b/pull/tests/integration/sample_server.cc @@ -1,7 +1,3 @@ -#include -#include -#include - #include #include #include @@ -9,6 +5,12 @@ #include #include +#include "prometheus/client_metric.h" +#include "prometheus/counter.h" +#include "prometheus/exposer.h" +#include "prometheus/family.h" +#include "prometheus/registry.h" + int main() { using namespace prometheus; diff --git a/pull/tests/integration/sample_server_auth.cc b/pull/tests/integration/sample_server_auth.cc index 1248d55b..b8ff99dd 100644 --- a/pull/tests/integration/sample_server_auth.cc +++ b/pull/tests/integration/sample_server_auth.cc @@ -1,11 +1,14 @@ -#include -#include -#include - #include #include +#include #include +#include "prometheus/client_metric.h" +#include "prometheus/counter.h" +#include "prometheus/exposer.h" +#include "prometheus/family.h" +#include "prometheus/registry.h" + int main() { using namespace prometheus; diff --git a/pull/tests/integration/sample_server_multi.cc b/pull/tests/integration/sample_server_multi.cc index 4a86171a..9e9f41b0 100644 --- a/pull/tests/integration/sample_server_multi.cc +++ b/pull/tests/integration/sample_server_multi.cc @@ -1,11 +1,14 @@ -#include -#include -#include - #include #include +#include #include +#include "prometheus/client_metric.h" +#include "prometheus/counter.h" +#include "prometheus/exposer.h" +#include "prometheus/family.h" +#include "prometheus/registry.h" + int main() { using namespace prometheus; diff --git a/pull/tests/unit/exposer_test.cc b/pull/tests/unit/exposer_test.cc index 0c46f95b..94c2f32d 100644 --- a/pull/tests/unit/exposer_test.cc +++ b/pull/tests/unit/exposer_test.cc @@ -1,6 +1,6 @@ #include "prometheus/exposer.h" -#include +#include namespace prometheus { namespace { diff --git a/push/include/prometheus/gateway.h b/push/include/prometheus/gateway.h index 49f081c5..8e0191e3 100644 --- a/push/include/prometheus/gateway.h +++ b/push/include/prometheus/gateway.h @@ -1,14 +1,15 @@ #pragma once #include -#include #include #include +#include #include +#include #include +#include "prometheus/collectable.h" #include "prometheus/detail/push_export.h" -#include "prometheus/registry.h" namespace prometheus { diff --git a/push/src/gateway.cc b/push/src/gateway.cc index 41c0f2f5..41801909 100644 --- a/push/src/gateway.cc +++ b/push/src/gateway.cc @@ -3,15 +3,19 @@ #include +#include +#include #include #include #include -#include "prometheus/client_metric.h" #include "prometheus/detail/future_std.h" -#include "prometheus/serializer.h" +#include "prometheus/metric_family.h" // IWYU pragma: keep #include "prometheus/text_serializer.h" +// IWYU pragma: no_include +// IWYU pragma: no_include + namespace prometheus { static const char CONTENT_TYPE[] = diff --git a/push/tests/integration/sample_client.cc b/push/tests/integration/sample_client.cc index 03414fe9..d2c5f8bf 100644 --- a/push/tests/integration/sample_client.cc +++ b/push/tests/integration/sample_client.cc @@ -1,18 +1,18 @@ -#include -#include -#include - #include #include -#include #include #include #include +#include "prometheus/client_metric.h" +#include "prometheus/counter.h" +#include "prometheus/family.h" +#include "prometheus/gateway.h" +#include "prometheus/registry.h" + #ifdef _WIN32 #include #else -#include #include #endif