# Filebeats records skipped and out of order

**URL:** https://discuss.elastic.co/t/filebeats-records-skipped-and-out-of-order/131992
**Category:** Beats
**Tags:** filebeat
**Created:** [May 15, 2018, 7:24pm UTC](https://discuss.elastic.co/t/filebeats-records-skipped-and-out-of-order/131992 "2018-05-15T19:24:35Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![pgf](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pgf/32/47996_2.png) [@pgf](https://discuss.elastic.co/u/pgf)
#### Post date: [May 15, 2018, 7:24pm UTC](https://discuss.elastic.co/t/filebeats-records-skipped-and-out-of-order/131992/1 "2018-05-15T19:24:35Z")

</div>

Hi, I am very new to this but I am trying to create what I thought was a very simple filberts configuration. The file I am reading is not a "normal" log file with timestamps and formatted fields. The first few lines look like:  
Reverse date time = 621170805  
Sequence number = 2147483952  
Component = SNSS1  
Security event = FALSE  
Event number = 4101  
Event name = ARG Information  
Event class = Software  
Event severity = Info

My config is pretty simple:  
- type: log  
enabled: true  
paths:  
- D:\testdata\*

Watching my log stash logs I see it skip the first few lines in the file every time... not always the same number of lines either. I threw together a test input file:  
Line 1  
Line 2  
Line 3  
Line 4  
And logstash said:  
Line 2  
Line 1  
Line3

So I added to the file:  
Line 5  
Line 6

And got in logstash:  
Line 4  
Line 5

I am very confused about what is going on here.

---

<div class="post-metadata">

### Author: ![pierhugues](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pierhugues/32/48383_2.png) [@pierhugues](https://discuss.elastic.co/u/pierhugues)
#### Post date: [May 16, 2018, 2:40pm UTC](https://discuss.elastic.co/t/filebeats-records-skipped-and-out-of-order/131992/2 "2018-05-16T14:40:29Z")

</div>

I think what you are experiencing is correct, but not what you are expecting.

First, let me clarify how Filebeat works.

When Filebeat read a file, it tracks lines, for Filebeat a line must end with `\n` when you hit enter you are adding that invisible character when the line doesn't contain that character Filebeat is considering it as incomplete and wont attempt to read it. All Log libraries will always append that newline when a log statement is complete.

Since you are editing the file manually, this is why you never see the last line that because it doesn't contain the newline character, and for Filebeat that line is incomplete.

---

<div class="post-metadata">

### Author: ![pgf](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pgf/32/47996_2.png) [@pgf](https://discuss.elastic.co/u/pgf)
#### Post date: [May 16, 2018, 2:42pm UTC](https://discuss.elastic.co/t/filebeats-records-skipped-and-out-of-order/131992/3 "2018-05-16T14:42:10Z")

</div>

Ok. I'll buy that pending testing. It sounds reasonable. What about the out of sequence lines and the fact that some are missed? In my original file it was the first three or four lines that were always missed.

---

<div class="post-metadata">

### Author: ![pierhugues](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pierhugues/32/48383_2.png) [@pierhugues](https://discuss.elastic.co/u/pierhugues)
#### Post date: [May 16, 2018, 3:00pm UTC](https://discuss.elastic.co/t/filebeats-records-skipped-and-out-of-order/131992/4 "2018-05-16T15:00:58Z")

</div>

> Watching my log stash logs I see it skip the first few lines in the file every time... not always the same number of lines either. I threw together a test input file:

It should read all the lines, from your examples I only see the last line skipped?  
Are you always editing the same file on disk? Because we track the read offset on disk in a registry file (data/registry).

> sequence lines

There are few things to take into consideration when considering sequence or order of events.

1. Filebeat is reading the file in order.
2. Filebeat is sending the events to Logstash in multiple batches.
3. Events are sent to a queue inside Logstash
4. Logstash by default is starting with multiple workers pickup up events from the queue. The number of worker default to the number of cores of the machine.

When you are at point 4, the ordering is not guaranteed due to the nature of asynchronous worker.  
In some cases, you can achieve ordering by configuring Logstash only to have 1 worker (see [pipeline.workers](https://www.elastic.co/guide/en/logstash/current/logstash-settings-file.html)), However, this is drastically affecting performance, and I do not recommend it.

What is your use case to require ordering?

---

<div class="post-metadata">

### Author: ![pgf](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pgf/32/47996_2.png) [@pgf](https://discuss.elastic.co/u/pgf)
#### Post date: [May 16, 2018, 3:04pm UTC](https://discuss.elastic.co/t/filebeats-records-skipped-and-out-of-order/131992/5 "2018-05-16T15:04:28Z")

</div>

I do expect the ordering to remain intact. I will sanitize my original file and publish it. What I noticed first was that only the middle of the file was being transmitted (apparently). The first and last few lines were always missing.

---

<div class="post-metadata">

### Author: ![pierhugues](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pierhugues/32/48383_2.png) [@pierhugues](https://discuss.elastic.co/u/pierhugues)
#### Post date: [May 16, 2018, 3:11pm UTC](https://discuss.elastic.co/t/filebeats-records-skipped-and-out-of-order/131992/6 "2018-05-16T15:11:12Z")

</div>

> [@pgf](#):
>
> I do expect the ordering to remain intact.

In that case configuring `logstash worker to 1`, should work but will make things slower and increasing the risk of blocking the pipeline.

We don't have nanosecond precision yet, if we have maybe using the generated timestamp could solve your case.

---

<div class="post-metadata">

### Author: ![pgf](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pgf/32/47996_2.png) [@pgf](https://discuss.elastic.co/u/pgf)
#### Post date: [May 16, 2018, 3:12pm UTC](https://discuss.elastic.co/t/filebeats-records-skipped-and-out-of-order/131992/7 "2018-05-16T15:12:03Z")

</div>

Ah! That makes perfect sense. Thanks Pier.

---

<div class="post-metadata">

### Author: ![pgf](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pgf/32/47996_2.png) [@pgf](https://discuss.elastic.co/u/pgf)
#### Post date: [May 16, 2018, 4:42pm UTC](https://discuss.elastic.co/t/filebeats-records-skipped-and-out-of-order/131992/8 "2018-05-16T16:42:55Z")

</div>

This certainly solved the sequencing problem, although, as you say, there are potential performance implications. I can design around that for now. Thanks Pier.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [June 13, 2018, 6:42pm UTC](https://discuss.elastic.co/t/filebeats-records-skipped-and-out-of-order/131992/9 "2018-06-13T18:42:58Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
