Skip to content

Commit eabad37

Browse files
committed
lib: cmetrics: upgrade to v0.9.1
Signed-off-by: Eduardo Silva <[email protected]>
1 parent 2181632 commit eabad37

File tree

8 files changed

+576
-51
lines changed

8 files changed

+576
-51
lines changed

lib/cmetrics/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
66
# CMetrics Version
77
set(CMT_VERSION_MAJOR 0)
88
set(CMT_VERSION_MINOR 9)
9-
set(CMT_VERSION_PATCH 0)
9+
set(CMT_VERSION_PATCH 1)
1010
set(CMT_VERSION_STR "${CMT_VERSION_MAJOR}.${CMT_VERSION_MINOR}.${CMT_VERSION_PATCH}")
1111

1212
# Include helpers

lib/cmetrics/include/cmetrics/cmt_cat.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ struct cmt_untyped;
2828
struct cmt_histogram;
2929
struct cmt_summary;
3030

31-
int cmt_cat_counter(struct cmt *cmt, struct cmt_counter *counter);
32-
int cmt_cat_gauge(struct cmt *cmt, struct cmt_gauge *gauge);
33-
int cmt_cat_untyped(struct cmt *cmt, struct cmt_untyped *untyped);
34-
int cmt_cat_histogram(struct cmt *cmt, struct cmt_histogram *histogram);
35-
int cmt_cat_summary(struct cmt *cmt, struct cmt_summary *summary);
31+
int cmt_cat_copy_label_keys(struct cmt_map *map, char **out);
32+
int cmt_cat_copy_map(struct cmt_opts *opts, struct cmt_map *dst, struct cmt_map *src);
33+
int cmt_cat_counter(struct cmt *cmt, struct cmt_counter *counter, struct cmt_map *filtered_map);
34+
int cmt_cat_gauge(struct cmt *cmt, struct cmt_gauge *gauge, struct cmt_map *filtered_map);
35+
int cmt_cat_untyped(struct cmt *cmt, struct cmt_untyped *untyped, struct cmt_map *filtered_map);
36+
int cmt_cat_histogram(struct cmt *cmt, struct cmt_histogram *histogram, struct cmt_map *filtered_map);
37+
int cmt_cat_summary(struct cmt *cmt, struct cmt_summary *summary, struct cmt_map *filtered_map);
3638
int cmt_cat(struct cmt *dst, struct cmt *src);
3739

3840
#endif

lib/cmetrics/include/cmetrics/cmt_filter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,8 @@ int cmt_filter(struct cmt *dst, struct cmt *src,
3838
void *compare_ctx, int (*compare)(void *compare_ctx, const char *str, size_t slen),
3939
int flags);
4040

41+
int cmt_filter_with_label_pair(struct cmt *dst, struct cmt *src,
42+
const char *label_key,
43+
const char *label_value);
44+
4145
#endif

