Git Product home page Git Product logo

fluent-plugin-elasticsearch-timestamp-check's Introduction

fluent-plugin-elasticsearch-timestamp-check

Fluent plugin to ensure @timestamp is in correct format for elasticsearch

Install

gem install fluent-plugin-elasticsearch-timestamp-check

Description

The purpose of this filter is to make sure the @timestamp field exists in the record which is necessary for the record to be indexed properly by elasticsearch.

  • If @timestamp field already exists, it will ensure the format is correct by parse and convert to format '%Y-%m-%dT%H:%M:%S%z'. As of version 0.2.4, it will support epoch second / epoch millis format as a valid timestamp value. If such value is detected, it will be converted to iso8601 format for easier consumption of elasticsearch when dynamic mapping is used.

  • By default, it will check whether fields named timestamp, time, or syslog_timestamp exists, if so it will parse that field and conver it to format '%Y-%m-%dT%H:%M:%S.%L%z' then store it in @timestamp field. In addition, a field fluent_converted_timestamp is added to the object with the same value.

  • (>=0.3.0) the list of fields can be overriden by setting the timestamp_fields parameter. It accepts a list of strings, the default is set to: ['@timestamp', 'timestamp', 'time', 'syslog_timestamp']

  • If none of the above field exists, it will insert current event time in '%Y-%m-%dT%H:%M:%S.%L%z' format as the @timestamp field. A field fluent_added_timestamp is added to the object with same value.

(>=0.2.6) Subsecond Precision

subsecond_precision controls the subsecond precision during the conversion. Default value is set to 3 (millisecond).

Other subsecond_precision sample values are:

  • 6 (microsecond)
  • 9 (nanosecond)
  • 12 (picosecond)

and more high precision is also supported.

Usage

<filter **>
  type elasticsearch_timestamp_check
  subsecond_precision 3
</filter>

fluent-plugin-elasticsearch-timestamp-check's People

Contributors

cosmo0920 avatar ecwws avatar richard-li-sp avatar tsotnikov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

fluent-plugin-elasticsearch-timestamp-check's Issues

Use Time.at(time) instead of Time.now for fallback

I'm curious why not use Time.at(time) in the fallback option instead of Time.now, here

AFAIU, every event that is ingested in fluntd has an internal time key, either extracted from the event record (using formatting/parsing) or by using the time when it was ingested, since the event can travel through the pipeline, by the time it reaches this plugin Time.now doesn't represent the actual ingestion time of the event.

Any thoughts? @ecwws @cosmo0920

[Improve] epoch_millis and epoch_second support

Hello, ecwws, thanks for this plugin.

Elasticsearch support:

epoch_millis
A formatter for the number of milliseconds since the epoch. Note, that this timestamp is subject to the limits of a Java Long.MIN_VALUE and Long.MAX_VALUE.
epoch_second
A formatter for the number of seconds since the epoch. Note, that this timestamp is subject to the limits of a Java Long.MIN_VALUE and Long. MAX_VALUE divided by 1000 (the number of milliseconds in a second).

And I checked source code, DateTime.parse only support from datetime string to DateTime, not support timestamp(epoch_millis/epoch_second).

How about add epoch_millis and epoch_second support?

Not working with fluentd 1.7

error_class=Fluent::ConfigError error=Unknown output plugin 'elasticsearch_timestamp_check'

sudo gem install fluent-plugin-elasticsearch-timestamp-check

<match pre.**>
  type elasticsearch_timestamp_check
</match>

(also tried new syntax @type)

Support nanosecond (epoch nano) timestamp

Since fluentd supports nanosecond timestamp, could we extend this plugin to support epoch nano as well?

We have one source that currently set timestamp field to epoch nano, so at the moment we need to do a transformation to millisecs, would be nice if the plugin supported it out-of-the-box.

NameError when using fallback timestamp logic

I'm observing that some events are not processed correctly due to a log statement issue.

Given an event like:

{
  "timestamp": "10/Aug/2021:22:48:47 +0000",
  "access": "GET / HTTP/1.1 200",
  "type": "access"
}

(that is, not using the "normal timestamp processing" but instead the secondary/backup parsing)

The result is an error such as:

2021-08-10 22:48:52 +0000 [warn]: #0 dump an error event: error_class=NameError error="undefined local variable or method `field' for #<Fluent::Plugin::ElasticsearchTimestampCheckFilter:0x00007f1780cc19a8>\nDid you mean?  yield" location="/usr/local/bundle/gems/fluent-plugin-elasticsearch-timestamp-check-0.3.0/lib/fluent/plugin/filter_elasticsearch_timestamp_check.rb:62:in `rescue in block in filter'" tag="docker.var.lib.docker.containers.83e55d29166ac414218614dda4e51e0409d9844e0629d50128edbb5e3bc6c9d7.83e55d29166ac414218614dda4e51e0409d9844e0629d50128edbb5e3bc6c9d7-json.log" time=2021-08-10 

22:48:52.731255982 +0000 record={"timestamp"=>"10/Aug/2021:22:48:47 +0000", "access"=>"GET / HTTP/1.1 200"}

It seems like the issue is that field is out of scope at this line (but I don't know Ruby..):

$log.debug("#{field} (#{timestamp}) failed to parse, trying next")

Fluent added timestamp truncated to seconds

In the case @timestamp (and fluent_added_timestamp) is added from fluentd event time, the timestamp is truncated to seconds.

The cause is the conversion of the time to an integer (Fluent::EventTime - to_int)

Time.at(time.is_a?(Fluent::EventTime) ? time.to_int : time).strftime(@strftime_format)

(It is the same issue as #15 but it was not described good enough)

Proposed solution

Use to_r method instead (Fluent::EventTime - to_r which converts it in a Time object ready to use with Time.at

Don't work

Hey i added conf in following way but i still don't have value in milliseconds.

<filter **>
  type elasticsearch_timestamp_check
  subsecond_precision 3
</filter>

@timestamp |   | October 1st 2020, 11:48:23.000
fluent_added_timestamp |   | October 1st 2020, 11:48:23.000

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.