Skip to content
Merged
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
8 changes: 4 additions & 4 deletions lib/cmetrics/.github/workflows/packages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
echo ${{ matrix.format }} | awk '{print toupper($0)}' | xargs -I{} cpack -G {}

- name: Store the master package artifacts
uses: actions/upload-artifact@v6
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.format }}-arm64
path: |
Expand All @@ -64,7 +64,7 @@ jobs:
echo ${{ matrix.format }} | awk '{print toupper($0)}' | xargs -I{} cpack -G {}

- name: Store the master package artifacts
uses: actions/upload-artifact@v6
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.format }}-amd64
path: |
Expand All @@ -91,7 +91,7 @@ jobs:
echo ${{ matrix.config.format }} | xargs -I{} cpack -G {}

- name: Store the master package artifacts
uses: actions/upload-artifact@v6
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.config.format }}-${{matrix.config.arch}}
path: |
Expand All @@ -109,7 +109,7 @@ jobs:
contents: write
steps:
- name: Download all artefacts
uses: actions/download-artifact@v7
uses: actions/download-artifact@v8
with:
path: artifacts/

Expand Down
2 changes: 1 addition & 1 deletion lib/cmetrics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# CMetrics Version
set(CMT_VERSION_MAJOR 2)
set(CMT_VERSION_MINOR 0)
set(CMT_VERSION_PATCH 4)
set(CMT_VERSION_PATCH 5)
set(CMT_VERSION_STR "${CMT_VERSION_MAJOR}.${CMT_VERSION_MINOR}.${CMT_VERSION_PATCH}")

# Include helpers
Expand Down
6 changes: 6 additions & 0 deletions lib/cmetrics/include/cmetrics/cmt_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@

#include <time.h>
#ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN
#else
#include <windows.h>
#endif
#endif

static inline struct tm *cmt_platform_gmtime_r(const time_t *timep, struct tm *result)
Expand Down
6 changes: 6 additions & 0 deletions lib/cmetrics/src/cmt_atomic_msvc.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@
*/

#include <cmetrics/cmt_atomic.h>
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN
#else
#include <windows.h>
#endif

