简体   繁体   English

解析器部分的 Fluentd 时间格式不起作用

[英]Fluentd time format in parser section doesn't work

Hi Fluentd Experts and Users!嗨,Fluentd 专家和用户!

I found that Fluentd parser cannot parse my time field in json format.我发现 Fluentd 解析器无法解析我的 json 格式的时间字段。

Frankly, I don't know what the time should look like after going through the parser, because I've never had success with it.坦率地说,我不知道通过解析器后时间应该是什么样子,因为我从来没有成功过。 The configuration I refer to is this link: https://docs.fluentd.org/configuration/parse-section#time-parameters我参考的配置是这个链接: https://docs.fluentd.org/configuration/parse-section#time-parameters

My test case is simple, input is a dummy Json with time field {"hello":"world", "time":"1991-02-19 00:00:00"} .我的测试用例很简单,输入是一个带有时间字段{"hello":"world", "time":"1991-02-19 00:00:00"}的虚拟 Json。

But no matter how I modify the time format, or deliberately write the wrong format of the input time, it will not affect the final output, and the final output seems to just print the time field as a string.但是不管我怎么修改时间格式,或者故意把输入时间的格式写错,都不会影响到最后的output,而且最后的output好像只是把时间字段打印成字符串。

Here is my fluentd config:这是我的流利配置:

<source>
  @type dummy
  dummy {"hello":"world", "time":"1991-02-19 00:00:00"}
  tag sample
  <parse>
    @type json
    time_type string
    time_format "%Y-%m-%dT%H:%M:%S"
    time_key "time"
    keep_time_key true
  </parse>
</source>

<match sample>
  @type stdout
  @id out_stdout
</match>

and the output is: output 是:

2022-04-12 01:44:01.034400852 +0000 sample: {"hello":"world","time":"1991-02-19 00:00:00"}
2022-04-12 01:44:02.035744518 +0000 sample: {"hello":"world","time":"1991-02-19 00:00:00"}
2022-04-12 01:44:03.037178309 +0000 sample: {"hello":"world","time":"1991-02-19 00:00:00"}
2022-04-12 01:44:04.038867836 +0000 sample: {"hello":"world","time":"1991-02-19 00:00:00"}
....

You can see that although there missed a 'T' in the input time field, but there is no error or warning, and the output just send the raw string out.可以看到,虽然输入的时间字段中少了一个'T',但是并没有报错和警告,output 只是将原始字符串发送了出去。

And if I put the 'T' back to the input, the output will get the 'T' back too.如果我将“T”放回输入,output 也会将“T”取回。 The config and output are:配置和 output 是:

<source>
  @type dummy
  dummy {"hello":"world", "time":"1991-02-19T00:00:00"}
  tag sample
  <parse>
    @type json
    time_type string
    time_format "%Y-%m-%dT%H:%M:%S"
    time_key "time"
    keep_time_key true
  </parse>
</source>

<match sample>
  @type stdout
  @id out_stdout
</match>
2022-04-12 01:59:56.026574094 +0000 sample: {"hello":"world","time":"1991-02-19T00:00:00"}
2022-04-12 01:59:57.028190722 +0000 sample: {"hello":"world","time":"1991-02-19T00:00:00"}
2022-04-12 01:59:58.029744904 +0000 sample: {"hello":"world","time":"1991-02-19T00:00:00"}
2022-04-12 01:59:59.031296625 +0000 sample: {"hello":"world","time":"1991-02-19T00:00:00"}
...

So I am very confused, does the time format in fluentd's parser really work?所以我很疑惑,fluentd的解析器中的时间格式真的有用吗? And I'm not sure if this is a Fluentd issue, or Plugin issue, or my configuration is wrong.而且我不确定这是 Fluentd 问题还是插件问题,还是我的配置有误。

Thanks a lot in advance!非常感谢!

The dummy / sample input plugin doesn't support a <parse> section. dummy / sample输入插件不支持<parse>部分。

Just ran fluentd with your configuration and observed these warnings in the logs:只需使用您的配置运行fluentd并在日志中观察到这些警告:

2022-04-12 19:44:56 +0500 [warn]: section <parse> is not used in <source> of sample plugin
2022-04-12 19:44:56 +0500 [warn]: section <parse> is not used in <source> of sample plugin
2022-04-12 19:44:56 +0500 [warn]: section <parse> is not used in <source> of sample plugin
2022-04-12 19:44:56 +0500 [warn]: section <parse> is not used in <source> of sample plugin
2022-04-12 19:44:56 +0500 [warn]: section <parse> is not used in <source> of sample plugin

Instead, you might want to add the <filter> section with type parser configured for json format.相反,您可能想要添加<filter>部分,其中类型解析器配置为json格式。

You should always check the logs for any issues.您应该始终检查日志是否有任何问题。 In addition, you can turn on debug logs with -v flag or trace logs with -vv flag.此外,您可以使用-v标志打开调试日志或使用-vv标志打开跟踪日志。

The --dry-run flag to pretty handly to validate the configuration file eg: --dry-run标志非常方便地验证配置文件,例如:

fluentd -c fluent.conf --dry-run

fluentd --help will give you the complete list of available flags. fluentd --help将为您提供可用标志的完整列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM