Skip to content

Commit

Permalink
parser: json: do not stop packing on time lookup error (#682)
Browse files Browse the repository at this point in the history
If the parser have time lookup enabled and it fails, do not
skip the record, instead add a more verbose message about the
exception.

Signed-off-by: Eduardo Silva <eduardo@treasure-data.com>
  • Loading branch information
edsiper committed Jul 24, 2018
1 parent fa150c1 commit 1e5fe3f
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/flb_parser_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ int flb_parser_json_do(struct flb_parser *parser,
char *mp_buf = NULL;
char *time_key;
char *tmp_out_buf = NULL;
char tmp[255];
size_t tmp_out_size = 0;
size_t off = 0;
size_t map_size;
size_t mp_size;
size_t len;
msgpack_sbuffer mp_sbuf;
msgpack_packer mp_pck;
msgpack_unpacked result;
Expand Down Expand Up @@ -153,10 +155,19 @@ int flb_parser_json_do(struct flb_parser *parser,
ret = flb_parser_time_lookup((char *) v->via.str.ptr, v->via.str.size,
0, parser, &tm, &tmfrac);
if (ret == -1) {
msgpack_unpacked_destroy(&result);
return *out_size;
len = v->via.str.size;
if (len > sizeof(tmp) - 1) {
len = sizeof(tmp) - 1;
}
memcpy(tmp, v->via.str.ptr, len);
tmp[len] = '\0';
flb_warn("[parser:%s] Invalid time format %s for '%s'.",
parser->name, parser->time_fmt, tmp);
time_lookup = time(NULL);
}
else {
time_lookup = flb_parser_tm2time(&tm);
}
time_lookup = flb_parser_tm2time(&tm);

/* Compose a new map without the time_key field */
msgpack_sbuffer_init(&mp_sbuf);
Expand Down

0 comments on commit 1e5fe3f

Please sign in to comment.