Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filter: Implement deleting by label key-value pair operation #207

Merged
merged 7 commits into from
May 16, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions include/cmetrics/cmt_cat.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ struct cmt_untyped;
struct cmt_histogram;
struct cmt_summary;

int cmt_cat_counter(struct cmt *cmt, struct cmt_counter *counter);
int cmt_cat_gauge(struct cmt *cmt, struct cmt_gauge *gauge);
int cmt_cat_untyped(struct cmt *cmt, struct cmt_untyped *untyped);
int cmt_cat_histogram(struct cmt *cmt, struct cmt_histogram *histogram);
int cmt_cat_summary(struct cmt *cmt, struct cmt_summary *summary);
int cmt_cat_copy_label_keys(struct cmt_map *map, char **out);
int cmt_cat_copy_map(struct cmt_opts *opts, struct cmt_map *dst, struct cmt_map *src);
int cmt_cat_counter(struct cmt *cmt, struct cmt_counter *counter, struct cmt_map *filtered_map);
int cmt_cat_gauge(struct cmt *cmt, struct cmt_gauge *gauge, struct cmt_map *filtered_map);
int cmt_cat_untyped(struct cmt *cmt, struct cmt_untyped *untyped, struct cmt_map *filtered_map);
int cmt_cat_histogram(struct cmt *cmt, struct cmt_histogram *histogram, struct cmt_map *filtered_map);
int cmt_cat_summary(struct cmt *cmt, struct cmt_summary *summary, struct cmt_map *filtered_map);
int cmt_cat(struct cmt *dst, struct cmt *src);

#endif
4 changes: 4 additions & 0 deletions include/cmetrics/cmt_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ int cmt_filter(struct cmt *dst, struct cmt *src,
void *compare_ctx, int (*compare)(void *compare_ctx, const char *str, size_t slen),
int flags);

int cmt_filter_with_label_pair(struct cmt *dst, struct cmt *src,
const char *label_key,
const char *label_value);

