Timestamp type assertion fails on darwin
I ran my test suite for my plugin on macOS. The one thing that it had a problem with was type asserting the timestamp. I used this code from the gstdout example:
flbTime := ts.(output.FLBTime)
This caused the plugin to panic:
panic: interface conversion: interface {} is uint64, not output.FLBTime
goroutine 17 [running, locked to thread]:
main.FLBPluginFlush(0x7fb67180f000, 0xc40000001d, 0x7fb670602270, 0xc42005ced8)
/Users/pivotal/workspace/foo/src/github.com/oratos/out_syslog/cmd/main.go:51 +0x25d
main._cgoexpwrap_44e740a65504_FLBPluginFlush(0x7fb67180f000, 0x1d, 0x7fb670602270, 0x0)
_cgo_gotypes.go:82 +0x3d
Easy workaround was to just do:
var timestamp time.Time
flbTime, ok := ts.(output.FLBTime)
if ok {
timestamp = flbTime.Time
} else {
timestamp = time.Now()
}
If I can get a useful timestamp out of the uint64 I would prefer that.
I ran into this issue today while using https://github.com/fluent/fluent-logger-golang
The timestamps for the messages it emits into fluent-bit are interpreted as uint64 when handed off to the go output plugin. I discovered this uint64 is apparently unix seconds. Negative values were not allowed by fluent-logger-golang.
I will look into this further. I think at the very least fluent-bit should convert the uint64 into an output.FLBTime before handing it off to the output plugin.
I believe the way it works is that when timestamp is available in the log record it is passed on to the plugin as FLBTime. On the other when timestamp is not available I believe FB provides current time as Unix time using uint64.
It would be great if FB always used one type in all cases, preferably regular Go time.Time struct.