Skip to content

Commit b8272c4

Browse files
author
yewei
committed
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
1 parent 0be1ffb commit b8272c4

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

output/decoder.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package output
2020
import (
2121
"C"
2222
"encoding/binary"
23+
"math"
2324
"reflect"
2425
"time"
2526
"unsafe"
@@ -82,7 +83,17 @@ func GetRecord(dec *FLBDecoder) (ret int, ts interface{}, rec map[interface{}]in
8283
return -2, 0, nil
8384
}
8485

85-
t := slice.Index(0).Interface()
86+
var t interface{}
87+
switch ts := slice.Index(0).Interface().(type) {
88+
case uint64:
89+
t = FLBTime{time.Unix(int64(ts), 0)}
90+
case float64:
91+
secs, frac := math.Modf(ts)
92+
t = FLBTime{time.Unix(int64(secs), int64(frac*1000_000_000))}
93+
default:
94+
t = ts
95+
}
96+
8697
data := slice.Index(1)
8798

8899
map_data := data.Interface().(map[interface{}]interface{})

0 commit comments

Comments
 (0)