Sha256: ea27365393a9d797d2de09e69557f10ee235e2b219f3be3cf57ea2b35f6da951

Contents?: true

Size: 1.22 KB

Versions: 3

Compression:

Stored size: 1.22 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 log_statement_parameters(query, statement, parameters)
      return unless @in_debug
      check_count_query(query) if @needs_check
      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

3 entries across 3 versions & 1 rubygems

Version Path
logstash-input-jdbc-4.3.14 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb
logstash-input-jdbc-4.3.13 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb
logstash-input-jdbc-4.3.12 lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb