Skip to content

Commit d80e644

Browse files
committed
pack: add 'epoch_ms' format
Signed-off-by: Jeongki Kim <[email protected]>
1 parent 3379df9 commit d80e644

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

include/fluent-bit/flb_pack.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@
3636
#define FLB_PACK_JSON_PRIMITIVE JSMN_PRIMITIVE
3737

3838
/* Date formats */
39-
#define FLB_PACK_JSON_DATE_DOUBLE 0
40-
#define FLB_PACK_JSON_DATE_ISO8601 1
41-
#define FLB_PACK_JSON_DATE_EPOCH 2
39+
#define FLB_PACK_JSON_DATE_DOUBLE 0
40+
#define FLB_PACK_JSON_DATE_ISO8601 1
41+
#define FLB_PACK_JSON_DATE_EPOCH 2
42+
#define FLB_PACK_JSON_DATE_EPOCH_MS 3
4243

4344
/* Specific ISO8601 format */
4445
#define FLB_PACK_JSON_DATE_ISO8601_FMT "%Y-%m-%dT%H:%M:%S"

src/flb_pack.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,11 @@ int flb_pack_to_json_date_type(const char *str)
772772
else if (strcasecmp(str, "epoch") == 0) {
773773
return FLB_PACK_JSON_DATE_EPOCH;
774774
}
775+
else if (strcasecmp(str, "epoch_ms") == 0 ||
776+
strcasecmp(str, "epoch_millis") == 0 ||
777+
strcasecmp(str, "epoch_milliseconds") == 0) {
778+
return FLB_PACK_JSON_DATE_EPOCH_MS;
779+
}
775780

776781
return -1;
777782
}
@@ -892,6 +897,11 @@ flb_sds_t flb_pack_msgpack_to_json_format(const char *data, uint64_t bytes,
892897
case FLB_PACK_JSON_DATE_EPOCH:
893898
msgpack_pack_uint64(&tmp_pck, (long long unsigned)(tms.tm.tv_sec));
894899
break;
900+
case FLB_PACK_JSON_DATE_EPOCH_MS:
901+
msgpack_pack_uint64(&tmp_pck,
902+
(long long unsigned)(tms.tm.tv_sec) * 1000 +
903+
tms.tm.tv_nsec / 1000000);
904+
break;
895905
}
896906
}
897907

0 commit comments

Comments
 (0)