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.2.4 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb
logstash-integration-jdbc-5.2.3 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb
logstash-integration-jdbc-5.2.2 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb
logstash-integration-jdbc-5.2.1 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb
logstash-integration-jdbc-5.2.0 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb
logstash-integration-jdbc-5.1.10 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb
logstash-integration-jdbc-5.1.8 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb
logstash-integration-jdbc-5.1.7 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb
logstash-integration-jdbc-5.1.6 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb
logstash-integration-jdbc-5.1.5 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb
logstash-integration-jdbc-5.1.4 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb
logstash-integration-jdbc-5.1.3 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb
logstash-integration-jdbc-5.1.2 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb
logstash-integration-jdbc-5.1.1 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb
logstash-integration-jdbc-5.1.0 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb
logstash-integration-jdbc-5.0.7 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb
logstash-integration-jdbc-5.0.6 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb
logstash-integration-jdbc-5.0.5 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb
logstash-integration-jdbc-5.0.4 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb
logstash-integration-jdbc-5.0.3 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb