Skip to content

Commit 0f3d980

Browse files
bshiftermgeriesa
authored andcommitted
pack: add 'epoch_ms' format based on jeongki-kim's commit (fluent#6114)
* pack: add 'epoch_ms' format Signed-off-by: Jeongki Kim <[email protected]> Signed-off-by: shifter <[email protected]> Signed-off-by: Manal Geries <[email protected]>
1 parent d0ac055 commit 0f3d980

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

include/fluent-bit/flb_pack.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#define FLB_PACK_JSON_DATE_ISO8601 1
4141
#define FLB_PACK_JSON_DATE_EPOCH 2
4242
#define FLB_PACK_JSON_DATE_JAVA_SQL_TIMESTAMP 3
43+
#define FLB_PACK_JSON_DATE_EPOCH_MS 4
4344

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

include/fluent-bit/flb_time.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ int flb_time_get(struct flb_time *tm);
7676
int flb_time_msleep(uint32_t ms);
7777
double flb_time_to_double(struct flb_time *tm);
7878
uint64_t flb_time_to_nanosec(struct flb_time *tm);
79+
uint64_t flb_time_to_millisec(struct flb_time *tm);
7980
int flb_time_add(struct flb_time *base, struct flb_time *duration,
8081
struct flb_time *result);
8182
int flb_time_diff(struct flb_time *time1,

src/flb_pack.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,11 @@ int flb_pack_to_json_date_type(const char *str)
832832
else if (strcasecmp(str, "epoch") == 0) {
833833
return FLB_PACK_JSON_DATE_EPOCH;
834834
}
835+
else if (strcasecmp(str, "epoch_ms") == 0 ||
836+
strcasecmp(str, "epoch_millis") == 0 ||
837+
strcasecmp(str, "epoch_milliseconds") == 0) {
838+
return FLB_PACK_JSON_DATE_EPOCH_MS;
839+
}
835840

836841
return -1;
837842
}
@@ -986,6 +991,9 @@ flb_sds_t flb_pack_msgpack_to_json_format(const char *data, uint64_t bytes,
986991
case FLB_PACK_JSON_DATE_EPOCH:
987992
msgpack_pack_uint64(&tmp_pck, (long long unsigned)(tms.tm.tv_sec));
988993
break;
994+
case FLB_PACK_JSON_DATE_EPOCH_MS:
995+
msgpack_pack_uint64(&tmp_pck, flb_time_to_millisec(&tms));
996+
break;
989997
}
990998
}
991999

src/flb_time.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ uint64_t flb_time_to_nanosec(struct flb_time *tm)
9696
return (((uint64_t)tm->tm.tv_sec * 1000000000L) + tm->tm.tv_nsec);
9797
}
9898

99+
uint64_t flb_time_to_millisec(struct flb_time *tm)
100+
{
101+
return (((uint64_t)tm->tm.tv_sec * 1000L) + tm->tm.tv_nsec / 1000000L);
102+
}
103+
99104
int flb_time_add(struct flb_time *base, struct flb_time *duration, struct flb_time *result)
100105
{
101106
if (base == NULL || duration == NULL|| result == NULL) {

0 commit comments

Comments
 (0)