Skip to content

Commit

Permalink
filter_kubernetes: add Keep_Log option
Browse files Browse the repository at this point in the history
This option allows to choose wether to keep the original log field once it has
been successfully unescaped or parsed.

Signed-off-by: Yann Soubeyrand <[email protected]>
  • Loading branch information
Yann Soubeyrand authored and edsiper committed Apr 5, 2019
1 parent 27f14f8 commit 3dea58e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
7 changes: 7 additions & 0 deletions plugins/filter_kubernetes/kube_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct flb_kube *flb_kube_conf_create(struct flb_filter_instance *i,
}
ctx->config = config;
ctx->merge_log = FLB_FALSE;
ctx->keep_log = FLB_TRUE;
ctx->labels = FLB_TRUE;
ctx->annotations = FLB_TRUE;
ctx->dummy_meta = FLB_FALSE;
Expand Down Expand Up @@ -118,6 +119,12 @@ struct flb_kube *flb_kube_conf_create(struct flb_filter_instance *i,
ctx->merge_log_trim = FLB_TRUE;
}

/* Keep original log key after successful parsing */
tmp = flb_filter_get_property("keep_log", i);
if (tmp) {
ctx->keep_log = flb_utils_bool(tmp);
}

/* Get Kubernetes API server */
url = flb_filter_get_property("kube_url", i);
if (!url) {
Expand Down
3 changes: 3 additions & 0 deletions plugins/filter_kubernetes/kube_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ struct flb_kube {
int merge_log_key_len;
char *merge_log_key;

/* Keep original log key after successful parsing */
int keep_log;

/* API Server end point */
char kube_url[1024];

Expand Down
12 changes: 9 additions & 3 deletions plugins/filter_kubernetes/kubernetes.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ static int pack_map_content(msgpack_packer *pck, msgpack_sbuffer *sbuf,
new_map_size += log_buf_entries;
}

if (merge_status == MERGE_PARSED && ctx->keep_log == FLB_FALSE) {
new_map_size--;
}

msgpack_pack_map(pck, new_map_size);

/* Original map */
Expand All @@ -330,9 +334,11 @@ static int pack_map_content(msgpack_packer *pck, msgpack_sbuffer *sbuf,
*/
if (log_index == i &&
(merge_status == MERGE_UNESCAPED || merge_status == MERGE_PARSED)) {
msgpack_pack_object(pck, k);
msgpack_pack_str(pck, ctx->unesc_buf_len);
msgpack_pack_str_body(pck, ctx->unesc_buf, ctx->unesc_buf_len);
if (merge_status == MERGE_UNESCAPED || ctx->keep_log == FLB_TRUE) {
msgpack_pack_object(pck, k);
msgpack_pack_str(pck, ctx->unesc_buf_len);
msgpack_pack_str_body(pck, ctx->unesc_buf, ctx->unesc_buf_len);
}
}
else { /* MERGE_BINARY ? */
msgpack_pack_object(pck, k);
Expand Down

0 comments on commit 3dea58e

Please sign in to comment.