Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
73 changes: 73 additions & 0 deletions .github/workflows/ci-vcpkg.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions .github/workflows/prometheus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
3 changes: 1 addition & 2 deletions exporters/prometheus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
43 changes: 23 additions & 20 deletions exporters/prometheus/test/push_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ namespace metrics
class PrometheusPushExporterTest
{ // : public ::testing::Test
public:
PrometheusPushExporter GetExporter() { return PrometheusPushExporter(); }
std::unique_ptr<PrometheusPushExporter> GetExporter() {
PrometheusPushExporterOptions opts{};
return std::make_unique<PrometheusPushExporter>(opts);
}

void CheckFactory(PrometheusPushExporter &exporter, const PrometheusPushExporterOptions &options)
{
Expand All @@ -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());
}

/**
Expand All @@ -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());
}

/**
Expand All @@ -89,15 +92,15 @@ 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",
"1.9.1");

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;
Expand All @@ -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",
Expand All @@ -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;
Expand All @@ -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",
Expand All @@ -159,15 +162,15 @@ 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);
}

auto data = CreateSumPointData(instrumentation_scope.get());

// 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;
Expand All @@ -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;
Expand Down
32 changes: 32 additions & 0 deletions exporters/prometheus/vcpkg.json
Original file line number Diff line number Diff line change
@@ -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"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be 1.29.0?

}
],
"builtin-baseline": "b4ae67c6051bb665f9414fca5c66f66cacc71970"
}
Loading