Skip to content

Commit

Permalink
out_prometheus_exporter: add destructor callback
Browse files Browse the repository at this point in the history
Signed-off-by: Takahiro Yamashita <[email protected]>
  • Loading branch information
nokute78 authored and edsiper committed Jul 7, 2021
1 parent a0c8082 commit ef0e705
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion plugins/out_prometheus_exporter/prom_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,29 @@ static int cleanup_metrics()
return c;
}

/* destructor callback */
static void destruct_metrics(void *data)
{
int c = 0;
struct mk_list *tmp;
struct mk_list *head;
struct mk_list *metrics_list = (struct mk_list*)data;
struct prom_http_buf *entry;

if (!metrics_list) {
return;
}

mk_list_foreach_safe(head, tmp, metrics_list) {
entry = mk_list_entry(head, struct prom_http_buf, _head);
mk_list_del(&entry->_head);
flb_free(entry->buf_data);
flb_free(entry);
}

flb_free(metrics_list);
}

/*
* Callback invoked every time a new payload of Metrics is received from
* Fluent Bit engine through Message Queue channel.
Expand Down Expand Up @@ -126,7 +149,7 @@ static int http_server_mq_create(struct prom_http *ph)
{
int ret;

pthread_key_create(&ph_metrics_key, NULL);
pthread_key_create(&ph_metrics_key, destruct_metrics);

ret = mk_mq_create(ph->ctx, "/metrics", cb_mq_metrics, NULL);
if (ret == -1) {
Expand Down

0 comments on commit ef0e705

Please sign in to comment.