Skip to content

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

@robbiezhang

Description

@robbiezhang

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions