From b2ddbc3ed6252729467408ece9bb21c1c6359662 Mon Sep 17 00:00:00 2001 From: James Thompson Date: Tue, 22 Sep 2026 23:35:12 +1000 Subject: [PATCH 1/6] Add reusable vcpkg workflow --- .github/workflows/ci-vcpkg.yml | 65 ++++++++++++++++++++++++++++++++ .github/workflows/prometheus.yml | 6 +++ exporters/prometheus/vcpkg.json | 40 ++++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 .github/workflows/ci-vcpkg.yml create mode 100644 exporters/prometheus/vcpkg.json diff --git a/.github/workflows/ci-vcpkg.yml b/.github/workflows/ci-vcpkg.yml new file mode 100644 index 000000000..7e566064b --- /dev/null +++ b/.github/workflows/ci-vcpkg.yml @@ -0,0 +1,65 @@ +name: vcpkg + +on: + workflow_call: + inputs: + working-directory: + required: true + type: string + +jobs: + build: + name: ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-26.04 + - Windows-2025 + steps: + - name: Checkout repo + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Install deps (Linux) + if: runner.os == 'Linux' + run: | + sudo apt update -y + sudo apt install -y --no-install-recommends --no-install-suggests \ + git cmake ninja-build pkg-config + - name: Install deps (Windows) + if: runner.os == 'Windows' + run: | + choco install ninja -y + choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System' -y + - name: Clone vcpkg + run: | + git clone https://github.com/microsoft/vcpkg.git "${GITHUB_WORKSPACE}/vcpkg" + - name: Bootstrap vcpkg (Linux) + if: runner.os == 'Linux' + run: | + cd "${GITHUB_WORKSPACE}/vcpkg" + ./bootstrap-vcpkg.sh + - name: Bootstrap vcpkg (Windows) + if: runner.os == 'Windows' + run: | + cd "${{ github.workspace }}\\vcpkg" + .\\bootstrap-vcpkg.bat + - name: Install dependencies from manifest + working-directory: ${{ inputs.working-directory }} + run: | + "${GITHUB_WORKSPACE}/vcpkg/vcpkg" install --triplet=x64-linux + - name: Configure (CMake + vcpkg toolchain) + working-directory: ${{ inputs.working-directory }} + run: | + cmake -S . -B build \ + -G Ninja \ + "-DCMAKE_TOOLCHAIN_FILE=${GITHUB_WORKSPACE}/vcpkg/scripts/buildsystems/vcpkg.cmake" \ + -DCMAKE_BUILD_TYPE=Debug + - name: Build + working-directory: ${{ inputs.working-directory }}/build + run: cmake --build . -j"$(nproc)" + - name: Test + working-directory: ${{ inputs.working-directory }}/build + run: ctest -VV diff --git a/.github/workflows/prometheus.yml b/.github/workflows/prometheus.yml index e81827bff..a54a920f6 100644 --- a/.github/workflows/prometheus.yml +++ b/.github/workflows/prometheus.yml @@ -7,6 +7,7 @@ on: - 'main' paths: - "exporters/prometheus/**" + - '.github/workflows/ci-vcpkg.yml' - ".github/workflows/prometheus.yml" pull_request: branches: @@ -136,3 +137,8 @@ jobs: -DCMAKE_BUILD_TYPE=Debug cmake --build . -j$(nproc) ctest -VV -R "opentelemetry_cpp_ecosystem_test.*" . + + vcpkg: + uses: ./.github/workflows/ci-vcpkg.yml + with: + working-directory: "exporters/prometheus" diff --git a/exporters/prometheus/vcpkg.json b/exporters/prometheus/vcpkg.json new file mode 100644 index 000000000..82aeb0d08 --- /dev/null +++ b/exporters/prometheus/vcpkg.json @@ -0,0 +1,40 @@ +{ + "name": "otel-prometheus-exporter", + "version-string": "0.1.0", + "dependencies": [ + { + "name": "opentelemetry-cpp", + "default-features": false, + "features": [ + "prometheus", + "metrics", + "resources" + ] + }, + { + "name": "prometheus-cpp", + "default-features": false, + "features": [ + "compression", + "core", + "pull", + "push" + ] + }, + "nlohmann-json", + "gtest", + "benchmark", + { + "name": "curl", + "default-features": false, + "features": [ + "core", + "non-http", + "openssl", + "ssl" + ] + }, + "openssl", + "zlib" + ] +} From 3d1c32ee512d77b96eff6e8fc99a90280168a422 Mon Sep 17 00:00:00 2001 From: James Thompson Date: Tue, 22 Sep 2026 23:42:22 +1000 Subject: [PATCH 2/6] review feedback --- .github/workflows/prometheus.yml | 2 +- exporters/prometheus/vcpkg.json | 12 +----------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/.github/workflows/prometheus.yml b/.github/workflows/prometheus.yml index a54a920f6..6b9469c71 100644 --- a/.github/workflows/prometheus.yml +++ b/.github/workflows/prometheus.yml @@ -139,6 +139,6 @@ jobs: ctest -VV -R "opentelemetry_cpp_ecosystem_test.*" . vcpkg: - uses: ./.github/workflows/ci-vcpkg.yml + uses: $/.github/workflows/ci-vcpkg.yml with: working-directory: "exporters/prometheus" diff --git a/exporters/prometheus/vcpkg.json b/exporters/prometheus/vcpkg.json index 82aeb0d08..f9d63bb0e 100644 --- a/exporters/prometheus/vcpkg.json +++ b/exporters/prometheus/vcpkg.json @@ -16,7 +16,6 @@ "default-features": false, "features": [ "compression", - "core", "pull", "push" ] @@ -24,16 +23,7 @@ "nlohmann-json", "gtest", "benchmark", - { - "name": "curl", - "default-features": false, - "features": [ - "core", - "non-http", - "openssl", - "ssl" - ] - }, + "curl", "openssl", "zlib" ] From b793f40538e8f92b7e23fa9fb860d08d8a8d051b Mon Sep 17 00:00:00 2001 From: James Thompson Date: Tue, 22 Sep 2026 23:50:48 +1000 Subject: [PATCH 3/6] error fix --- .github/workflows/ci-vcpkg.yml | 36 +++++++++++++++++++------------- .github/workflows/prometheus.yml | 3 ++- exporters/prometheus/vcpkg.json | 18 +++++++++------- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ci-vcpkg.yml b/.github/workflows/ci-vcpkg.yml index 7e566064b..bdaf25d11 100644 --- a/.github/workflows/ci-vcpkg.yml +++ b/.github/workflows/ci-vcpkg.yml @@ -22,44 +22,52 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - - name: Install deps (Linux) + - name: Install deps [Linux] if: runner.os == 'Linux' run: | sudo apt update -y sudo apt install -y --no-install-recommends --no-install-suggests \ - git cmake ninja-build pkg-config - - name: Install deps (Windows) + cmake ninja-build pkg-config + - name: Install deps [Windows] if: runner.os == 'Windows' run: | - choco install ninja -y choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System' -y - name: Clone vcpkg + shell: bash run: | git clone https://github.com/microsoft/vcpkg.git "${GITHUB_WORKSPACE}/vcpkg" - - name: Bootstrap vcpkg (Linux) + - name: Bootstrap vcpkg [Linux] if: runner.os == 'Linux' run: | cd "${GITHUB_WORKSPACE}/vcpkg" ./bootstrap-vcpkg.sh - - name: Bootstrap vcpkg (Windows) + - name: Bootstrap vcpkg [Windows] if: runner.os == 'Windows' run: | cd "${{ github.workspace }}\\vcpkg" .\\bootstrap-vcpkg.bat - name: Install dependencies from manifest working-directory: ${{ inputs.working-directory }} + shell: bash run: | - "${GITHUB_WORKSPACE}/vcpkg/vcpkg" install --triplet=x64-linux - - name: Configure (CMake + vcpkg toolchain) + "${GITHUB_WORKSPACE}/vcpkg/vcpkg" install + - name: Configure (CMake + vcpkg toolchain) [Linux] + if: runner.os == 'Linux' + working-directory: ${{ inputs.working-directory }} + shell: pwsh + run: | + $toolchain = "$env:GITHUB_WORKSPACE/vcpkg/scripts/buildsystems/vcpkg.cmake" + cmake -S . -B .cmake-build -G Ninja "-DCMAKE_TOOLCHAIN_FILE=$toolchain" -DCMAKE_BUILD_TYPE=DebugDebug + - name: Configure (CMake + vcpkg toolchain) [Windows] + if: runner.os == 'Windows' working-directory: ${{ inputs.working-directory }} + shell: pwsh run: | - cmake -S . -B build \ - -G Ninja \ - "-DCMAKE_TOOLCHAIN_FILE=${GITHUB_WORKSPACE}/vcpkg/scripts/buildsystems/vcpkg.cmake" \ - -DCMAKE_BUILD_TYPE=Debug + $toolchain = "$env:GITHUB_WORKSPACE/vcpkg/scripts/buildsystems/vcpkg.cmake" + cmake -S . -B .cmake-build "-DCMAKE_TOOLCHAIN_FILE=$toolchain" -DCMAKE_BUILD_TYPE=Debug - name: Build - working-directory: ${{ inputs.working-directory }}/build + working-directory: ${{ inputs.working-directory }}/.cmake-build run: cmake --build . -j"$(nproc)" - name: Test - working-directory: ${{ inputs.working-directory }}/build + working-directory: ${{ inputs.working-directory }}/.cmake-build run: ctest -VV diff --git a/.github/workflows/prometheus.yml b/.github/workflows/prometheus.yml index 6b9469c71..bc0b6680c 100644 --- a/.github/workflows/prometheus.yml +++ b/.github/workflows/prometheus.yml @@ -7,13 +7,14 @@ on: - 'main' paths: - "exporters/prometheus/**" - - '.github/workflows/ci-vcpkg.yml' + - '.github/workflows/ci-*.yml' - ".github/workflows/prometheus.yml" pull_request: branches: - 'main' paths: - "exporters/prometheus/**" + - '.github/workflows/ci-*.yml' - ".github/workflows/prometheus.yml" permissions: diff --git a/exporters/prometheus/vcpkg.json b/exporters/prometheus/vcpkg.json index f9d63bb0e..f0eaa54c3 100644 --- a/exporters/prometheus/vcpkg.json +++ b/exporters/prometheus/vcpkg.json @@ -1,21 +1,16 @@ { "name": "otel-prometheus-exporter", - "version-string": "0.1.0", + "version-string": "1.19.0", "dependencies": [ { "name": "opentelemetry-cpp", - "default-features": false, "features": [ - "prometheus", - "metrics", - "resources" + "prometheus" ] }, { "name": "prometheus-cpp", - "default-features": false, "features": [ - "compression", "pull", "push" ] @@ -26,5 +21,12 @@ "curl", "openssl", "zlib" - ] + ], + "overrides": [ + { + "name": "opentelemetry-cpp", + "version": "1.28.0" + } + ], + "builtin-baseline": "b4ae67c6051bb665f9414fca5c66f66cacc71970" } From 6c24a9331c3577a5fc92440bd5aabe6af56cb19d Mon Sep 17 00:00:00 2001 From: James Thompson Date: Thu, 24 Sep 2026 12:54:39 +1000 Subject: [PATCH 4/6] prom changes --- exporters/prometheus/CMakeLists.txt | 3 +- .../prometheus/test/push_exporter_test.cc | 43 ++++++++++--------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/exporters/prometheus/CMakeLists.txt b/exporters/prometheus/CMakeLists.txt index fe1fe0725..1f0f2c56f 100644 --- a/exporters/prometheus/CMakeLists.txt +++ b/exporters/prometheus/CMakeLists.txt @@ -66,8 +66,7 @@ endif() include_directories(include) include(CMakeDependentOption) -cmake_dependent_option(BUILD_TESTING "Enable tests" ON - "NOT CMAKE_CROSSCOMPILING" OFF) +cmake_dependent_option(BUILD_TESTING "Enable tests" ON) if(BUILD_TESTING) enable_testing() diff --git a/exporters/prometheus/test/push_exporter_test.cc b/exporters/prometheus/test/push_exporter_test.cc index 6a819f369..7b7fb2b5c 100644 --- a/exporters/prometheus/test/push_exporter_test.cc +++ b/exporters/prometheus/test/push_exporter_test.cc @@ -29,7 +29,10 @@ namespace metrics class PrometheusPushExporterTest { // : public ::testing::Test public: - PrometheusPushExporter GetExporter() { return PrometheusPushExporter(); } + std::unique_ptr GetExporter() { + PrometheusPushExporterOptions opts{}; + return std::make_unique(opts); + } void CheckFactory(PrometheusPushExporter &exporter, const PrometheusPushExporterOptions &options) { @@ -55,10 +58,10 @@ using opentelemetry::exporter::metrics::PrometheusPushExporterTest; TEST(PrometheusPushExporter, InitializeConstructorIsNotShutdown) { PrometheusPushExporterTest p; - PrometheusPushExporter exporter = p.GetExporter(); + auto exporter = p.GetExporter(); // // Asserts that the exporter is not shutdown. - ASSERT_TRUE(!exporter.IsShutdown()); + ASSERT_TRUE(!exporter->IsShutdown()); } /** @@ -67,19 +70,19 @@ TEST(PrometheusPushExporter, InitializeConstructorIsNotShutdown) TEST(PrometheusPushExporter, ShutdownSetsIsShutdownToTrue) { PrometheusPushExporterTest p; - PrometheusPushExporter exporter = p.GetExporter(); + auto exporter = p.GetExporter(); // exporter shuold not be shutdown by default - ASSERT_TRUE(!exporter.IsShutdown()); + ASSERT_TRUE(!exporter->IsShutdown()); - exporter.Shutdown(); + exporter->Shutdown(); // the exporter shuold be shutdown - ASSERT_TRUE(exporter.IsShutdown()); + ASSERT_TRUE(exporter->IsShutdown()); // shutdown function should be idempotent - exporter.Shutdown(); - ASSERT_TRUE(exporter.IsShutdown()); + exporter->Shutdown(); + ASSERT_TRUE(exporter->IsShutdown()); } /** @@ -89,7 +92,7 @@ TEST(PrometheusPushExporter, ShutdownSetsIsShutdownToTrue) TEST(PrometheusPushExporter, ExportSuccessfully) { PrometheusPushExporterTest p; - PrometheusPushExporter exporter = p.GetExporter(); + auto exporter = p.GetExporter(); auto instrumentation_scope = opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create("library_name", @@ -97,7 +100,7 @@ TEST(PrometheusPushExporter, ExportSuccessfully) auto data = CreateSumPointData(instrumentation_scope.get()); - auto res = exporter.Export(data); + auto res = exporter->Export(data); // result should be kSuccess = 0 ExportResult code = ExportResult::kSuccess; @@ -111,9 +114,9 @@ TEST(PrometheusPushExporter, ExportSuccessfully) TEST(PrometheusPushExporter, ExporterIsShutdown) { PrometheusPushExporterTest p; - PrometheusPushExporter exporter = p.GetExporter(); + auto exporter = p.GetExporter(); - exporter.Shutdown(); + exporter->Shutdown(); auto instrumentation_scope = opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create("library_name", @@ -122,7 +125,7 @@ TEST(PrometheusPushExporter, ExporterIsShutdown) auto data = CreateSumPointData(instrumentation_scope.get()); // send export request after shutdown - auto res = exporter.Export(data); + auto res = exporter->Export(data); // result code should be kFailure = 1 ExportResult code = ExportResult::kFailure; @@ -138,13 +141,13 @@ TEST(PrometheusPushExporter, ExporterIsShutdown) TEST(PrometheusPushExporter, CollectionNotEnoughSpace) { PrometheusPushExporterTest p; - PrometheusPushExporter exporter = p.GetExporter(); + auto exporter = p.GetExporter(); // prepare two collections of records to export, // one close to max size and another one that, when added // to the first, will exceed the size of the collection - int max_collection_size = exporter.GetMaxCollectionSize(); + int max_collection_size = exporter->GetMaxCollectionSize(); auto instrumentation_scope = opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create("library_name", @@ -159,7 +162,7 @@ TEST(PrometheusPushExporter, CollectionNotEnoughSpace) for (int count = 1; count <= max_collection_size; count += 2) { auto data = CreateSumPointData(instrumentation_scope.get()); - auto res = exporter.Export(data); + auto res = exporter->Export(data); ASSERT_EQ(res, code); } @@ -167,7 +170,7 @@ TEST(PrometheusPushExporter, CollectionNotEnoughSpace) // send export request that does not complete // due to not enough space in the collection - auto res = exporter.Export(data); + auto res = exporter->Export(data); // the result code should be kFailureFull = 2 code = ExportResult::kFailureFull; @@ -182,14 +185,14 @@ TEST(PrometheusPushExporter, CollectionNotEnoughSpace) TEST(PrometheusPushExporter, InvalidArgumentWhenPassedEmptyRecordCollection) { PrometheusPushExporterTest p; - PrometheusPushExporter exporter = p.GetExporter(); + auto exporter = p.GetExporter(); // Initializes an empty colelction of records metric_sdk::ResourceMetrics data; // send export request to fill the // collection in the collector - auto res = exporter.Export(data); + auto res = exporter->Export(data); // the result code should be kFailureInvalidArgument = 3 ExportResult code = ExportResult::kFailureInvalidArgument; From 852d60c44b4af482e37d7dda02d9badc0cf26c41 Mon Sep 17 00:00:00 2001 From: James Thompson Date: Thu, 24 Sep 2026 18:37:44 +1000 Subject: [PATCH 5/6] Update CMakeLists.txt --- exporters/prometheus/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporters/prometheus/CMakeLists.txt b/exporters/prometheus/CMakeLists.txt index 1f0f2c56f..12491b90c 100644 --- a/exporters/prometheus/CMakeLists.txt +++ b/exporters/prometheus/CMakeLists.txt @@ -66,7 +66,7 @@ endif() include_directories(include) include(CMakeDependentOption) -cmake_dependent_option(BUILD_TESTING "Enable tests" ON) +option(BUILD_TESTING "Enable tests" ON) if(BUILD_TESTING) enable_testing() From fc29829db214e9e2ca71889fa2d234b8151da02f Mon Sep 17 00:00:00 2001 From: James Thompson Date: Thu, 24 Sep 2026 19:51:02 +1000 Subject: [PATCH 6/6] Update ci-vcpkg.yml --- .github/workflows/ci-vcpkg.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci-vcpkg.yml b/.github/workflows/ci-vcpkg.yml index bdaf25d11..3f5bf7c6e 100644 --- a/.github/workflows/ci-vcpkg.yml +++ b/.github/workflows/ci-vcpkg.yml @@ -22,13 +22,13 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - - name: Install deps [Linux] + - name: Install system deps [Linux] if: runner.os == 'Linux' run: | sudo apt update -y sudo apt install -y --no-install-recommends --no-install-suggests \ cmake ninja-build pkg-config - - name: Install deps [Windows] + - name: Install system deps [Windows] if: runner.os == 'Windows' run: | choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System' -y @@ -66,8 +66,8 @@ jobs: $toolchain = "$env:GITHUB_WORKSPACE/vcpkg/scripts/buildsystems/vcpkg.cmake" cmake -S . -B .cmake-build "-DCMAKE_TOOLCHAIN_FILE=$toolchain" -DCMAKE_BUILD_TYPE=Debug - name: Build - working-directory: ${{ inputs.working-directory }}/.cmake-build - run: cmake --build . -j"$(nproc)" + working-directory: ${{ inputs.working-directory }} + run: cmake --build .cmake-build -j"$(nproc)" - name: Test - working-directory: ${{ inputs.working-directory }}/.cmake-build - run: ctest -VV + working-directory: ${{ inputs.working-directory }} + run: ctest --test-dir .cmake-build -VV