y-ken / fluent-plugin-geoip

Fluentd output plugin to geolocate with geoip.
http://rubygems.org/gems/fluent-plugin-geoip
Other
103 stars 23 forks source link

Filtering error on empty IP field #89

Closed tommiv closed 4 years ago

tommiv commented 4 years ago

Problem

It looks like if the geoip_lookup_keys key => value is present, but equals an empty string, the plugins throws an exception. This break further fluentd filters chain processing and therefore the record is just thrown away.

Steps to replicate

Just try to ingest such a record:

{"log.real_ip": ""}

with this config:

<filter infra.nginx.access.*>
  @type geoip
  geoip_lookup_keys log.real_ip
  backend_library geoip2_c
  skip_adding_null_record true
  @log_level info
  <record>
    geo.code  ${country.iso_code["log.real_ip"]}
    geo.name  ${country.names.en["log.real_ip"]}
    geo.city  ${city.names.en["log.real_ip"]}
    geo.point '[${location.longitude["log.real_ip"]},${location.latitude["log.real_ip"]}]'
  </record>
</filter>

I get this error: {"error":"#<GeoIP2::Error: getaddrinfo failed: Name or service not known>","location":"/opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/fluent-plugin-geoip-1.3.1/lib/fluent/plugin/filter_geoip.rb:175:inlookup'" ...`

Expected Behavior

The plugin should leave the record unmodified.

Your environment

okkez commented 4 years ago

The following configuration will generate the below results:

  <source>
    @type dummy
    @id dummy
    dummy [{"host":"","message":"this is test message"}]
    tag "dummy"
  </source>
  <filter dummy>
    @type geoip
    backend_library geoip2_c
    geoip_lookup_keys host
    <record>
      geoip_city ${city.names.en["host"]}
    </record>
  </filter>
  <match dummy>
    @type stdout
  </match>

Current behavior:

2020-05-30 21:55:27 +0900 [warn]: #0 dump an error event: error_class=GeoIP2::Error error="getaddrinfo failed: Name or service not known" location="/home/kenji/wc/src/github.com/y-ken/fluent-plugin-geoip/lib/fluent/plugin/filter_geoip.rb:175:in `lookup'" tag="dummy" time=2020-05-30 21:55:27.072298297 +0900 record={"host"=>"", "message"=>"this is test message"}
2020-05-30 21:55:27.072298297 +0900 dummy: {"host":"","message":"this is test message"}

The above result did not add any fields to record.

91 behavior:

2020-05-30 21:57:42 +0900 [warn]: #0 host is empty string
2020-05-30 21:57:42.065259460 +0900 dummy: {"host":"","message":"this is test message","geoip_city":null}

The above result added geoip_city field specified in the configuration.