Skip to content

Commit

Permalink
lib: cmetrics: upgrade to v0.9.5
Browse files Browse the repository at this point in the history
Signed-off-by: Eduardo Silva <[email protected]>
  • Loading branch information
edsiper committed Sep 2, 2024
1 parent d466d6f commit 72a8188
Show file tree
Hide file tree
Showing 10 changed files with 227 additions and 33 deletions.
57 changes: 57 additions & 0 deletions lib/cmetrics/.github/workflows/packages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,68 @@ jobs:
path: |
./*.${{matrix.format}}
build-macos-packages-amd64:
name: build macOS intel packages
strategy:
fail-fast: true
matrix:
config:
- format: productbuild
arch: intel
ext: pkg
runs-on: macos-12
steps:
- uses: actions/checkout@v3
with:
submodules: true

- name: Build the ${{matrix.config.format}} packages
run: |
cmake . -DCPACK_GENERATOR=${{ matrix.config.format }}
echo ${{ matrix.config.format }} | xargs -I{} cpack -G {}
- name: Store the master package artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.config.format }}-${{matrix.config.arch}}
path: |
./*-${{matrix.config.arch}}.${{matrix.config.ext}}
build-macos-packages-arm64:
name: build macOS Apple Silicon packages
strategy:
fail-fast: true
matrix:
config:
- format: productbuild
arch: apple
ext: pkg
runs-on: macos-14
steps:
- uses: actions/checkout@v3
with:
submodules: true

- name: Build the ${{matrix.config.format}} packages
run: |
cmake . -DCPACK_GENERATOR=${{ matrix.config.format }}
echo ${{ matrix.config.format }} | xargs -I{} cpack -G {}
- name: Store the master package artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.config.format }}-${{matrix.config.arch}}
path: |
./*-${{matrix.config.arch}}.${{matrix.config.ext}}
release:
name: Create release and upload packages
needs:
- build-distro-packages-amd64
- build-distro-packages-arm64
- build-macos-packages-amd64
- build-macos-packages-arm64

runs-on: ubuntu-latest
permissions:
contents: write
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 0)
set(CMT_VERSION_MINOR 9)
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
13 changes: 10 additions & 3 deletions lib/cmetrics/src/cmt_decode_prometheus.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,16 @@ static void reset_context(struct cmt_decode_prometheus_context *context,
}

if (context->metric.ns) {
if (strcmp(context->metric.ns, "")) {
if ((void *) context->metric.ns != (void *) "") {
/* when namespace is empty, "name" contains a pointer to the
* allocated string */
* allocated string.
*
* Note : When the metric name doesn't include the namespace
* ns is set to a constant empty string and we need to
* differentiate that case from the case where an empty
* namespace is provided.
*/

free(context->metric.ns);
}
else {
Expand Down Expand Up @@ -516,7 +523,7 @@ static int add_metric_histogram(struct cmt_decode_prometheus_context *context)
"failed to parse bucket");
goto end;
}
if (parse_uint64(sample->value1,
if (parse_uint64(sample->value1,
bucket_defaults + bucket_index)) {
/* Count is supposed to be integer, but apparently
* some tools can generate count in a floating format.
Expand Down
18 changes: 16 additions & 2 deletions lib/cmetrics/src/cmt_decode_prometheus_remote_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ static int decode_histogram_points(struct cmt *cmt,
destroy_label_list(&metric->labels);

free(metric);

return CMT_DECODE_PROMETHEUS_REMOTE_WRITE_DECODE_ERROR;
}
else {
cfl_list_add(&metric->_head, &map->metrics);
Expand All @@ -438,7 +440,13 @@ static int decode_histogram_points(struct cmt *cmt,
}
}
else {
free(metric);
if (static_metric_detected == CMT_FALSE) {
destroy_label_list(&metric->labels);

cfl_list_del(&metric->_head);

free(metric);
}

return CMT_DECODE_PROMETHEUS_REMOTE_WRITE_DECODE_ERROR;
}
Expand All @@ -452,7 +460,13 @@ static int decode_histogram_points(struct cmt *cmt,
metric->hist_count = hist->count_float;
}
else {
free(metric);
if (static_metric_detected == CMT_FALSE) {
destroy_label_list(&metric->labels);

cfl_list_del(&metric->_head);

free(metric);
}

return CMT_DECODE_PROMETHEUS_REMOTE_WRITE_DECODE_ERROR;
}
Expand Down
43 changes: 33 additions & 10 deletions lib/cmetrics/src/cmt_decode_statsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static int decode_labels(struct cmt *cmt,
size_t label_index;
int label_found;
char *label_kv, *colon;
cfl_sds_t label_k, label_v, tmp;
cfl_sds_t label_k = NULL, label_v = NULL, tmp = NULL;
int result;
struct cfl_list *head = NULL;
struct cfl_list *kvs = NULL;
Expand Down Expand Up @@ -157,7 +157,14 @@ static int decode_labels(struct cmt *cmt,
}
label_k = cfl_sds_create_len(label_kv, colon - label_kv);
if (label_k == NULL) {
for (label_index = 0 ; label_index < 128 ; label_index++) {
if (value_index_list[label_index] != NULL) {
cfl_sds_destroy(value_index_list[label_index]);
}
}

free(value_index_list);

if (kvs != NULL) {
cfl_utils_split_free(kvs);
}
Expand All @@ -167,7 +174,15 @@ static int decode_labels(struct cmt *cmt,
label_v = cfl_sds_create_len(colon + 1, strlen(label_kv) - strlen(label_k) - 1);
if (label_v == NULL) {
cfl_sds_destroy(label_k);

for (label_index = 0 ; label_index < 128 ; label_index++) {
if (value_index_list[label_index] != NULL) {
cfl_sds_destroy(value_index_list[label_index]);
}
}

free(value_index_list);

if (kvs != NULL) {
cfl_utils_split_free(kvs);
}
Expand All @@ -190,7 +205,15 @@ static int decode_labels(struct cmt *cmt,
if (label_index > 127) {
cfl_sds_destroy(label_k);
cfl_sds_destroy(label_v);

for (label_index = 0 ; label_index < 128 ; label_index++) {
if (value_index_list[label_index] != NULL) {
cfl_sds_destroy(value_index_list[label_index]);
}
}

free(value_index_list);

if (kvs != NULL) {
cfl_utils_split_free(kvs);
}
Expand All @@ -203,10 +226,12 @@ static int decode_labels(struct cmt *cmt,
}

if (result == CMT_DECODE_STATSD_SUCCESS) {
value_index_list[label_index] = (void *) label_v;
value_index_list[label_index] = (void *) cfl_sds_create_len(label_v,
cfl_sds_len(label_v));
}

cfl_sds_destroy(label_k);
cfl_sds_destroy(label_v);
}
}

Expand All @@ -225,20 +250,18 @@ static int decode_labels(struct cmt *cmt,
}
}

for (map_label_index = 0 ;
result == CMT_DECODE_STATSD_SUCCESS &&
map_label_index < map_label_count ;
map_label_index++) {
label_v = (cfl_sds_t) value_index_list[map_label_index];
cfl_sds_destroy(label_v);
for (label_index = 0 ; label_index < 128 ; label_index++) {
if (value_index_list[label_index] != NULL) {
cfl_sds_destroy(value_index_list[label_index]);
}
}

free(value_index_list);

if (kvs != NULL) {
cfl_utils_split_free(kvs);
}

free(value_index_list);

return result;
}

Expand Down
34 changes: 23 additions & 11 deletions lib/cmetrics/src/cmt_encode_influx.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,9 @@ static void format_metric(struct cmt *cmt, cfl_sds_t *buf, struct cmt_map *map,
{
int i;
int n;
int count = 0;
int static_count = 0;
int static_labels = 0;
int has_namespace = CMT_FALSE;
struct cmt_map_label *label_k;
struct cmt_map_label *label_v;
struct cfl_list *head;
Expand All @@ -241,19 +242,26 @@ static void format_metric(struct cmt *cmt, cfl_sds_t *buf, struct cmt_map *map,
opts = map->opts;

/* Measurement */
cfl_sds_cat_safe(buf, opts->ns, cfl_sds_len(opts->ns));

if (cfl_sds_len(opts->subsystem) > 0) {
cfl_sds_cat_safe(buf, "_", 1);
cfl_sds_cat_safe(buf, opts->subsystem, cfl_sds_len(opts->subsystem));
if (cfl_sds_len(opts->ns) > 0) {
cfl_sds_cat_safe(buf, opts->ns, cfl_sds_len(opts->ns));
if (cfl_sds_len(opts->subsystem) > 0) {
cfl_sds_cat_safe(buf, "_", 1);
cfl_sds_cat_safe(buf, opts->subsystem, cfl_sds_len(opts->subsystem));
}
has_namespace = CMT_TRUE;
}
else {
has_namespace = CMT_FALSE;
}

/* Static labels (tags) */
static_labels = cmt_labels_count(cmt->static_labels);
if (static_labels > 0) {
cfl_sds_cat_safe(buf, ",", 1);
if (has_namespace == CMT_TRUE) {
cfl_sds_cat_safe(buf, ",", 1);
}
cfl_list_foreach(head, &cmt->static_labels->list) {
count++;
static_count++;
slabel = cfl_list_entry(head, struct cmt_label, _head);

/* key */
Expand All @@ -265,7 +273,7 @@ static void format_metric(struct cmt *cmt, cfl_sds_t *buf, struct cmt_map *map,
/* val */
append_string(buf, slabel->val);

if (count < static_labels) {
if (static_count < static_labels) {
cfl_sds_cat_safe(buf, ",", 1);
}
}
Expand All @@ -274,7 +282,9 @@ static void format_metric(struct cmt *cmt, cfl_sds_t *buf, struct cmt_map *map,
/* Labels / Tags */
n = cfl_list_size(&metric->labels);
if (n > 0) {
cfl_sds_cat_safe(buf, ",", 1);
if (static_labels > 0 || has_namespace == CMT_TRUE) {
cfl_sds_cat_safe(buf, ",", 1);
}

label_k = cfl_list_entry_first(&map->label_keys, struct cmt_map_label, _head);

Expand All @@ -297,7 +307,9 @@ static void format_metric(struct cmt *cmt, cfl_sds_t *buf, struct cmt_map *map,
}
}

cfl_sds_cat_safe(buf, " ", 1);
if (has_namespace == CMT_TRUE || static_labels > 0 || n > 0) {
cfl_sds_cat_safe(buf, " ", 1);
}
append_metric_value(map, buf, metric);
}

Expand Down
8 changes: 4 additions & 4 deletions lib/cmetrics/src/cmt_encode_opentelemetry.c
Original file line number Diff line number Diff line change
Expand Up @@ -711,13 +711,13 @@ static inline Opentelemetry__Proto__Common__V1__AnyValue *cfl_variant_binary_to_
result->bytes_value.len = cfl_sds_len(value->data.as_bytes);
result->bytes_value.data = calloc(result->bytes_value.len, sizeof(char));

if (result->bytes_value.data == NULL) {
if (result->bytes_value.data) {
memcpy(result->bytes_value.data, value->data.as_bytes, result->bytes_value.len);
}
else {
otlp_any_value_destroy(result);

result = NULL;
}

memcpy(result->bytes_value.data, value->data.as_bytes, result->bytes_value.len);
}

return result;
Expand Down
1 change: 1 addition & 0 deletions lib/cmetrics/tests/data/issue_fluent_bit_9267.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_bu_nn 0 171798732
Loading

0 comments on commit 72a8188

Please sign in to comment.