File tailing doesn't work on NFS-mounted files
- Dominant language
- C
- Stars
- 8.1k
- Forks
- 2k
- Avg merge
- 4d 20h
- Merged PRs (30d)
- 71
Description
## Bug Report
**Describe the bug**
When using the `tail` plugin to tail files mounted via NFS, their full content is read once, but then additional lines are not detected.
**To Reproduce**
- Created an Ubuntu 18.04 EC2 instance.
- Installed required NFS packages:
```
sudo apt update && sudo apt install nfs-kernel-server nfs-common
```
- Created folder to be shared via NFS:
```
sudo mkdir /var/nfs/general -p
sudo chown nobody:nogroup /var/nfs/general
```
- Configured the NFS server in `/etc/exports`:
```
/var/nfs/general 172.31.38.100(rw,sync,no_subtree_check)
```
- Restarted NFS server process:
```
sudo systemctl restart nfs-kernel-server
```
- Created "local" directory and mounted the remote NFS directory onto it:
```
sudo mkdir -p /nfstest/general
sudo mount 172.31.38.100:/var/nfs/general /nfstest/general
```
- Compiled Fluent Bit 1.6.3 and started it with the following configuration:
```
[INPUT]
Name tail
Path /var/nfs/general/testfile.log
Tag local
DB /home/ubuntu/fb.db
[INPUT]
Name tail
Path /nfstest/general/testfile.log
Tag nfs
DB /home/ubuntu/fb.db
[FILTER]
Name record_modifier
Match local
Record source local
[FILTER]
Name record_modifier
Match nfs
Record source nfs
[OUTPUT]
Name stdout
Match *
```
- At this point, the `testfile.log` didn't exist yet. I added a couple of lines:
```
echo "test" | sudo tee -a /var/nfs/general/testfile.log
echo "test2" | sudo tee -a /var/nfs/general/testfile.log
```
- At this point, the file was detected by Fluent Bit and all the contents were read:
```
[2021/02/23 17:46:15] [ info] [input:tail:tail.0] inotify_fs_add(): inode=256347 watch_fd=1 name=/var/nfs/general/testfile.log
[2021/02/23 17:46:15] [ info] [input:tail:tail.1] inotify_fs_add(): inode=256347 watch_fd=1 name=/nfstest/general/testfile.log
[0] local: [1614102375.274775905, {"log"=>"test", "source"=>"local"}]
[1] local: [1614102375.274784234, {"log"=>"test2", "source"=>"local"}]
[0] nfs: [1614102375.274967561, {"log"=>"test", "source"=>"nfs"}]
[1] nfs: [1614102375.274969523, {"log"=>"test2", "source"=>"nfs"}]
```
- I appended a couple of additional lines to the file:
```
echo "test3" | sudo tee -a /var/nfs/general/testfile.log
echo "test4" | sudo tee -a /var/nfs/general/testfile.log
```
- But they were only picked up by the "local" tail process:
```
[0] local: [1614102392.972660467, {"log"=>"test3", "source"=>"local"}]
[0] local: [1614102423.664101011, {"log"=>"test4", "source"=>"local"}]
```
- I restarted FluentBit and sent an additional line:
```
echo "test5" | sudo tee -a /var/nfs/general/testfile.log
```
- And again, it was only picked by the "local" tail process:
```
[2021/02/23 17:47:43] [ info] [input:tail:tail.0] inotify_fs_add(): inode=256347 watch_fd=1 name=/var/nfs/general/testfile.log
[2021/02/23 17:47:43] [ info] [input:tail:tail.1] inotify_fs_add(): inode=256347 watch_fd=1 name=/nfstest/general/testfile.log
[0] local: [1614102484.487772957, {"log"=>"test5", "source"=>"local"}]
```
**Expected behavior**
Lines appended to a file mounted via NFS should be tailed correctly, as if it were a local file.
**Screenshots**

**Your Environment**
* Version used: 1.6.3
* Configuration: provided above
* Environment name and version: AWS EC2
* Server type and version: `t2.micro` EC2 instance
* Operating System and version: Ubuntu Server 18.04 LTS (HVM), SSD Volume Type (EC2 instance)
* Filters and plugins: `tail`, `record_modifier`, `stdout`
**Additional context**
N/A
Contributor guide
Assessment
This issue has not been assessed yet.