Skip to content

Commit

Permalink
parser_decoders: re-structure core functionality and extend actions
Browse files Browse the repository at this point in the history
Signed-off-by: Eduardo Silva <[email protected]>
  • Loading branch information
edsiper committed Mar 19, 2018
1 parent d34dcaf commit 7798b36
Show file tree
Hide file tree
Showing 3 changed files with 262 additions and 73 deletions.
4 changes: 2 additions & 2 deletions conf/parsers.conf
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
Time_Keep On
# Command | Decoder | Field | Optional Action
# ===========|==================|=================
Decode_Field json log try_next
Decode_Field escaped log
Decode_Field_As escaped log do_next
Decode_Field json log

[PARSER]
Name docker-daemon
Expand Down
36 changes: 21 additions & 15 deletions include/fluent-bit/flb_parser_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/* Fluent Bit
* ==========
* Copyright (C) 2015-2017 Treasure Data Inc.
* Copyright (C) 2015-2018 Treasure Data Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,35 +21,41 @@
#define FLB_PARSER_DECODER_H

#include <fluent-bit/flb_info.h>
#include <fluent-bit/flb_sds.h>
#include <monkey/mk_core.h>

/* Decoder types */
/* Decoder behavior */
#define FLB_PARSER_DEC_DEFAULT 0 /* results place as separate keys */
#define FLB_PARSER_DEC_AS 1 /* results replace current key/value */

/* Decoder Backend */
#define FLB_PARSER_DEC_JSON 0 /* decode_json() */
#define FLB_PARSER_DEC_ESCAPED 1 /* decode_escaped() */

/* Decoder actions */
#define FLB_PARSER_ACT_NONE 0
#define FLB_PARSER_ACT_TRY_NEXT 1
#define FLB_PARSER_ACT_DO_NEXT 2

#define FLB_PARSER_DEC_BUF_SIZE 1024*8 /* 8KB */

struct flb_parser_dec {
int type;
int action;

/* Key name */
int key_len;
char *key_name;

/* Temporal buffer for data decoding */
int buf_len;
char *buf_data;
size_t buf_size;
struct flb_parser_dec_rule {
int type; /* decode_field, decode_field_as */
int backend; /* backend handler: json, escaped */
int action; /* actions: try_next, do_next */

/* Link to parser->decoders list */
/* Link to flb_parser_dec->rules list head */
struct mk_list _head;
};

struct flb_parser_dec {
flb_sds_t key;
flb_sds_t buffer; /* temporal buffer for decoding work */
int add_extra_keys; /* if type == FLB_PARSER_DEC_DEFAULT, flag is True */
struct mk_list rules; /* list head for decoder key rules */
struct mk_list _head; /* link to parser->decoders */
};

struct mk_list *flb_parser_decoder_list_create(struct mk_rconf_section *section);
int flb_parser_decoder_list_destroy(struct mk_list *list);
int flb_parser_decoder_do(struct mk_list *decoders,
Expand Down
Loading

0 comments on commit 7798b36

Please sign in to comment.