Skip to content

Commit

Permalink
pack: add 'epoch_ms' format based on jeongki-kim's commit (fluent#6114)
Browse files Browse the repository at this point in the history
* pack: add 'epoch_ms' format

Signed-off-by: Jeongki Kim <[email protected]>
Signed-off-by: shifter <[email protected]>
Signed-off-by: root <[email protected]>
  • Loading branch information
bshifter authored and root committed Feb 8, 2023
1 parent ecaef64 commit 5144312
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/fluent-bit/flb_pack.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#define FLB_PACK_JSON_DATE_ISO8601 1
#define FLB_PACK_JSON_DATE_EPOCH 2
#define FLB_PACK_JSON_DATE_JAVA_SQL_TIMESTAMP 3
#define FLB_PACK_JSON_DATE_EPOCH_MS 4

/* Specific ISO8601 format */
#define FLB_PACK_JSON_DATE_ISO8601_FMT "%Y-%m-%dT%H:%M:%S"
Expand Down
1 change: 1 addition & 0 deletions include/fluent-bit/flb_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ int flb_time_get(struct flb_time *tm);
int flb_time_msleep(uint32_t ms);
double flb_time_to_double(struct flb_time *tm);
uint64_t flb_time_to_nanosec(struct flb_time *tm);
uint64_t flb_time_to_millisec(struct flb_time *tm);
int flb_time_add(struct flb_time *base, struct flb_time *duration,
struct flb_time *result);
int flb_time_diff(struct flb_time *time1,
Expand Down
8 changes: 8 additions & 0 deletions src/flb_pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,11 @@ int flb_pack_to_json_date_type(const char *str)
else if (strcasecmp(str, "epoch") == 0) {
return FLB_PACK_JSON_DATE_EPOCH;
}
else if (strcasecmp(str, "epoch_ms") == 0 ||
strcasecmp(str, "epoch_millis") == 0 ||
strcasecmp(str, "epoch_milliseconds") == 0) {
return FLB_PACK_JSON_DATE_EPOCH_MS;
}

return -1;
}
Expand Down Expand Up @@ -986,6 +991,9 @@ flb_sds_t flb_pack_msgpack_to_json_format(const char *data, uint64_t bytes,
case FLB_PACK_JSON_DATE_EPOCH:
msgpack_pack_uint64(&tmp_pck, (long long unsigned)(tms.tm.tv_sec));
break;
case FLB_PACK_JSON_DATE_EPOCH_MS:
msgpack_pack_uint64(&tmp_pck, flb_time_to_millisec(&tms));
break;
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/flb_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ uint64_t flb_time_to_nanosec(struct flb_time *tm)
return (((uint64_t)tm->tm.tv_sec * 1000000000L) + tm->tm.tv_nsec);
}

uint64_t flb_time_to_millisec(struct flb_time *tm)
{
return (((uint64_t)tm->tm.tv_sec * 1000L) + tm->tm.tv_nsec / 1000000L);
}

int flb_time_add(struct flb_time *base, struct flb_time *duration, struct flb_time *result)
{
if (base == NULL || duration == NULL|| result == NULL) {
Expand Down

0 comments on commit 5144312

Please sign in to comment.