class LogStash::PluginMixins::Jdbc::CheckedCountLogger

Public Class Methods

new(logger) click to toggle source
# File lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb, line 5
def initialize(logger)
  @logger = logger
  @needs_check = true
  @count_is_supported = false
  @in_debug = @logger.debug?
end

Public Instance Methods

check_count_query(query) click to toggle source
# File lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb, line 27
def check_count_query(query)
  @needs_check = false
  begin
    execute_count(query)
    @count_is_supported = true
  rescue Exception => e
    @logger.warn("Attempting a count query raised an error, the generated count statement is most likely incorrect but check networking, authentication or your statement syntax", "exception" => e.message)
    @logger.warn("Ongoing count statement generation is being prevented")
    @count_is_supported = false
  end
end
disable_count() click to toggle source
# File lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb, line 12
def disable_count
  @needs_check = false
  @count_is_supported = false
end
execute_count(query) click to toggle source
# File lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb, line 39
def execute_count(query)
  query.count
end
log_statement_parameters(statement, parameters, query) click to toggle source
# File lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb, line 17
def log_statement_parameters(statement, parameters, query)
  return unless @in_debug
  check_count_query(query) if @needs_check && query
  if @count_is_supported
    @logger.debug("Executing JDBC query", :statement => statement, :parameters => parameters, :count => execute_count(query))
  else
    @logger.debug("Executing JDBC query", :statement => statement, :parameters => parameters)
  end
end