Skip to content

Commit 341ae83

Browse files
committed
lib: cmetrics: upgrade to v0.3.4
Signed-off-by: Eduardo Silva <[email protected]>
1 parent 4180633 commit 341ae83

File tree

14 files changed

+439
-22
lines changed

14 files changed

+439
-22
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
steps:
5959
- uses: actions/checkout@v3
6060
- name: Build on ${{ matrix.os }} with ${{ matrix.compiler }}
61-
uses: uraimo/run-on-arch-action@v2.1.1
61+
uses: uraimo/run-on-arch-action@v2.2.0
6262
with:
6363
arch: aarch64
6464
distro: ubuntu20.04

lib/cmetrics/.github/workflows/packages.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
format: [ rpm, deb ]
2020
steps:
2121
- uses: actions/checkout@v2
22-
- uses: uraimo/run-on-arch-action@v2.1.1
22+
- uses: uraimo/run-on-arch-action@v2.2.0
2323
name: Build the ${{matrix.format}} packages
2424
with:
2525
arch: aarch64
@@ -36,7 +36,7 @@ jobs:
3636
echo ${{ matrix.format }} | awk '{print toupper($0)}' | xargs -I{} cpack -G {}
3737
3838
- name: Store the master package artifacts
39-
uses: actions/upload-artifact@v2
39+
uses: actions/upload-artifact@v3
4040
with:
4141
name: ${{ matrix.format }}-arm64
4242
path: |
@@ -58,7 +58,7 @@ jobs:
5858
echo ${{ matrix.format }} | awk '{print toupper($0)}' | xargs -I{} cpack -G {}
5959
6060
- name: Store the master package artifacts
61-
uses: actions/upload-artifact@v2
61+
uses: actions/upload-artifact@v3
6262
with:
6363
name: ${{ matrix.format }}-amd64
6464
path: |
@@ -74,7 +74,7 @@ jobs:
7474
contents: write
7575
steps:
7676
- name: Download all artefacts
77-
uses: actions/download-artifact@v2
77+
uses: actions/download-artifact@v3
7878
with:
7979
path: artifacts/
8080

lib/cmetrics/CMakeLists.txt

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ if(CMAKE_SYSTEM_NAME MATCHES "Windows")
1818
message(STATUS "Specifying YY_NO_UNISTD_H")
1919
endif()
2020

21+
# Define macro to identify macOS system
22+
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
23+
set(CMT_SYSTEM_MACOS On)
24+
add_definitions(-DCMT_SYSTEM_MACOS)
25+
endif()
2126

2227
if(NOT MSVC)
2328
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
@@ -26,7 +31,7 @@ endif()
2631
# CMetrics Version
2732
set(CMT_VERSION_MAJOR 0)
2833
set(CMT_VERSION_MINOR 3)
29-
set(CMT_VERSION_PATCH 1)
34+
set(CMT_VERSION_PATCH 4)
3035
set(CMT_VERSION_STR "${CMT_VERSION_MAJOR}.${CMT_VERSION_MINOR}.${CMT_VERSION_PATCH}")
3136

3237
# Define __FILENAME__ consistently across Operating Systems
@@ -222,6 +227,7 @@ endif()
222227
# Enable components
223228
set(CPACK_DEB_COMPONENT_INSTALL ON)
224229
set(CPACK_RPM_COMPONENT_INSTALL ON)
230+
set(CPACK_productbuild_COMPONENT_INSTALL ON)
225231
set(CPACK_COMPONENTS_ALL ${CPACK_COMPONENTS_ALL} binary library headers)
226232
set(CPACK_COMPONENTS_GROUPING "ONE_PER_GROUP")
227233

@@ -275,4 +281,40 @@ if(CPACK_GENERATOR MATCHES "ZIP")
275281
set(CPACK_PACKAGE_INSTALL_DIRECTORY "cmetrics")
276282
endif()
277283

284+
# CPack: macOS w/ productbuild
285+
if(CMT_SYSTEM_MACOS)
286+
# Determine the platform suffix
287+
execute_process(
288+
COMMAND uname -m
289+
RESULT_VARIABLE UNAME_M_RESULT
290+
OUTPUT_VARIABLE UNAME_ARCH
291+
OUTPUT_STRIP_TRAILING_WHITESPACE
292+
)
293+
if (UNAME_M_RESULT EQUAL 0 AND UNAME_ARCH STREQUAL "arm64")
294+
set(CMETRICS_PKG ${CMAKE_CURRENT_BINARY_DIR}/${CPACK_PACKAGE_NAME}-${CMT_VERSION_STR}-apple)
295+
elseif(UNAME_M_RESULT EQUAL 0 AND UNAME_ARCH STREQUAL "x86_64")
296+
set(CMETRICS_PKG ${CMAKE_CURRENT_BINARY_DIR}/${CPACK_PACKAGE_NAME}-${CMT_VERSION_STR}-intel)
297+
else()
298+
set(CMETRICS_PKG ${CMAKE_CURRENT_BINARY_DIR}/${CPACK_PACKAGE_NAME}-${CMT_VERSION_STR}-${UNAME_ARCH})
299+
endif()
300+
301+
if (CPACK_GENERATOR MATCHES "productbuild")
302+
set(CPACK_SET_DESTDIR "ON")
303+
configure_file(cpack/macos/welcome.txt.cmakein ${CMAKE_CURRENT_BINARY_DIR}/welcome.txt)
304+
configure_file(LICENSE ${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt)
305+
find_program(CONVERTER textutil)
306+
if (NOT CONVERTER)
307+
message(FATAL_ERROR "textutil not found.")
308+
endif()
309+
if (CONVERTER)
310+
execute_process(COMMAND ${CONVERTER} -convert html "${CMAKE_SOURCE_DIR}/README.md" -output "${CMAKE_BINARY_DIR}/README.html")
311+
endif()
312+
set(CPACK_PACKAGE_FILE_NAME "${CMETRICS_PKG}")
313+
set(CPACK_RESOURCE_FILE_WELCOME ${CMAKE_CURRENT_BINARY_DIR}/welcome.txt)
314+
set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt)
315+
set(CPACK_RESOURCE_FILE_README ${CMAKE_CURRENT_BINARY_DIR}/README.html)
316+
set(CPACK_PRODUCTBUILD_IDENTIFIER "com.calyptia.${CPACK_PACKAGE_NAME}")
317+
endif()
318+
endif()
319+
278320
include(CPack)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
This will install @CPACK_PACKAGE_NAME@ on your Mac.
2+
3+
--------------------------------------------------
4+
5+
Thank you for trying @CPACK_PACKAGE_NAME@! Have a fantastic day!
6+
7+
You can use @CPACK_PACKAGE_NAME@ as metrics library on your system.

lib/cmetrics/src/cmetrics.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ struct cmt *cmt_create()
5858
cmt_labels_destroy(cmt->static_labels);
5959

6060
free(cmt);
61+
return NULL;
6162
}
6263

6364
cmt->external_metadata = cmt_kvlist_create();
@@ -67,6 +68,7 @@ struct cmt *cmt_create()
6768
cmt_labels_destroy(cmt->static_labels);
6869

6970
free(cmt);
71+
return NULL;
7072
}
7173

7274
mk_list_init(&cmt->counters);

lib/cmetrics/src/cmt_decode_msgpack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ static int unpack_metric(mpack_reader_t *reader,
737737
if (decode_context->map->type == CMT_HISTOGRAM) {
738738
histogram = decode_context->map->parent;
739739

740-
metric->hist_buckets = calloc(histogram->buckets->count, sizeof(uint64_t));
740+
metric->hist_buckets = calloc(histogram->buckets->count + 1, sizeof(uint64_t));
741741

742742
if (metric->hist_buckets == NULL) {
743743
cmt_errno();

lib/cmetrics/src/cmt_decode_opentelemetry.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ static int append_new_map_label_key(struct cmt_map *map, char *name)
237237
}
238238

239239
mk_list_add(&label->_head, &map->label_keys);
240+
map->label_count++;
240241

241242
return CMT_DECODE_OPENTELEMETRY_SUCCESS;
242243
}
@@ -921,6 +922,13 @@ static int decode_metrics_entry(struct cmt *cmt,
921922
metric_subsystem = "";
922923
metric_description = metric->description;
923924

925+
if (metric_description == NULL) {
926+
metric_description = "-";
927+
}
928+
else if (strlen(metric_description) == 0) {
929+
metric_description = "-";
930+
}
931+
924932
if (metric->data_case == OPENTELEMETRY__PROTO__METRICS__V1__METRIC__DATA_SUM) {
925933
instance = cmt_counter_create(cmt,
926934
metric_namespace,

lib/cmetrics/src/cmt_decode_prometheus.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ static int add_metric_histogram(struct cmt_decode_prometheus_context *context)
432432
uint64_t *bucket_defaults = NULL;
433433
double sum;
434434
uint64_t count;
435+
double count_dbl;
435436
struct mk_list *head;
436437
struct mk_list *tmp;
437438
struct cmt_decode_prometheus_context_sample *sample;
@@ -510,10 +511,17 @@ static int add_metric_histogram(struct cmt_decode_prometheus_context *context)
510511
}
511512
if (parse_uint64(sample->value1,
512513
bucket_defaults + bucket_index)) {
513-
ret = report_error(context,
514-
CMT_DECODE_PROMETHEUS_CMT_CREATE_ERROR,
515-
"failed to parse bucket count");
516-
goto end;
514+
/* Count is supposed to be integer, but apparently
515+
* some tools can generate count in a floating format.
516+
* Try to parse as a double and then cast to uint64_t */
517+
if (parse_double(sample->value1, &count_dbl) || count_dbl < 0) {
518+
ret = report_error(context,
519+
CMT_DECODE_PROMETHEUS_CMT_CREATE_ERROR,
520+
"failed to parse count");
521+
goto end;
522+
} else {
523+
*(bucket_defaults + bucket_index) = (uint64_t)count_dbl;
524+
}
517525
}
518526
bucket_index++;
519527

@@ -545,10 +553,17 @@ static int add_metric_histogram(struct cmt_decode_prometheus_context *context)
545553
break;
546554
case CMT_DECODE_PROMETHEUS_CONTEXT_SAMPLE_TYPE_COUNT:
547555
if (parse_uint64(sample->value1, &count)) {
548-
ret = report_error(context,
549-
CMT_DECODE_PROMETHEUS_CMT_CREATE_ERROR,
550-
"failed to parse count");
551-
goto end;
556+
/* Count is supposed to be integer, but apparently
557+
* some tools can generate count in a floating format.
558+
* Try to parse as a double and then cast to uint64_t */
559+
if (parse_double(sample->value1, &count_dbl) || count_dbl < 0) {
560+
ret = report_error(context,
561+
CMT_DECODE_PROMETHEUS_CMT_CREATE_ERROR,
562+
"failed to parse count");
563+
goto end;
564+
} else {
565+
count = (uint64_t)count_dbl;
566+
}
552567
}
553568
bucket_defaults[bucket_index] = count;
554569

0 commit comments

Comments
 (0)