/* This allows cmt_atomic_initialize to be automatically called
* as soon as the program starts if enabled.
Expand Down
5 changes: 0 additions & 5 deletions lib/cmetrics/src/cmt_cat.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,9 +689,6 @@ int cmt_cat_counter(struct cmt *cmt, struct cmt_counter *counter,
return -1;
}

c->aggregation_type = counter->aggregation_type;
c->allow_reset = counter->allow_reset;

if (filtered_map != NULL) {
ret = cmt_cat_copy_map(&c->opts, c->map, filtered_map);
if (ret == -1) {
Expand Down Expand Up @@ -840,8 +837,6 @@ int cmt_cat_histogram(struct cmt *cmt, struct cmt_histogram *histogram,
return -1;
}

hist->aggregation_type = histogram->aggregation_type;

if (filtered_map != NULL) {
ret = cmt_cat_copy_map(&hist->opts, hist->map, filtered_map);
if (ret == -1) {
Expand Down
23 changes: 22 additions & 1 deletion lib/cmetrics/src/cmt_decode_opentelemetry.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ static struct cfl_variant *clone_variant(Opentelemetry__Proto__Common__V1__AnyVa
if (source->value_case == OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_STRING_VALUE) {
result_instance = cfl_variant_create_from_string(source->string_value);
}
else if (source->value_case == OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_STRING_VALUE_STRINDEX) {
result_instance = cfl_variant_create_from_string("");
}
Comment on lines +74 to +76
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Empty-string fallback will merge distinct label and metadata values.

This decoder has no string-table context, so coercing VALUE_STRING_VALUE_STRINDEX to "" silently changes the original value. For labels that can collapse distinct series into the same identity; for metadata it hides the actual payload. Please fail with CMT_DECODE_OPENTELEMETRY_INVALID_ARGUMENT_ERROR until real resolution is available.

Also applies to: 645-648

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/cmetrics/src/cmt_decode_opentelemetry.c` around lines 74 - 76, The
decoder currently coerces
OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_STRING_VALUE_STRINDEX to an
empty string using cfl_variant_create_from_string(""), which can collapse
distinct labels/metadata; instead detect this value_case and return
CMT_DECODE_OPENTELEMETRY_INVALID_ARGUMENT_ERROR so the caller knows string-table
resolution is required. Update the handling code for the symbol
source->value_case ==
OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_STRING_VALUE_STRINDEX (and
the identical logic at the other location handling lines 645-648) to abort with
CMT_DECODE_OPENTELEMETRY_INVALID_ARGUMENT_ERROR rather than creating an
empty-string variant.

else if (source->value_case == OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_BOOL_VALUE) {
result_instance = cfl_variant_create_from_bool(source->bool_value);
}
Expand Down Expand Up @@ -154,6 +157,11 @@ static int clone_array_entry(struct cfl_array *target,
struct cfl_variant *new_child_instance;
int result;

if (source != NULL &&
source->value_case == OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_STRING_VALUE_STRINDEX) {
return CMT_DECODE_OPENTELEMETRY_SUCCESS;
}
Comment on lines +160 to +163
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Don't drop string_value_strindex entries from arrays or kvlists.

These branches return success without inserting anything, so arrays lose elements and kvlists lose keys whenever a VALUE_STRING_VALUE_STRINDEX value appears. Either append the placeholder variant or reject the payload, but silently succeeding corrupts the decoded structure.

Also applies to: 207-210

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/cmetrics/src/cmt_decode_opentelemetry.c` around lines 160 - 163, The code
branch that checks for
OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_STRING_VALUE_STRINDEX
currently returns CMT_DECODE_OPENTELEMETRY_SUCCESS without inserting a value,
which drops elements/keys; modify the handler (the same places as the checks
around the
OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_STRING_VALUE_STRINDEX
condition) to preserve structure by inserting a placeholder AnyValue variant
(e.g., a sentinel/empty-string or explicit "strindex" placeholder) into arrays
and kvlists instead of returning success, or alternatively return a decode
error; ensure you update both occurrences (the one shown and the similar block
at lines ~207-210) and keep the return value consistent with other decode
failures (do not silently succeed).


new_child_instance = clone_variant(source);
if (new_child_instance == NULL) {
return CMT_DECODE_OPENTELEMETRY_ALLOCATION_ERROR;
Expand Down Expand Up @@ -183,7 +191,7 @@ static int clone_kvlist(struct cfl_kvlist *target,
result = clone_kvlist_entry(target, source->values[index]);
}

return 0;
return result;
}

static int clone_kvlist_entry(struct cfl_kvlist *target,
Expand All @@ -192,6 +200,15 @@ static int clone_kvlist_entry(struct cfl_kvlist *target,
struct cfl_variant *new_child_instance;
int result;

if (source == NULL) {
return CMT_DECODE_OPENTELEMETRY_SUCCESS;
}

if (source->value != NULL &&
source->value->value_case == OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_STRING_VALUE_STRINDEX) {
return CMT_DECODE_OPENTELEMETRY_SUCCESS;
}

new_child_instance = clone_variant(source->value);

if (new_child_instance == NULL) {
Expand Down Expand Up @@ -625,6 +642,10 @@ static int decode_data_point_labels(struct cmt *cmt,
if (attribute->value->value_case == OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_STRING_VALUE) {
result = append_new_metric_label_value(metric, attribute->value->string_value, 0);
}
else if (attribute->value->value_case ==
OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_STRING_VALUE_STRINDEX) {
result = append_new_metric_label_value(metric, "", 0);
}
else if (attribute->value->value_case == OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_BYTES_VALUE) {
result = append_new_metric_label_value(metric,
(char *) attribute->value->bytes_value.data,
Expand Down
95 changes: 0 additions & 95 deletions lib/cmetrics/tests/cat.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <cmetrics/cmt_gauge.h>
#include <cmetrics/cmt_untyped.h>
#include <cmetrics/cmt_histogram.h>
#include <cmetrics/cmt_exp_histogram.h>
#include <cmetrics/cmt_summary.h>
#include <cmetrics/cmt_encode_text.h>
#include <cmetrics/cmt_encode_prometheus.h>
Expand Down Expand Up @@ -612,106 +611,12 @@ void test_histogram_populated_to_empty()
cmt_destroy(cmt2);
}

void test_cat_preserves_aggregation_metadata()
{
int ret;
uint64_t ts;
uint64_t positive_counts[2] = {3, 4};
struct cmt *src;
struct cmt *dst;
struct cmt_counter *src_counter;
struct cmt_counter *dst_counter;
struct cmt_histogram *src_histogram;
struct cmt_histogram *dst_histogram;
struct cmt_exp_histogram *src_exp_histogram;
struct cmt_exp_histogram *dst_exp_histogram;
struct cmt_histogram_buckets *buckets;

src = cmt_create();
TEST_CHECK(src != NULL);

dst = cmt_create();
TEST_CHECK(dst != NULL);

buckets = cmt_histogram_buckets_create(3, 1.0, 5.0, 10.0);
TEST_CHECK(buckets != NULL);

src_counter = cmt_counter_create(src, "otlp", "cat", "counter", "counter",
0, NULL);
TEST_CHECK(src_counter != NULL);

src_histogram = cmt_histogram_create(src, "otlp", "cat", "histogram", "histogram",
buckets, 0, NULL);
TEST_CHECK(src_histogram != NULL);

src_exp_histogram = cmt_exp_histogram_create(src, "otlp", "cat", "exp_histogram",
"exp histogram", 0, NULL);
TEST_CHECK(src_exp_histogram != NULL);

ts = cfl_time_now();
cmt_counter_allow_reset(src_counter);
src_counter->aggregation_type = CMT_AGGREGATION_TYPE_DELTA;
cmt_counter_add(src_counter, ts, 4.0, 0, NULL);

src_histogram->aggregation_type = CMT_AGGREGATION_TYPE_DELTA;
cmt_histogram_observe(src_histogram, ts, 2.5, 0, NULL);

src_exp_histogram->aggregation_type = CMT_AGGREGATION_TYPE_DELTA;
ret = cmt_exp_histogram_set_default(src_exp_histogram,
ts,
2,
1,
0.0,
0,
2,
positive_counts,
0,
0,
NULL,
CMT_TRUE,
7.5,
7,
0,
NULL);
TEST_CHECK(ret == 0);

ret = cmt_cat(dst, src);
TEST_CHECK(ret == 0);

TEST_CHECK(cfl_list_size(&dst->counters) == 1);
dst_counter = cfl_list_entry_first(&dst->counters, struct cmt_counter, _head);
TEST_CHECK(dst_counter != NULL);
if (dst_counter != NULL) {
TEST_CHECK(dst_counter->allow_reset == CMT_TRUE);
TEST_CHECK(dst_counter->aggregation_type == CMT_AGGREGATION_TYPE_DELTA);
}

TEST_CHECK(cfl_list_size(&dst->histograms) == 1);
dst_histogram = cfl_list_entry_first(&dst->histograms, struct cmt_histogram, _head);
TEST_CHECK(dst_histogram != NULL);
if (dst_histogram != NULL) {
TEST_CHECK(dst_histogram->aggregation_type == CMT_AGGREGATION_TYPE_DELTA);
}

TEST_CHECK(cfl_list_size(&dst->exp_histograms) == 1);
dst_exp_histogram = cfl_list_entry_first(&dst->exp_histograms,
struct cmt_exp_histogram, _head);
TEST_CHECK(dst_exp_histogram != NULL);
if (dst_exp_histogram != NULL) {
TEST_CHECK(dst_exp_histogram->aggregation_type == CMT_AGGREGATION_TYPE_DELTA);
}

cmt_destroy(src);
cmt_destroy(dst);
}

TEST_LIST = {
{"cat", test_cat},
{"duplicate_metrics", test_duplicate_metrics},
{"histogram_empty_concatenation", test_histogram_empty_concatenation},
{"histogram_mismatched_buckets", test_histogram_mismatched_buckets},
{"histogram_empty_to_populated", test_histogram_empty_to_populated},
{"histogram_populated_to_empty", test_histogram_populated_to_empty},
{"cat_preserves_aggregation_metadata", test_cat_preserves_aggregation_metadata},
{ 0 }
};
Binary file modified lib/cmetrics/tests/prometheus_remote_write_payload.bin
Binary file not shown.
21 changes: 14 additions & 7 deletions lib/cprofiles/.github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ jobs:
sed -i -e "s/^mirrorlist=http:\/\/mirrorlist.centos.org/#mirrorlist=http:\/\/mirrorlist.centos.org/g" /etc/yum.repos.d/CentOS-Base.repo
sed -i -e "s/^#baseurl=http:\/\/mirror.centos.org/baseurl=http:\/\/vault.centos.org/g" /etc/yum.repos.d/CentOS-Base.repo
yum -y update && \
yum install -y ca-certificates cmake curl-devel gcc gcc-c++ git make wget && \
yum install -y epel-release
yum install -y cmake3
yum install -y ca-certificates curl-devel gcc gcc-c++ git make wget && \
yum install -y epel-release && \
yum install -y python3 python3-pip
python3 -m pip install --user --upgrade "cmake>=3.20,<4"
echo "$(python3 -m site --user-base)/bin" >> "$GITHUB_PATH"
shell: bash

- name: Clone repo without submodules (1.8.3 version of Git)
Expand All @@ -69,7 +71,7 @@ jobs:

- name: Run compilation
run: |
cmake3 -DCPROF_DEV=on ../
cmake -DCPROF_DEV=on ../
make
shell: bash
working-directory: cprofiles/build
Expand All @@ -82,7 +84,9 @@ jobs:
- name: Set up base image dependencies
run: |
apt-get update
apt-get install -y build-essential cmake make git
apt-get install -y build-essential git make python3 python3-pip
python3 -m pip install --user --upgrade "cmake>=3.20,<4"
echo "$(python3 -m site --user-base)/bin" >> "$GITHUB_PATH"
shell: bash

- uses: actions/checkout@v6
Expand Down Expand Up @@ -121,9 +125,12 @@ jobs:
apt-get update && \
apt-get install -y --no-install-recommends \
build-essential \
cmake \
file \
make
make \
python3 \
python3-pip
python3 -m pip install --user --upgrade "cmake>=3.20,<4"
export PATH="$(python3 -m site --user-base)/bin:$PATH"
export CC=${{ env.compiler }}
cd build
cmake -DCPROF_TESTS=On ../
Expand Down
8 changes: 4 additions & 4 deletions lib/cprofiles/.github/workflows/packages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
echo ${{ matrix.format }} | awk '{print toupper($0)}' | xargs -I{} cpack -G {}

- name: Store the master package artifacts
uses: actions/upload-artifact@v6
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.format }}-arm64
path: |
Expand All @@ -63,7 +63,7 @@ jobs:
echo ${{ matrix.format }} | awk '{print toupper($0)}' | xargs -I{} cpack -G {}

- name: Store the master package artifacts
uses: actions/upload-artifact@v6
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.format }}-amd64
path: |
Expand All @@ -90,7 +90,7 @@ jobs:
echo ${{ matrix.config.format }} | xargs -I{} cpack -G {}

- name: Store the master package artifacts
uses: actions/upload-artifact@v6
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.config.format }}-${{matrix.config.arch}}
path: |
Expand All @@ -107,7 +107,7 @@ jobs:
contents: write
steps:
- name: Download all artefacts
uses: actions/download-artifact@v7
uses: actions/download-artifact@v8
with:
path: artifacts/

Expand Down
Loading
Loading