fluentd-plugin-mdsd
fluentd-plugin-mdsd copied to clipboard
Timestamp sub-second resolution is lost in the to_msgpack
Sub-second resolution is supported after fluentd v0.14. However, the to_msgpack will only keep the unix second.
https://github.com/Azure/fluentd-plugin-mdsd/blob/9bacb00a722a6a27e44751652918c6262515184a/src/fluent-plugin-mdsd/lib/fluent/plugin/out_mdsd.rb#L72
A workaround is to us to_msgpack_ext to serialize the time.
[tag, time.to_msgpack_ext, record].to_msgpack
And de-serialize it in the emit.
def write(chunk)
if use_source_timestamp
chunk.msgpack_each {|(tag, time, record)|
# Ruby (version >= 1.9) hash preserves insertion order. So the following item is
# the last item when iterating the 'record' hash.
record[emit_timestamp_name] = Time.at(Fluent::EventTime.from_msgpack_ext(time).to_r)
handle_record(tag, record)
}
else
chunk.msgpack_each {|(tag, record)|
record[emit_timestamp_name] = Time.now
handle_record(tag, record)
}
end
@log.flush
end
@robbiezhang This example will not work since there is no Fluent::EventTime
module in min supported version of fluentd (0.12)
Wonder if there's any update about this thread? The MDSD Fluentd plugin still seems to have the sub second precision issue.