logstash-plugins / logstash-filter-translate

Translate filter for Logstash
Apache License 2.0
21 stars 47 forks source link

Refactor: reading .csv for JRuby 9.3 compatibility #94

Closed kares closed 2 years ago

kares commented 2 years ago

NOTE: these changes are essential for the plugin to work properly under Logstash 8.3 and later. :red_circle: CI prior to this PR: https://app.travis-ci.com/github/logstash-plugins/logstash-filter-translate/builds/251684358


the code we had seem to have relied on internals - with changing the io object underneath the CSV:

      @csv = ::CSV.new(@io = StringIO.new)

      IO.foreach(@dictionary_path, :mode => 'r:bom|utf-8') do |line|
        @io.string = line
        k,v = @csv.readline # working in 9.2, in 9.3 only the first line is read
        @dictionary[k] = v

in JRuby 9.3 (which updated CSV library to 3.1.2) a state is kept and the @io is not read since start.

we could have done a rewind but this code seemed fragile and the csv.rewind resets a lot of it's state, thus refactored to an API usage that is more in-line with how the library is meant to be used.


      # low level CSV read that tries to create as
      # few intermediate objects as possible
      # this overwrites the value at key

following up on the updated CSV code I do not see how it would generate more objects, as far as checked.