#endif
1 change: 1 addition & 0 deletions include/cmetrics/cmt_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ struct cmt_metric *cmt_map_metric_get(struct cmt_opts *opts, struct cmt_map *map
int cmt_map_metric_get_val(struct cmt_opts *opts, struct cmt_map *map,
int labels_count, char **labels_val,
double *out_val);
void cmt_map_metric_destroy(struct cmt_metric *metric);

void destroy_label_list(struct cfl_list *label_list);

Expand Down
109 changes: 77 additions & 32 deletions src/cmt_cat.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <cmetrics/cmt_histogram.h>
#include <cmetrics/cmt_summary.h>

static int copy_label_keys(struct cmt_map *map, char **out)
int cmt_cat_copy_label_keys(struct cmt_map *map, char **out)
{
int i;
int s;
Expand Down Expand Up @@ -96,7 +96,7 @@ static int copy_label_values(struct cmt_metric *metric, char **out)
return i;
}

static int copy_map(struct cmt_opts *opts, struct cmt_map *dst, struct cmt_map *src)
int cmt_cat_copy_map(struct cmt_opts *opts, struct cmt_map *dst, struct cmt_map *src)
{
int i;
int c;
Expand Down Expand Up @@ -213,7 +213,8 @@ static int copy_map(struct cmt_opts *opts, struct cmt_map *dst, struct cmt_map *

}

int cmt_cat_counter(struct cmt *cmt, struct cmt_counter *counter)
int cmt_cat_counter(struct cmt *cmt, struct cmt_counter *counter,
struct cmt_map *filtered_map)
{
int ret;
char **labels = NULL;
Expand All @@ -224,7 +225,7 @@ int cmt_cat_counter(struct cmt *cmt, struct cmt_counter *counter)
map = counter->map;
opts = map->opts;

ret = copy_label_keys(map, (char **) &labels);
ret = cmt_cat_copy_label_keys(map, (char **) &labels);
if (ret == -1) {
return -1;
}
Expand All @@ -240,15 +241,24 @@ int cmt_cat_counter(struct cmt *cmt, struct cmt_counter *counter)
return -1;
}

ret = copy_map(&c->opts, c->map, map);
if (ret == -1) {
return -1;
if (filtered_map != NULL) {
ret = cmt_cat_copy_map(&c->opts, c->map, filtered_map);
if (ret == -1) {
return -1;
}
}
else {
ret = cmt_cat_copy_map(&c->opts, c->map, map);
if (ret == -1) {
return -1;
}
}

return 0;
}

int cmt_cat_gauge(struct cmt *cmt, struct cmt_gauge *gauge)
int cmt_cat_gauge(struct cmt *cmt, struct cmt_gauge *gauge,
struct cmt_map *filtered_map)
{
int ret;
char **labels = NULL;
Expand All @@ -259,7 +269,7 @@ int cmt_cat_gauge(struct cmt *cmt, struct cmt_gauge *gauge)
map = gauge->map;
opts = map->opts;

ret = copy_label_keys(map, (char **) &labels);
ret = cmt_cat_copy_label_keys(map, (char **) &labels);
if (ret == -1) {
return -1;
}
Expand All @@ -274,15 +284,24 @@ int cmt_cat_gauge(struct cmt *cmt, struct cmt_gauge *gauge)
return -1;
}

ret = copy_map(&g->opts, g->map, map);
if (ret == -1) {
return -1;
if (filtered_map != NULL) {
ret = cmt_cat_copy_map(&g->opts, g->map, filtered_map);
if (ret == -1) {
return -1;
}
}
else {
ret = cmt_cat_copy_map(&g->opts, g->map, map);
if (ret == -1) {
return -1;
}
}

return 0;
}

int cmt_cat_untyped(struct cmt *cmt, struct cmt_untyped *untyped)
int cmt_cat_untyped(struct cmt *cmt, struct cmt_untyped *untyped,
struct cmt_map *filtered_map)
{
int ret;
char **labels = NULL;
Expand All @@ -293,7 +312,7 @@ int cmt_cat_untyped(struct cmt *cmt, struct cmt_untyped *untyped)
map = untyped->map;
opts = map->opts;

ret = copy_label_keys(map, (char **) &labels);
ret = cmt_cat_copy_label_keys(map, (char **) &labels);
if (ret == -1) {
return -1;
}
Expand All @@ -308,15 +327,24 @@ int cmt_cat_untyped(struct cmt *cmt, struct cmt_untyped *untyped)
return -1;
}

ret = copy_map(&u->opts, u->map, map);
if (ret == -1) {
return -1;
if (filtered_map != NULL) {
ret = cmt_cat_copy_map(&u->opts, u->map, filtered_map);
if (ret == -1) {
return -1;
}
}
else {
ret = cmt_cat_copy_map(&u->opts, u->map, map);
if (ret == -1) {
return -1;
}
}

return 0;
}

int cmt_cat_histogram(struct cmt *cmt, struct cmt_histogram *histogram)
int cmt_cat_histogram(struct cmt *cmt, struct cmt_histogram *histogram,
struct cmt_map *filtered_map)
{
int i;
double val;
Expand All @@ -333,7 +361,7 @@ int cmt_cat_histogram(struct cmt *cmt, struct cmt_histogram *histogram)
opts = map->opts;
timestamp = cmt_metric_get_timestamp(&map->metric);

ret = copy_label_keys(map, (char **) &labels);
ret = cmt_cat_copy_label_keys(map, (char **) &labels);
if (ret == -1) {
return -1;
}
Expand All @@ -354,15 +382,24 @@ int cmt_cat_histogram(struct cmt *cmt, struct cmt_histogram *histogram)
return -1;
}

ret = copy_map(&hist->opts, hist->map, map);
if (ret == -1) {
return -1;
if (filtered_map != NULL) {
ret = cmt_cat_copy_map(&hist->opts, hist->map, filtered_map);
if (ret == -1) {
return -1;
}
}
else {
ret = cmt_cat_copy_map(&hist->opts, hist->map, map);
if (ret == -1) {
return -1;
}
}

return 0;
}

int cmt_cat_summary(struct cmt *cmt, struct cmt_summary *summary)
int cmt_cat_summary(struct cmt *cmt, struct cmt_summary *summary,
struct cmt_map *filtered_map)
{
int i;
int ret;
Expand All @@ -378,7 +415,7 @@ int cmt_cat_summary(struct cmt *cmt, struct cmt_summary *summary)
opts = map->opts;
timestamp = cmt_metric_get_timestamp(&map->metric);

ret = copy_label_keys(map, (char **) &labels);
ret = cmt_cat_copy_label_keys(map, (char **) &labels);
if (ret == -1) {
return -1;
}
Expand All @@ -405,9 +442,17 @@ int cmt_cat_summary(struct cmt *cmt, struct cmt_summary *summary)
free(labels);
free(quantiles);

ret = copy_map(&sum->opts, sum->map, map);
if (ret == -1) {
return -1;
if (filtered_map != NULL) {
ret = cmt_cat_copy_map(&sum->opts, sum->map, filtered_map);
if (ret == -1) {
return -1;
}
}
else {
ret = cmt_cat_copy_map(&sum->opts, sum->map, map);
if (ret == -1) {
return -1;
}
}

return 0;
Expand All @@ -426,7 +471,7 @@ static int append_context(struct cmt *dst, struct cmt *src)
/* Counters */
cfl_list_foreach(head, &src->counters) {
counter = cfl_list_entry(head, struct cmt_counter, _head);
ret = cmt_cat_counter(dst, counter);
ret = cmt_cat_counter(dst, counter, NULL);
if (ret == -1) {
return -1;
}
Expand All @@ -435,7 +480,7 @@ static int append_context(struct cmt *dst, struct cmt *src)
/* Gauges */
cfl_list_foreach(head, &src->gauges) {
gauge = cfl_list_entry(head, struct cmt_gauge, _head);
ret = cmt_cat_gauge(dst, gauge);
ret = cmt_cat_gauge(dst, gauge, NULL);
if (ret == -1) {
return -1;
}
Expand All @@ -444,7 +489,7 @@ static int append_context(struct cmt *dst, struct cmt *src)
/* Untyped */
cfl_list_foreach(head, &src->untypeds) {
untyped = cfl_list_entry(head, struct cmt_untyped, _head);
ret = cmt_cat_untyped(dst, untyped);
ret = cmt_cat_untyped(dst, untyped, NULL);
if (ret == -1) {
return -1;
}
Expand All @@ -453,7 +498,7 @@ static int append_context(struct cmt *dst, struct cmt *src)
/* Histogram */
cfl_list_foreach(head, &src->histograms) {
histogram = cfl_list_entry(head, struct cmt_histogram, _head);
ret = cmt_cat_histogram(dst, histogram);
ret = cmt_cat_histogram(dst, histogram, NULL);
if (ret == -1) {
return -1;
}
Expand All @@ -462,7 +507,7 @@ static int append_context(struct cmt *dst, struct cmt *src)
/* Summary */
cfl_list_foreach(head, &src->summaries) {
summary = cfl_list_entry(head, struct cmt_summary, _head);
ret = cmt_cat_summary(dst, summary);
ret = cmt_cat_summary(dst, summary, NULL);
if (ret == -1) {
return -1;
}
Expand Down