环境
ES版本:8.5.3
FileBeat版本:8.5.3
需求: 因工作需要,需将采集到ES中的日志,进行规范化清洗。pipeline设置如下:
PUT _ingest/pipeline/demo_pipeline
{
"description": "demo",
"processors": [
{
"grok": {
"field": "message",
"patterns": [
"%{GREEDYDATA:extra}\\[%{GREEDYDATA:traceId}\\] \\[%{TIMESTAMP_ISO8601:timestamp}\\] \\[%{GREEDYDATA:thread}\\] %{GREEDYDATA:extra}\\[%{GREEDYDATA:level}\\] %{GREEDYDATA:class} - %{GREEDYDATA:request}"
]
}
},
{
"json": {
"field": "request",
"target_field": "json",
"if": "ctx.request.startsWith('{')"
}
},
{
"script": {
"lang": "painless",
"source": "if (ctx['json'] != null){ctx['uri'] = ctx['json']['uri'];ctx['url'] = ctx['json']['url'];}"
}
},
{
"remove": {
"field": "json"
}
}
]
}
因有一个需求是需要统计接口在一段时间的请求次数,项目中的以做好日志输出到request中,所以需要json转化组件。也就是以上代码中的json模块;后将json中有用的url(接口链路)、uri(接口全链路)的信息使用scripts的painless脚本进行拆分;最后觉得转化后的json串冗余了,做了删除。
但是就是这个remove模块导致很大的坑。添加后,使用以下方式进行调试:
POST _ingest/pipeline/demo_pipeline/_simulate
却报错:
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "field [json] not present as part of path [json]"
}
],
"type": "illegal_argument_exception",
"reason": "field [json] not present as part of path [json]"
}
}
使得json转化失败的数据被丢弃,得到的数据量远小于实际数据量。
刚开始怀疑是processor执行顺序的问题,但是看到一些帖子说,会按照配置文件中定义的processor顺序执行,因此
现在问题原因未解决,只是移除了remove模块。特此记录问题。