Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateTime::ISO8601 is not fine-grained enough for logs #6

Open
markkimsal opened this issue Dec 6, 2018 · 0 comments
Open

DateTime::ISO8601 is not fine-grained enough for logs #6

markkimsal opened this issue Dec 6, 2018 · 0 comments

Comments

@markkimsal
Copy link

I'm throwing some logs at ES and when I'm viewing them in grafana in the table viewer, some record are out of order because they happen at the same second. ES can handle milliseconds since epoch as a default datetime format.

If I make a change like this:

class ElasticsearchFormatter extends NormalizerFormatter
{
    /**
     * @var string
     */
    private $type;

    /**
     * @var string
     */
    private $index;

    public function __construct($index, $type)
    { 
        parent::__construct('U.u');

        $this->index = $index;
        $this->type = $type;
    } 

    public function format(array $record)
    { 
        $record = parent::format($record);
        $record['datetime'] = (int)round($record['datetime']*1000);

        var_dump(
            $record                                                                                                                                                   
        );
        die();
        return [ 
            'type'      => $this->type,
            'index'     => $this->index,
            'body'      => $record
        ];
    } 

Then I can see that it works and it saves to ES quite readily.

Note that I had to change the Normalizer's date format to 'U.u', and to specifically cast as an int because a float value gets an extra ".0" added to it when it gets converted to JSON.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant