Skip to content

Timestamp sub-second resolution is lost in the to_msgpack #63

Description

Sub-second resolution is supported after fluentd v0.14. However, the to_msgpack will only keep the unix second.

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions