Skip to content

Commit

Permalink
Switched to vcpkg (#66)
Browse files Browse the repository at this point in the history
* Switched to vcpkg, disabled Prometheus Push Gateway for now

* CMake fix on Linux

* Added vcpkg stuff in workflow

* Moved vcpkg toolchain to all presets

* Explicitly call vpckg install in Linux

* Try another variant as well

* Syntax fix

* Fix case

* Fix & reformat workflows

* Fix integration test

* Remove unneeded variable
  • Loading branch information
DarkWanderer authored Sep 29, 2024
1 parent cca3c62 commit 564799f
Show file tree
Hide file tree
Showing 18 changed files with 154 additions and 173 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ insert_final_newline = true
indent_style = space
indent_size = 4

[*.yml]
indent_size = 2

[CMakePresets.json]
insert_final_newline = false
indent_style = space
Expand Down
90 changes: 48 additions & 42 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build
name: Build

on:
workflow_call:
Expand All @@ -23,47 +23,53 @@ on:
jobs:
build:
name: Build

runs-on: ${{ inputs.os }}-latest

steps:
- uses: actions/checkout@v4

- uses: ammaraskar/msvc-problem-matcher@master
- uses: ammaraskar/gcc-problem-matcher@master

- name: Set preset name
id: preset
shell: bash
run: |
echo "name=${{ inputs.os }}-${{ inputs.arch }}-${{ inputs.conf }}" | sed s/ubuntu/linux/ >> $GITHUB_OUTPUT
- name: Set up Windows compiler
uses: ilammy/msvc-dev-cmd@v1
with:
arch: ${{ inputs.arch }}

- name: Configure
run: cmake --preset ${{ steps.preset.outputs.name }}

- name: Build
run: cmake --build --preset ${{ steps.preset.outputs.name }}

- name: Test
run: ctest --timeout 5 --preset ${{ steps.preset.outputs.name }}

- name: Install
if: ${{ inputs.artifacts }}
run: cmake --install out/build/${{ steps.preset.outputs.name }} --prefix out/install/${{ steps.preset.outputs.name }}

- name: Tar
if: ${{ inputs.artifacts }}
working-directory: out/install/${{ steps.preset.outputs.name }}
run: tar -czf ${{ github.workspace }}/${{ steps.preset.outputs.name }}.tar.gz .

- name: Upload artifact
if: ${{ inputs.artifacts }}
uses: actions/upload-artifact@v4
with:
name: ${{ steps.preset.outputs.name }}
path: ${{ steps.preset.outputs.name }}.tar.gz
- uses: actions/checkout@v4

- uses: ammaraskar/msvc-problem-matcher@master # Report MSVC compiler errors

- uses: ammaraskar/gcc-problem-matcher@master # Report GCC compiler errors

- uses: lukka/get-cmake@latest # Set up latest cmake/Ninja

- uses: lukka/run-vcpkg@v11 # Set up vcpkg and install dependencies
with:
runVcpkgInstall: true

- name: Set preset name
id: preset
shell: bash
run: echo "name=${{ inputs.os }}-${{ inputs.arch }}-${{ inputs.conf }}" | sed s/ubuntu/linux/ >> $GITHUB_OUTPUT

- name: Set up Windows compiler
uses: ilammy/msvc-dev-cmd@v1
with:
arch: ${{ inputs.arch }}

- name: Configure
run: cmake --preset ${{ steps.preset.outputs.name }}

- name: Build
run: cmake --build --preset ${{ steps.preset.outputs.name }}

- name: Test
run: ctest --timeout 5 --preset ${{ steps.preset.outputs.name }}

- name: Install
if: ${{ inputs.artifacts }}
run: cmake --install out/build/${{ steps.preset.outputs.name }} --prefix out/install/${{ steps.preset.outputs.name }}

- name: Tar
if: ${{ inputs.artifacts }}
working-directory: out/install/${{ steps.preset.outputs.name }}
run: tar -czf ${{ github.workspace }}/${{ steps.preset.outputs.name }}.tar.gz .

- name: Upload artifact
if: ${{ inputs.artifacts }}
uses: actions/upload-artifact@v4
with:
name: ${{ steps.preset.outputs.name }}
path: ${{ steps.preset.outputs.name }}.tar.gz
28 changes: 16 additions & 12 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
name: Integration
name: Integration

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]

jobs:
build:
name: Integration test

runs-on: ubuntu-latest

services:
pushgateway:
image: prom/pushgateway:latest
ports:
ports:
- "9091:9091"
statsd:
image: prom/statsd-exporter:latest
ports:
ports:
- "9125:9125/udp"
- "9125:9125/tcp"

steps:
- uses: actions/checkout@v4
- run: cmake --preset linux-x64-debug
- run: cmake --build --preset linux-x64-debug --target integration-test
- run: out/build/linux-x64-debug/integration-test statsd+tcp://localhost:9125
- run: out/build/linux-x64-debug/integration-test statsd+udp://localhost:9125
- run: out/build/linux-x64-debug/integration-test pushgateway+http://localhost:9091/metrics/job/test_job/instance/test_instance
- uses: actions/checkout@v4
- uses: lukka/get-cmake@latest
- uses: lukka/run-vcpkg@v11
with:
runVcpkgInstall: true
- run: cmake --preset linux-x64-debug
- run: cmake --build --preset linux-x64-debug --target integration-test
- run: out/build/linux-x64-debug/integration-test statsd+tcp://localhost:9125
- run: out/build/linux-x64-debug/integration-test statsd+udp://localhost:9125
- run: out/build/linux-x64-debug/integration-test pushgateway+http://localhost:9091/metrics/job/test_job/instance/test_instance
12 changes: 6 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: "Mainline Checks"

on:
push:
branches: [ "main" ]
branches: ["main"]

jobs:
build:
Expand All @@ -14,11 +14,11 @@ jobs:
conf: [release, debug, asan]
arch: [x64]
exclude:
- os: ubuntu
arch: x86
- os: macos
arch: x86
uses: ./.github/workflows/build.yml
- os: ubuntu
arch: x86
- os: macos
arch: x86
uses: ./.github/workflows/build.yml
with:
conf: ${{ matrix.conf }}
os: ${{ matrix.os }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: "PR Checks"

on:
pull_request:
branches: [ "main" ]
branches: ["main"]

jobs:
build:
Expand All @@ -13,7 +13,7 @@ jobs:
os: [windows, ubuntu]
conf: [debug, asan]
arch: [x64]
uses: ./.github/workflows/build.yml
uses: ./.github/workflows/build.yml
with:
conf: ${{ matrix.conf }}
os: ${{ matrix.os }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@
build/
out/
.vs/
vcpkg_installed
15 changes: 14 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,23 @@ if(METRICS_BUILD_SANITIZER)
enable_sanitizer(${METRICS_BUILD_SANITIZER})
endif()

# Boost
set(BOOST_USE_STATIC_LIBS ON)
set(BOOST_ENABLE_CMAKE ON)
if (METRICS_BUILD_SANITIZER)
set(BOOST_USE_ASAN ON)
endif()

find_package(Boost COMPONENTS asio accumulators beast json url REQUIRED)
find_package(OpenSSL CONFIG REQUIRED)
find_package(CURL CONFIG REQUIRED)

message(STATUS "Boost_INCLUDE_DIRS: [${Boost_INCLUDE_DIRS}]")
message(STATUS "Boost_LIBRARIES: [${Boost_LIBRARIES}]")

set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR})
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR})

add_subdirectory(ext)
add_subdirectory(src)

