Skip to content

Commit c9aa855

Browse files
committed
lib: cmetrics: upgrade to v2.2.1
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
1 parent b4cb968 commit c9aa855

32 files changed

Lines changed: 2327 additions & 323 deletions

lib/cmetrics/.github/workflows/build.yaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,12 @@ jobs:
5959
provenance: false
6060

6161
build-debian:
62-
name: Debian Buster build to confirm no issues once used downstream
62+
name: Debian Bookworm build to confirm no issues once used downstream
6363
runs-on: ubuntu-latest
64-
container: debian:buster
64+
container: debian:bookworm
6565
steps:
6666
- name: Set up base image dependencies
6767
run: |
68-
# Update sources to use archive.debian.org (Buster reached end-of-life)
69-
sed -i 's/deb.debian.org/archive.debian.org/g' /etc/apt/sources.list
70-
sed -i 's/security.debian.org/archive.debian.org/g' /etc/apt/sources.list
7168
apt-get update
7269
apt-get install -y build-essential wget make gcc g++ git libcurl4-openssl-dev
7370

lib/cmetrics/AGENTS.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## Testing
2+
3+
- When making code changes, run the related unit test when one is available.
4+
5+
## Performance
6+
7+
- Build benchmarks with `CMT_BENCHMARKS=ON` and an optimized Release build.
8+
- For performance changes, capture at least five before and five after runs on
9+
the same machine with identical compiler flags and workload parameters.
10+
- Use `benchmarks/run-perf.sh` for the standard workloads and Linux `perf stat`
11+
hardware counters. Keep only changes with repeatable improvements and no
12+
relevant benchmark regressions.

lib/cmetrics/CMakeLists.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,14 @@ if(NOT MSVC)
6363
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
6464
endif()
6565

66-
# Define __CMT_FILENAME__ consistently across Operating Systems
67-
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows")
68-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__CMT_FILENAME__='\"$$(subst ${CMAKE_SOURCE_DIR}/,,$$(abspath $$<))\"'")
69-
else()
70-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__CMT_FILENAME__=__FILE__")
71-
endif()
66+
# Define __CMT_FILENAME__
67+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__CMT_FILENAME__=__FILE__")
7268

7369
# Configuration options
7470
option(CMT_DEV "Enable development mode" No)
7571
option(CMT_DEBUG "Enable debug mode" No)
7672
option(CMT_TESTS "Enable unit testing" No)
73+
option(CMT_BENCHMARKS "Build performance benchmarks" No)
7774
option(CMT_INSTALL_TARGETS "Enable subdirectory library installations" Yes)
7875
option(CMT_PROMETHEUS_TEXT_DECODER "Enable prometheus text format decoder (requires Flex/Bison)" Yes)
7976

@@ -302,6 +299,10 @@ endif()
302299
add_subdirectory(include)
303300
add_subdirectory(src)
304301

302+
if(CMT_BENCHMARKS)
303+
add_subdirectory(benchmarks)
304+
endif()
305+
305306
# Tests
306307
if(CMT_TESTS)
307308
enable_testing()

lib/cmetrics/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ CMetrics is heavily inspired by the Go Prometheus Client API design:
141141
142142
- https://pkg.go.dev/github.com/prometheus/client_golang/prometheus#section-documentation
143143
144+
Additional design notes:
145+
146+
- [Long metric label handling](docs/label-value-handling.md)
147+
144148
## License
145149
146150
This program is under the terms of the
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
add_executable(cmt-benchmark benchmark.c)
2+
target_link_libraries(cmt-benchmark cmetrics-static cfl-static fluent-otel-proto)
3+
4+
if(NOT CMT_SYSTEM_WINDOWS)
5+
target_link_libraries(cmt-benchmark pthread)
6+
endif()

lib/cmetrics/benchmarks/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# CMetrics benchmarks
2+
3+
Benchmarks are opt-in and are intended for before/after comparisons on the
4+
same machine. Build an optimized binary:
5+
6+
```sh
7+
cmake -S . -B build-perf \
8+
-DCMT_BENCHMARKS=ON \
9+
-DCMT_INSTALL_TARGETS=OFF \
10+
-DCMAKE_BUILD_TYPE=Release \
11+
-DCMAKE_C_FLAGS_RELEASE='-O3 -DNDEBUG'
12+
cmake --build build-perf -j --target cmt-benchmark
13+
```
14+
15+
Run the standard repeated workloads and Linux hardware counters:
16+
17+
```sh
18+
REPETITIONS=5 benchmarks/run-perf.sh \
19+
./build-perf/benchmarks/cmt-benchmark
20+
```
21+
22+
The executable also accepts individual workloads:
23+
24+
```text
25+
cmt-benchmark lookup|update|prometheus|opentelemetry|opentelemetry-mixed CARDINALITY OPERATIONS
26+
```
27+
28+
The `opentelemetry` workload repeatedly encodes a labeled counter with the
29+
requested number of series. The `opentelemetry-mixed` workload creates that
30+
many counter, gauge, and histogram series to exercise scalar and aggregate
31+
protobuf data points in the same request.
32+
33+
Compare medians from at least five alternating before/after runs. Keep CPU
34+
frequency policy, compiler, flags, machine load, and input parameters fixed.
35+
Use the reported in-process `elapsed_ns` for the operation itself and `perf
36+
stat` for whole-process hardware counters. Whole-process counters include
37+
series construction and teardown by design, exposing setup complexity as well
38+
as steady-state behavior.

0 commit comments

Comments
 (0)