Skip to content

Commit

Permalink
Added log of ECS enabled while 'target' option is not specified expli…
Browse files Browse the repository at this point in the history
…citly for logstash-filter-jdbc_static
  • Loading branch information
andsel committed May 24, 2021
1 parent c1b91e2 commit bb023d0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/logstash/filters/jdbc/lookup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ def initialize(options, globals, default_id)
@target = options["target"]
@id_used_as_target = @target.nil?
if @id_used_as_target
# target shouldn't be nil if ecs_compatibility is not :disabled
if globals[:ecs_compatibility] != :disabled
logger.info("When ECS compatibility is enabled also target option must be valued")
end
@target = @id
end
@options = options
Expand Down
5 changes: 5 additions & 0 deletions lib/logstash/filters/jdbc_static.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require "logstash-integration-jdbc_jars"
require "logstash/filters/base"
require "logstash/namespace"
require "logstash/plugin_mixins/ecs_compatibility_support"
require_relative "jdbc/loader"
require_relative "jdbc/loader_schedule"
require_relative "jdbc/repeating_load_runner"
Expand All @@ -14,6 +15,9 @@

#
module LogStash module Filters class JdbcStatic < LogStash::Filters::Base
# adds ecs_compatibility config which could be :disabled or :v1
include LogStash::PluginMixins::ECSCompatibilitySupport(:disabled, :v1)

config_name "jdbc_static"

# Define the loaders, an Array of Hashes, to fetch remote data and create local tables.
Expand Down Expand Up @@ -214,6 +218,7 @@ def global_lookup_options(options = Hash.new)
options["lookup_jdbc_driver_class"] = @lookup_jdbc_driver_class
options["lookup_jdbc_driver_library"] = @lookup_jdbc_driver_library
options["lookup_jdbc_connection_string"] = @lookup_jdbc_connection_string
options["ecs_compatibility"] = @ecs_compatibility
options
end

Expand Down
31 changes: 31 additions & 0 deletions spec/filters/jdbc/lookup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,37 @@ module LogStash module Filters module Jdbc
expect(subject.valid?).to be_falsey
end
end

describe "validation of target option" do
let(:lookup_hash) do
{
"query" => "select * from servers WHERE ip LIKE ? AND os LIKE ?",
"prepared_parameters" => ["%%{[ip]}"],
}
end

it "should log a warn when ECS is enabled and target not defined" do

class LoggableLookup < Lookup

@@TEST_LOGGER = nil

def self.logger=(log)
@@TEST_LOGGER = log
end

def self.logger
@@TEST_LOGGER
end
end

spy_logger = double("logger")
expect(spy_logger).to receive(:info).once.with("When ECS compatibility is enabled also target option must be valued")
LoggableLookup.logger = spy_logger

LoggableLookup.new(lookup_hash, {:ecs_compatibility => 'v1'}, "lookup-1")
end
end
end
end end end

0 comments on commit bb023d0

Please sign in to comment.