Sha256: 6923dc7e17499e65b22854b2bd3bfe1792ad96b2a9aee458c0bfec2bb0165f66

Contents?: true

Size: 1.32 KB

Versions: 28

Compression:

Stored size: 1.32 KB

Contents

# encoding: utf-8

module LogStash module PluginMixins module Jdbc
  class CheckedCountLogger
    def initialize(logger)
      @logger = logger
      @needs_check = true
      @count_is_supported = false
      @in_debug = @logger.debug?
    end

    def disable_count
      @needs_check = false
      @count_is_supported = false
    end

    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

    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

    def execute_count(query)
      query.count
    end
  end
end end end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
logstash-integration-jdbc-5.0.2 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb
logstash-integration-jdbc-5.0.1 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb
logstash-integration-jdbc-5.0.0 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb
logstash-integration-jdbc-5.0.0.alpha1 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb
logstash-input-jdbc-4.3.19 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb
logstash-input-jdbc-4.3.18 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb
logstash-input-jdbc-4.3.17 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb
logstash-input-jdbc-4.3.16 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb