logstash-plugins/logstash-filter-xml

Target is required value as xml_store is default to true

purbon opened this issue · 3 comments

According to documentation:

 # XML in the value of the source field will be expanded into a
  # datastructure in the `target` field.
  # Note: if the `target` field already exists, it will be overridden.
  # Required if `store_xml` is true (which is the default).

https://github.com/logstash-plugins/logstash-filter-xml/blob/master/lib/logstash/filters/xml.rb#L40

what makes this field required, but is not like this in the documentation causing probably many unknown errors until this is discovered.

Easy fix would be to just make the target field required.

Easy fix would be to just make the target field required.

But... then people would have to set the target option even if they disable store_xml and the target option's value is unused. Is that really better than the current situation where users get a concrete and descriptive error message if they screw up the configuration?

mut3 commented

Just ran into this issue today. Tried to set an xml filter with only a source field. A concrete and descriptive error message seems to be raised here:

def register
    require "nokogiri"
    require "xmlsimple"

    if @store_xml && (!@target || @target.empty?)
      raise LogStash::ConfigurationError, I18n.t(
        "logstash.runner.configuration.invalid_plugin_register",
        :plugin => "filter",
        :type => "xml",
        :error => "When the 'store_xml' configuration option is true, 'target' must also be set"
      )
    end
  end

But this error does not actually make it to the end user, at least in my case, here's what I got:

Pipeline aborted due to error {:exception=>"LogStash::ConfigurationError", :backtrace=>["/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-filter-xml-2.2.0/lib/logstash/filters/xml.rb:106:in `register'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.4.0-java/lib/logstash/pipeline.rb:182:in `start_workers'", "org/jruby/RubyArray.java:1613:in `each'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.4.0-java/lib/logstash/pipeline.rb:182:in `start_workers'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.4.0-java/lib/logstash/pipeline.rb:136:in `run'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.4.0-java/lib/logstash/agent.rb:491:in `start_pipeline'"], :level=>:error}

Actually receiving this error and/or more clearly stated documentation would solve a lot of headaches.

I found this open issue because after some extensive googling I could not find why my XML was failing so I went and looked at the register block in the xml filter code.

@mut3, your bad experience is due to a bug in Logstash 2.4.0 that was fixed in 2.4.1 and 5.x (although in different ways). See elastic/logstash#6011 for the fix that went into 2.4.1.