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

reader: add new reader dirx #613

Merged
merged 1 commit into from
Jul 23, 2018
Merged

reader: add new reader dirx #613

merged 1 commit into from
Jul 23, 2018

Conversation

unknwon
Copy link
Contributor

@unknwon unknwon commented Jul 18, 2018

JIRA: https://jira.qiniu.io/browse/PDR-6301

  1. 添加 dirx reader
  2. 定义 DaemonReader 接口用于需要守护线程的 reader

@unknwon unknwon changed the title [WIP] reader: add new reader dirx reader: add new reader dirx Jul 19, 2018
@@ -177,6 +178,7 @@ var (
{ModeDir, "logkit会在启动时根据文件夹下文件时间顺序依次读取文件,当读到时间最新的文件时会不断读取追加的数据,直到该文件夹下出现新的文件。该模式的经典日志存储方式为整个文件夹下存储业务日志,文件夹下的日志使用统一前缀,后缀为时间戳,根据日志的大小rotate到新的文件。"},
{ModeFile, "logkit会不断读取文件追加的数据。该模式的经典日志存储方式类似于nginx的日志rotate方式,日志名称为固定的名称,如access.log,rotate时直接move成新的文件如access.log.1,新的数据仍然写入到access.log。"},
{ModeTailx, "展开并匹配所有符合表达式的文件,并持续读取所有有数据追加的文件。每隔stat_interval的时间,重新刷新一遍logpath模式串,添加新增的文件。该模式比较灵活,几乎可以读取所有日志更新,需要注意的是,使用tailx模式容易导致文件句柄打开过多。tailx模式的文件重复判断标准为文件名称,若使用rename, copy等方式改变日志名称,并且新的名字在logpath模式串的包含范围内,在read_from为oldest的情况下则会导致重复写入数据。"},
{ModeDirx, "展开并匹配所有符合表达式的目录下的文件,并持续读取所有有数据追加的文件。每隔stat_interval的时间,重新刷新一遍logpath模式串,添加新增的文件。该模式比较灵活,几乎可以读取所有日志更新,需要注意的是,使用dirx模式容易导致文件句柄打开过多。dirx模式的文件重复判断标准为文件名称,若使用rename, copy等方式改变日志名称,并且新的名字在logpath模式串的包含范围内,在read_from为oldest的情况下则会导致重复写入数据。"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个描述是抄的吧,不合适

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

相应位置都改过了的

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

展开并匹配所有符合表达式的目录下的文件,并持续读取目录中新产生的文件,或者最新文件的数据追加。每隔stat_interval的时间,重新刷新一遍logpath模式串,监听新增的文件夹。该模式与tailx最大的区别时底层的实现方式是按文件夹读取(dir),而tailx是按文件读取,同样,使用dirx模式容易导致文件句柄打开过多,当相对于tailx会大大减少。dirx模式监听到文件夹后,会按文件夹内文件的最后更新依次读取,适合文件夹内文件依次滚动产生的场景。如果文件夹内的不同文件都会随时更新,则会导致重复读取,此时请选择tailx。

ToolTip: "最大同时追踪的文件数,默认为256",
},
{
KeyName: KeyStatInterval,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

上面这几个选项有过,合并一下这里用变量把

return nil, err
}

expireDur, _ := conf.GetStringOr(reader.KeyExpire, "24h")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dir的expire时间可以长一点,因为一般文件夹比文件的数量会少很多,默认30天吧

@@ -177,6 +178,7 @@ var (
{ModeDir, "logkit会在启动时根据文件夹下文件时间顺序依次读取文件,当读到时间最新的文件时会不断读取追加的数据,直到该文件夹下出现新的文件。该模式的经典日志存储方式为整个文件夹下存储业务日志,文件夹下的日志使用统一前缀,后缀为时间戳,根据日志的大小rotate到新的文件。"},
{ModeFile, "logkit会不断读取文件追加的数据。该模式的经典日志存储方式类似于nginx的日志rotate方式,日志名称为固定的名称,如access.log,rotate时直接move成新的文件如access.log.1,新的数据仍然写入到access.log。"},
{ModeTailx, "展开并匹配所有符合表达式的文件,并持续读取所有有数据追加的文件。每隔stat_interval的时间,重新刷新一遍logpath模式串,添加新增的文件。该模式比较灵活,几乎可以读取所有日志更新,需要注意的是,使用tailx模式容易导致文件句柄打开过多。tailx模式的文件重复判断标准为文件名称,若使用rename, copy等方式改变日志名称,并且新的名字在logpath模式串的包含范围内,在read_from为oldest的情况下则会导致重复写入数据。"},
{ModeDirx, "展开并匹配所有符合表达式的目录下的文件,并持续读取所有有数据追加的文件。每隔stat_interval的时间,重新刷新一遍logpath模式串,添加新增的文件。该模式比较灵活,几乎可以读取所有日志更新,需要注意的是,使用dirx模式容易导致文件句柄打开过多。dirx模式的文件重复判断标准为文件名称,若使用rename, copy等方式改变日志名称,并且新的名字在logpath模式串的包含范围内,在read_from为oldest的情况下则会导致重复写入数据。"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

展开并匹配所有符合表达式的目录下的文件,并持续读取目录中新产生的文件,或者最新文件的数据追加。每隔stat_interval的时间,重新刷新一遍logpath模式串,监听新增的文件夹。该模式与tailx最大的区别时底层的实现方式是按文件夹读取(dir),而tailx是按文件读取,同样,使用dirx模式容易导致文件句柄打开过多,当相对于tailx会大大减少。dirx模式监听到文件夹后,会按文件夹内文件的最后更新依次读取,适合文件夹内文件依次滚动产生的场景。如果文件夹内的不同文件都会随时更新,则会导致重复读取,此时请选择tailx。

OptionKeyExpire = Option{
KeyName: KeyExpire,
ChooseOnly: false,
Default: "24h",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个不能共用,dirx模式的改为30天

@wonderflow
Copy link
Contributor

LGTM

可以写文档了

@wonderflow wonderflow merged commit f169524 into qiniu:master Jul 23, 2018
@unknwon unknwon deleted the PDR-6301-dirx branch July 23, 2018 09:43
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

Successfully merging this pull request may close these issues.

2 participants