Logstash类型转换在单个mutate过滤器中不起作用

时间:2017-07-25 11:28:14

标签: filter logstash mutate

下面是我的mutate过滤器配置,其中caller和callee数据的格式如下。它不起作用,因为类型转换时调用者和被调用者数据都设置为0。当我使用单独的mutate过滤器进行类型转换时,转换工作正常。为什么我的第一个配置不起作用?

"caller":"caller:123"
"callee":"callee:123"

mutate {
          gsub => [
                   #regex to remove : and every thing before it 
                   "caller", "^[^:]*:", "",                        
                   "callee","^[^:]*:", ""
                  ]
          convert => { 
                     #type conversion from string to integer 
                       "caller" => "integer"
                       "callee" => "integer"                             
                     }                                              
        }

类型转换工作正常,使用了两个单独的mutate过滤器

      mutate {
              gsub => [
                       #regex to remove : and every thing before it 
                       "caller", "^[^:]*:", "",                        
                       "callee","^[^:]*:", ""
                      ]
       } 

           mutate {
                     convert => { "caller" => "integer"
                                  "callee"=>  "integer" 
                                 } 

                   }    

1 个答案:

答案 0 :(得分:1)

显然,从源代码开始,在gsub操作之前调用convert操作。

https://github.com/logstash-plugins/logstash-filter-mutate/blob/d8936feaa5c7141f96fdfbf1120f23ecdc816275/lib/logstash/filters/mutate.rb#L218

  def filter(event)
    ...
    convert(event) if @convert
    gsub(event) if @gsub