lib/cmetrics/include/cmetrics/cmt_map.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ struct cmt_metric *cmt_map_metric_get(struct cmt_opts *opts, struct cmt_map *map
5555
int cmt_map_metric_get_val(struct cmt_opts *opts, struct cmt_map *map,
5656
int labels_count, char **labels_val,
5757
double *out_val);
58+
void cmt_map_metric_destroy(struct cmt_metric *metric);
5859

5960
void destroy_label_list(struct cfl_list *label_list);
6061

lib/cmetrics/src/cmt_cat.c

Lines changed: 77 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include <cmetrics/cmt_histogram.h>
2727
#include <cmetrics/cmt_summary.h>
2828

29-
static int copy_label_keys(struct cmt_map *map, char **out)
29+
int cmt_cat_copy_label_keys(struct cmt_map *map, char **out)
3030
{
3131
int i;
3232
int s;
@@ -96,7 +96,7 @@ static int copy_label_values(struct cmt_metric *metric, char **out)
9696
return i;
9797
}
9898

99-
static int copy_map(struct cmt_opts *opts, struct cmt_map *dst, struct cmt_map *src)
99+
int cmt_cat_copy_map(struct cmt_opts *opts, struct cmt_map *dst, struct cmt_map *src)
100100
{
101101
int i;
102102
int c;
@@ -213,7 +213,8 @@ static int copy_map(struct cmt_opts *opts, struct cmt_map *dst, struct cmt_map *
213213

214214
}
215215

216-
int cmt_cat_counter(struct cmt *cmt, struct cmt_counter *counter)
216+
int cmt_cat_counter(struct cmt *cmt, struct cmt_counter *counter,
217+
struct cmt_map *filtered_map)
217218
{
218219
int ret;
219220
char **labels = NULL;
@@ -224,7 +225,7 @@ int cmt_cat_counter(struct cmt *cmt, struct cmt_counter *counter)
224225
map = counter->map;
225226
opts = map->opts;
226227

227-
ret = copy_label_keys(map, (char **) &labels);
228+
ret = cmt_cat_copy_label_keys(map, (char **) &labels);
228229
if (ret == -1) {
229230
return -1;
230231
}
@@ -240,15 +241,24 @@ int cmt_cat_counter(struct cmt *cmt, struct cmt_counter *counter)
240241
return -1;
241242
}
242243

243-
ret = copy_map(&c->opts, c->map, map);
244-
if (ret == -1) {
245-
return -1;
244+
if (filtered_map != NULL) {
245+
ret = cmt_cat_copy_map(&c->opts, c->map, filtered_map);
246+
if (ret == -1) {
247+
return -1;
248+
}
249+
}
250+
else {
251+
ret = cmt_cat_copy_map(&c->opts, c->map, map);
252+
if (ret == -1) {
253+
return -1;
254+
}
246255
}
247256

248257
return 0;
249258
}
250259

251-
int cmt_cat_gauge(struct cmt *cmt, struct cmt_gauge *gauge)
260+
int cmt_cat_gauge(struct cmt *cmt, struct cmt_gauge *gauge,
261+
struct cmt_map *filtered_map)
252262
{
253263
int ret;
254264
char **labels = NULL;
@@ -259,7 +269,7 @@ int cmt_cat_gauge(struct cmt *cmt, struct cmt_gauge *gauge)
259269
map = gauge->map;
260270
opts = map->opts;
261271

262-
ret = copy_label_keys(map, (char **) &labels);
272+
ret = cmt_cat_copy_label_keys(map, (char **) &labels);
263273
if (ret == -1) {
264274
return -1;
265275
}
@@ -274,15 +284,24 @@ int cmt_cat_gauge(struct cmt *cmt, struct cmt_gauge *gauge)
274284
return -1;
275285
}
276286

277-
ret = copy_map(&g->opts, g->map, map);
278-
if (ret == -1) {
279-
return -1;
287+
if (filtered_map != NULL) {
288+
ret = cmt_cat_copy_map(&g->opts, g->map, filtered_map);
289+
if (ret == -1) {
290+
return -1;
291+
}
292+
}
293+
else {
294+
ret = cmt_cat_copy_map(&g->opts, g->map, map);
295+
if (ret == -1) {
296+
return -1;
297+
}
280298
}
281299

282300
return 0;
283301
}
284302

285-
int cmt_cat_untyped(struct cmt *cmt, struct cmt_untyped *untyped)
303+
int cmt_cat_untyped(struct cmt *cmt, struct cmt_untyped *untyped,
304+
struct cmt_map *filtered_map)
286305
{
287306
int ret;
288307
char **labels = NULL;
@@ -293,7 +312,7 @@ int cmt_cat_untyped(struct cmt *cmt, struct cmt_untyped *untyped)
293312
map = untyped->map;
294313
opts = map->opts;
295314

296-
ret = copy_label_keys(map, (char **) &labels);
315+
ret = cmt_cat_copy_label_keys(map, (char **) &labels);
297316
if (ret == -1) {
298317
return -1;
299318
}
@@ -308,15 +327,24 @@ int cmt_cat_untyped(struct cmt *cmt, struct cmt_untyped *untyped)
308327
return -1;
309328
}
310329

311-
ret = copy_map(&u->opts, u->map, map);
312-
if (ret == -1) {
313-
return -1;
330+
if (filtered_map != NULL) {
331+
ret = cmt_cat_copy_map(&u->opts, u->map, filtered_map);
332+
if (ret == -1) {
333+
return -1;
334+
}
335+
}
336+
else {
337+
ret = cmt_cat_copy_map(&u->opts, u->map, map);
338+
if (ret == -1) {
339+
return -1;
340+
}
314341
}
315342

316343
return 0;
317344
}
318345

319-
int cmt_cat_histogram(struct cmt *cmt, struct cmt_histogram *histogram)
346+
int cmt_cat_histogram(struct cmt *cmt, struct cmt_histogram *histogram,
347+
struct cmt_map *filtered_map)
320348
{
321349
int i;
322350
double val;
@@ -333,7 +361,7 @@ int cmt_cat_histogram(struct cmt *cmt, struct cmt_histogram *histogram)
333361
opts = map->opts;
334362
timestamp = cmt_metric_get_timestamp(&map->metric);
335363

336-
ret = copy_label_keys(map, (char **) &labels);
364+
ret = cmt_cat_copy_label_keys(map, (char **) &labels);
337365
if (ret == -1) {
338366
return -1;
339367
}
@@ -354,15 +382,24 @@ int cmt_cat_histogram(struct cmt *cmt, struct cmt_histogram *histogram)
354382
return -1;
355383
}
356384

357-
ret = copy_map(&hist->opts, hist->map, map);
358-
if (ret == -1) {
359-
return -1;
385+
if (filtered_map != NULL) {
386+
ret = cmt_cat_copy_map(&hist->opts, hist->map, filtered_map);
387+
if (ret == -1) {
388+
return -1;
389+
}
390+
}
391+
else {
392+
ret = cmt_cat_copy_map(&hist->opts, hist->map, map);
393+
if (ret == -1) {
394+
return -1;
395+
}
360396
}
361397

362398
return 0;
363399
}
364400

365-
int cmt_cat_summary(struct cmt *cmt, struct cmt_summary *summary)
401+
int cmt_cat_summary(struct cmt *cmt, struct cmt_summary *summary,
402+
struct cmt_map *filtered_map)
366403
{
367404
int i;
368405
int ret;
@@ -378,7 +415,7 @@ int cmt_cat_summary(struct cmt *cmt, struct cmt_summary *summary)
378415
opts = map->opts;
379416
timestamp = cmt_metric_get_timestamp(&map->metric);
380417

381-
ret = copy_label_keys(map, (char **) &labels);
418+
ret = cmt_cat_copy_label_keys(map, (char **) &labels);
382419
if (ret == -1) {
383420
return -1;
384421
}
@@ -405,9 +442,17 @@ int cmt_cat_summary(struct cmt *cmt, struct cmt_summary *summary)
405442
free(labels);
406443
free(quantiles);
407444

408-
ret = copy_map(&sum->opts, sum->map, map);
409-
if (ret == -1) {
410-
return -1;
445+
if (filtered_map != NULL) {
446+
ret = cmt_cat_copy_map(&sum->opts, sum->map, filtered_map);
447+
if (ret == -1) {
448+
return -1;
449+
}
450+
}
451+
else {
452+
ret = cmt_cat_copy_map(&sum->opts, sum->map, map);
453+
if (ret == -1) {
454+
return -1;
455+
}
411456
}
412457

413458
return 0;
@@ -426,7 +471,7 @@ static int append_context(struct cmt *dst, struct cmt *src)
426471
/* Counters */
427472
cfl_list_foreach(head, &src->counters) {
428473
counter = cfl_list_entry(head, struct cmt_counter, _head);
429-
ret = cmt_cat_counter(dst, counter);
474+
ret = cmt_cat_counter(dst, counter, NULL);
430475
if (ret == -1) {
431476
return -1;
432477
}
@@ -435,7 +480,7 @@ static int append_context(struct cmt *dst, struct cmt *src)
435480
/* Gauges */
436481
cfl_list_foreach(head, &src->gauges) {
437482
gauge = cfl_list_entry(head, struct cmt_gauge, _head);
438-
ret = cmt_cat_gauge(dst, gauge);
483+
ret = cmt_cat_gauge(dst, gauge, NULL);
439484
if (ret == -1) {
440485
return -1;
441486
}
@@ -444,7 +489,7 @@ static int append_context(struct cmt *dst, struct cmt *src)
444489
/* Untyped */
445490
cfl_list_foreach(head, &src->untypeds) {
446491
untyped = cfl_list_entry(head, struct cmt_untyped, _head);
447-
ret = cmt_cat_untyped(dst, untyped);
492+
ret = cmt_cat_untyped(dst, untyped, NULL);
448493
if (ret == -1) {
449494
return -1;
450495
}
@@ -453,7 +498,7 @@ static int append_context(struct cmt *dst, struct cmt *src)
453498
/* Histogram */
454499
cfl_list_foreach(head, &src->histograms) {
455500
histogram = cfl_list_entry(head, struct cmt_histogram, _head);
456-
ret = cmt_cat_histogram(dst, histogram);
501+
ret = cmt_cat_histogram(dst, histogram, NULL);
457502
if (ret == -1) {
458503
return -1;
459504
}
@@ -462,7 +507,7 @@ static int append_context(struct cmt *dst, struct cmt *src)
462507
/* Summary */
463508
cfl_list_foreach(head, &src->summaries) {
464509
summary = cfl_list_entry(head, struct cmt_summary, _head);
465-
ret = cmt_cat_summary(dst, summary);
510+
ret = cmt_cat_summary(dst, summary, NULL);
466511
if (ret == -1) {
467512
return -1;
468513
}

0 commit comments

Comments
 (0)