Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions include/cmetrics/cmetrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,6 @@ struct cmt *cmt_create();
void cmt_destroy(struct cmt *cmt);
int cmt_label_add(struct cmt *cmt, char *key, char *val);
char *cmt_version();
void cmt_expire(struct cmt *cmt, uint64_t expiration);

#endif
3 changes: 3 additions & 0 deletions include/cmetrics/cmt_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ int cmt_map_metric_get_val(struct cmt_opts *opts, struct cmt_map *map,
double *out_val);
void cmt_map_metric_destroy(struct cmt_metric *metric);

int cmt_map_metrics_expire(struct cmt_map *, uint64_t);

void destroy_label_list(struct cfl_list *label_list);


#endif
37 changes: 37 additions & 0 deletions src/cmetrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <cmetrics/cmt_atomic.h>
#include <cmetrics/cmt_compat.h>
#include <cmetrics/cmt_label.h>
#include <cmetrics/cmt_map.h>
#include <cmetrics/cmt_version.h>

#include <cfl/cfl_kvlist.h>
Expand Down Expand Up @@ -136,6 +137,42 @@ void cmt_destroy(struct cmt *cmt)
free(cmt);
}

void cmt_expire(struct cmt *cmt, uint64_t expiration)
{
struct cfl_list *tmp;
struct cfl_list *head;
struct cmt_counter *c;
struct cmt_gauge *g;
struct cmt_summary *s;
struct cmt_histogram *h;
struct cmt_untyped *u;

cfl_list_foreach_safe(head, tmp, &cmt->counters) {
c = cfl_list_entry(head, struct cmt_counter, _head);
cmt_map_metrics_expire(c->map, expiration);
}

cfl_list_foreach_safe(head, tmp, &cmt->gauges) {
g = cfl_list_entry(head, struct cmt_gauge, _head);
cmt_map_metrics_expire(g->map, expiration);
}

cfl_list_foreach_safe(head, tmp, &cmt->summaries) {
s = cfl_list_entry(head, struct cmt_summary, _head);
cmt_map_metrics_expire(s->map, expiration);
}

cfl_list_foreach_safe(head, tmp, &cmt->histograms) {
h = cfl_list_entry(head, struct cmt_histogram, _head);
cmt_map_metrics_expire(s->map, expiration);
}

cfl_list_foreach_safe(head, tmp, &cmt->untypeds) {
u = cfl_list_entry(head, struct cmt_untyped, _head);
cmt_map_metrics_expire(u->map, expiration);
}
}

int cmt_label_add(struct cmt *cmt, char *key, char *val)
{
return cmt_labels_add_kv(cmt->static_labels, key, val);
Expand Down
16 changes: 16 additions & 0 deletions src/cmt_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,19 @@ void destroy_label_list(struct cfl_list *label_list)
}
}

/* This function can be used to expire untouched metrics.
*/
int cmt_map_metrics_expire(struct cmt_map *map, uint64_t expiration)
{
struct cfl_list *tmp;
struct cfl_list *head;
struct cmt_metric *metric;

cfl_list_foreach_safe(head, tmp, &map->metrics) {
metric = cfl_list_entry(head, struct cmt_metric, _head);
if (metric->timestamp <= expiration) {
cmt_map_metric_destroy(metric);
}
}
return 0;
}
Loading