fluentd-plugin-mdsd icon indicating copy to clipboard operation
fluentd-plugin-mdsd copied to clipboard

Timestamp sub-second resolution is lost in the to_msgpack

Open robbiezhang opened this issue 6 years ago • 2 comments

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 avatar Feb 22 '19 02:02 robbiezhang

@robbiezhang This example will not work since there is no Fluent::EventTime module in min supported version of fluentd (0.12)

fatal10110 avatar Mar 31 '19 10:03 fatal10110

Wonder if there's any update about this thread? The MDSD Fluentd plugin still seems to have the sub second precision issue.

kenans avatar Jul 27 '21 08:07 kenans