From 16c79af4bdc8e96a9a10b5d83f85d5315bf1f8a1 Mon Sep 17 00:00:00 2001 From: yewei Date: Thu, 24 Feb 2022 15:25:07 +0800 Subject: [PATCH] Make the beheavior of getting record time same with the C code `flb_time_msgpack_to_time` See: https://github.com/fluent/fluent-bit/blob/v1.8.12/src/flb_time.c#L198-L223 Signed-off-by: yewei --- output/decoder.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/output/decoder.go b/output/decoder.go index faf9595..3e649ee 100644 --- a/output/decoder.go +++ b/output/decoder.go @@ -20,6 +20,7 @@ package output import ( "C" "encoding/binary" + "math" "reflect" "time" "unsafe" @@ -82,7 +83,17 @@ func GetRecord(dec *FLBDecoder) (ret int, ts interface{}, rec map[interface{}]in return -2, 0, nil } - t := slice.Index(0).Interface() + var t interface{} + switch ts := slice.Index(0).Interface().(type) { + case uint64: + t = FLBTime{time.Unix(int64(ts), 0)} + case float64: + secs, frac := math.Modf(ts) + t = FLBTime{time.Unix(int64(secs), int64(frac*1000_000_000))} + default: + t = ts + } + data := slice.Index(1) map_data := data.Interface().(map[interface{}]interface{})