if (METRICS_BUILD_TESTS OR METRICS_BUILD_BENCHMARKS)
Expand Down
5 changes: 4 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": {
"METRICS_BUILD_TESTS": true,
"METRICS_BUILD_BENCHMARKS": true
"METRICS_BUILD_BENCHMARKS": true,
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
}
},
{
Expand Down Expand Up @@ -123,6 +124,8 @@
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
},
"cacheVariables": {
}
},
{
Expand Down
11 changes: 1 addition & 10 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
include(FetchContent)

message(STATUS "Cloning Google Benchmark")
set(BENCHMARK_ENABLE_TESTING NO)
FetchContent_Declare(
googlebenchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG v1.8.4
)
FetchContent_MakeAvailable(googlebenchmark)

find_package(benchmark CONFIG REQUIRED)
add_executable(metrics_benchmark benchmarks.cpp)
target_link_libraries(metrics_benchmark PUBLIC METRICS::lib benchmark::benchmark)
24 changes: 19 additions & 5 deletions benchmarks/benchmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

using namespace Metrics;

static void BM_AtomicIncrement(benchmark::State& state) {
static void BM_Reference_AtomicIncrement(benchmark::State& state) {
std::atomic<int> counter;
for (auto _ : state)
counter++;
}
BENCHMARK(BM_AtomicIncrement);
BENCHMARK(BM_Reference_AtomicIncrement);

static void BM_CounterIncrement(benchmark::State& state) {
auto counter = Counter();
Expand All @@ -26,12 +26,26 @@ static void BM_GaugeSet(benchmark::State& state) {
}
BENCHMARK(BM_GaugeSet);

static void BM_HistogramObserve(benchmark::State& state) {
static void BM_Histogram2Observe(benchmark::State& state) {
auto histogram = makeHistogram({ 1,2 });
for (auto _ : state)
histogram->observe(20);
}
BENCHMARK(BM_Histogram2Observe);

static void BM_Histogram5Observe(benchmark::State& state) {
auto histogram = makeHistogram({ 1,2,3,4,5 });
for (auto _ : state)
histogram->observe(5);
histogram->observe(20);
}
BENCHMARK(BM_Histogram5Observe);

static void BM_Histogram10Observe(benchmark::State& state) {
auto histogram = makeHistogram({ 1,2,3,4,5,6,7,8,9,10 });
for (auto _ : state)
histogram->observe(20);
}
BENCHMARK(BM_HistogramObserve);
BENCHMARK(BM_Histogram10Observe);

static void BM_SummaryObserve(benchmark::State& state) {
auto summary = makeSummary({ 0.9, 0.99, 0.999 }, 0.01);
Expand Down
28 changes: 0 additions & 28 deletions ext/CMakeLists.txt

This file was deleted.

2 changes: 1 addition & 1 deletion include/metrics/prometheus.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace Metrics {
namespace Prometheus {
METRICS_EXPORT std::string serialize(std::shared_ptr<IRegistry> registry);
METRICS_EXPORT std::shared_ptr<IOnDemandSink> createPushGatewaySink(const std::string& host, const std::string& port, std::string job, std::string instance);
METRICS_EXPORT std::shared_ptr<IOnDemandSink> createPushGatewaySink(const std::string& url);
METRICS_EXPORT std::shared_ptr<IRegistrySink> createPrometheusHttpServerSink(std::shared_ptr<IRegistry> registry, const std::string& address, const std::string& port);
}
}
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ else()
endif()

file(GLOB_RECURSE METRICS_SOURCE_FILES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
file(GLOB_RECURSE METRICS_HEADER_FILES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../include/*.h")
file(GLOB_RECURSE METRICS_HEADER_FILES CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/include/*.h")

add_library(metrics SHARED ${METRICS_SOURCE_FILES})
target_include_directories(metrics PUBLIC "${PROJECT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}")
target_link_libraries(metrics PRIVATE Boost::asio Boost::accumulators Boost::beast Boost::json Boost::url)
target_link_libraries(metrics PRIVATE ${Boost_LIBRARIES} CURL::libcurl OpenSSL::SSL)
generate_export_header(metrics)
add_library(METRICS::lib ALIAS metrics)

Expand Down
6 changes: 4 additions & 2 deletions src/common/sink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ namespace Metrics {
return Statsd::createUdpSink(url.host(), url.port());
if (scheme == "statsd+tcp")
return Statsd::createTcpSink(url.host(), url.port());
if (scheme == "pushgateway+http" || scheme == "pushgateway+https")
return Prometheus::createPushGatewaySink(url.host(), url.port(), "job", "instance");
if (scheme.find("pushgateway+") == 0) {
std::string url_truncated = url_string.substr(strlen("pushgateway+"));
return Prometheus::createPushGatewaySink(url_truncated);
}
}
catch (std::exception&)
{
Expand Down
Loading

0 comments on commit 564799f

Please sign in to comment.