diff --git a/.github/workflows/ci-vcpkg.yml b/.github/workflows/ci-vcpkg.yml new file mode 100644 index 000000000..3f5bf7c6e --- /dev/null +++ b/.github/workflows/ci-vcpkg.yml @@ -0,0 +1,73 @@ +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 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 system deps [Windows] + if: runner.os == 'Windows' + run: | + 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] + 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 }} + shell: bash + run: | + "${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: | + $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 }} + run: cmake --build .cmake-build -j"$(nproc)" + - name: Test + working-directory: ${{ inputs.working-directory }} + run: ctest --test-dir .cmake-build -VV diff --git a/.github/workflows/prometheus.yml b/.github/workflows/prometheus.yml index e81827bff..bc0b6680c 100644 --- a/.github/workflows/prometheus.yml +++ b/.github/workflows/prometheus.yml @@ -7,12 +7,14 @@ on: - 'main' paths: - "exporters/prometheus/**" + - '.github/workflows/ci-*.yml' - ".github/workflows/prometheus.yml" pull_request: branches: - 'main' paths: - "exporters/prometheus/**" + - '.github/workflows/ci-*.yml' - ".github/workflows/prometheus.yml" permissions: @@ -136,3 +138,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/CMakeLists.txt b/exporters/prometheus/CMakeLists.txt index fe1fe0725..12491b90c 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) +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; diff --git a/exporters/prometheus/vcpkg.json b/exporters/prometheus/vcpkg.json new file mode 100644 index 000000000..f0eaa54c3 --- /dev/null +++ b/exporters/prometheus/vcpkg.json @@ -0,0 +1,32 @@ +{ + "name": "otel-prometheus-exporter", + "version-string": "1.19.0", + "dependencies": [ + { + "name": "opentelemetry-cpp", + "features": [ + "prometheus" + ] + }, + { + "name": "prometheus-cpp", + "features": [ + "pull", + "push" + ] + }, + "nlohmann-json", + "gtest", + "benchmark", + "curl", + "openssl", + "zlib" + ], + "overrides": [ + { + "name": "opentelemetry-cpp", + "version": "1.28.0" + } + ], + "builtin-baseline": "b4ae67c6051bb665f9414fca5c66f66cacc71970" +}