uken/fluent-plugin-elasticsearch

View on GitHub

Showing 80 of 80 total issues

Identical blocks of code found in 2 locations. Consider refactoring.
Open

    def is_existing_connection(host)
      # check if the host provided match the current connection
      return false if @_es.nil?
      return false if @current_config.nil?
      return false if host.length != @current_config.length
Severity: Major
Found in lib/fluent/plugin/in_elasticsearch.rb and 1 other location - About 1 hr to fix
lib/fluent/plugin/out_elasticsearch.rb on lines 1179..1191

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 55.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Method expand_param has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def expand_param(param, tag, time, record)
      # check for '${ ... }'
      #   yes => `eval`
      #   no  => return param
      return param if (param.to_s =~ /\${.+}/).nil?
Severity: Minor
Found in lib/fluent/plugin/out_elasticsearch_dynamic.rb - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Identical blocks of code found in 2 locations. Consider refactoring.
Open

    def is_existing_connection(host)
      # check if the host provided match the current connection
      return false if @_es.nil?
      return false if @current_config.nil?
      return false if host.length != @current_config.length
Severity: Major
Found in lib/fluent/plugin/out_elasticsearch.rb and 1 other location - About 1 hr to fix
lib/fluent/plugin/in_elasticsearch.rb on lines 245..257

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 55.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Method client has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def client(host = nil)
      # check here to see if we already have a client connection for the given host
      connection_options = get_connection_options(host)

      @_es = nil unless is_existing_connection(connection_options[:hosts])
Severity: Minor
Found in lib/fluent/plugin/in_elasticsearch.rb - About 1 hr to fix

    Method configure has 29 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def configure(conf)
          super
    
          @timestamp_parser = create_time_parser
          @backend_options = backend_options
    Severity: Minor
    Found in lib/fluent/plugin/in_elasticsearch.rb - About 1 hr to fix

      Method create_rollover_alias has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def create_rollover_alias(target_index, rollover_index, deflector_alias_name, app_name, index_date_pattern, index_separator, enable_ilm, ilm_policy_id, ilm_policy, ilm_policy_overwrite, host)
           # ILM request to create alias.
          if rollover_index || enable_ilm
            if !client.indices.exists_alias(:name => deflector_alias_name)
              if @logstash_format
      Severity: Minor
      Found in lib/fluent/plugin/elasticsearch_index_template.rb - About 1 hr to fix

        Method template_install has 9 arguments (exceeds 4 allowed). Consider refactoring.
        Open

          def template_install(name, template_file, overwrite, enable_ilm = false, deflector_alias_name = nil, ilm_policy_id = nil, host = nil, target_index = nil, index_separator = '-')
        Severity: Major
        Found in lib/fluent/plugin/elasticsearch_index_template.rb - About 1 hr to fix

          Method get_affinity_target_indices has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def get_affinity_target_indices(chunk)
                indices = Hash.new
                if target_index_affinity_enabled?()
                  id_key_accessor = record_accessor_create(@id_key)
                  ids = Set.new
          Severity: Minor
          Found in lib/fluent/plugin/out_elasticsearch.rb - About 1 hr to fix

            Method verify_ilm_working has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

              def verify_ilm_working
                # Check the Elasticsearch instance for ILM readiness - this means that the version has to be a non-OSS release, with ILM feature
                # available and enabled.
                begin
                  xpack = xpack_info
            Severity: Minor
            Found in lib/fluent/plugin/elasticsearch_index_lifecycle_management.rb - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method get_connection_options has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def get_connection_options(con_host)
                  raise "`password` must be present if `user` is present" if @user && !@password
            
                  hosts = if con_host || @hosts
                    (con_host || @hosts).split(',').map do |host_str|
            Severity: Minor
            Found in lib/fluent/plugin/out_elasticsearch_dynamic.rb - About 1 hr to fix

              Method retry_operate has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                def retry_operate(max_retries, fail_on_retry_exceed = true, catch_trasport_exceptions = true)
                  return unless block_given?
                  retries = 0
                  transport_errors = TRANSPORT_CLASS::Transport::Errors.constants.map{ |c| TRANSPORT_CLASS::Transport::Errors.const_get c } if catch_trasport_exceptions
                  begin
              Severity: Minor
              Found in lib/fluent/plugin/elasticsearch_index_template.rb - About 55 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Method template_install has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                def template_install(name, template_file, overwrite, enable_ilm = false, deflector_alias_name = nil, ilm_policy_id = nil, host = nil, target_index = nil, index_separator = '-')
                  inject_template_name = get_template_name(enable_ilm, name, deflector_alias_name)
                  if overwrite
                    template_put(inject_template_name,
                                 enable_ilm ? inject_ilm_settings_to_template(deflector_alias_name,
              Severity: Minor
              Found in lib/fluent/plugin/elasticsearch_index_template.rb - About 55 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Method process_message has 7 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def process_message(tag, meta, header, time, record, affinity_target_indices, extracted_values)
              Severity: Major
              Found in lib/fluent/plugin/out_elasticsearch.rb - About 50 mins to fix

                Method template_installation_actual has 7 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    def template_installation_actual(deflector_alias, template_name, customize_template, application_name, target_index, ilm_policy_id, host=nil)
                Severity: Major
                Found in lib/fluent/plugin/out_elasticsearch.rb - About 50 mins to fix

                  Method template_installation has 7 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      def template_installation(deflector_alias, template_name, customize_template, application_name, ilm_policy_id, target_index, host)
                  Severity: Major
                  Found in lib/fluent/plugin/out_elasticsearch.rb - About 50 mins to fix

                    Method send_bulk has 7 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        def send_bulk(data, tag, chunk, bulk_message_count, extracted_values, info, unpacked_msg_arr)
                    Severity: Major
                    Found in lib/fluent/plugin/out_elasticsearch.rb - About 50 mins to fix

                      Method process_events has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def process_events(hit, es)
                            event = hit["_source"]
                            time = Fluent::Engine.now
                            if @parse_timestamp
                              if event.has_key?(TIMESTAMP_FIELD)
                      Severity: Minor
                      Found in lib/fluent/plugin/in_elasticsearch.rb - About 45 mins to fix

                      Cognitive Complexity

                      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                      A method's cognitive complexity is based on a few simple rules:

                      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                      • Code is considered more complex for each "break in the linear flow of the code"
                      • Code is considered more complex when "flow breaking structures are nested"

                      Further reading

                      Method run_slice has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def run_slice(slice_id=nil)
                            slice_query = @base_query
                            slice_query = slice_query.merge('slice' => { 'id' => slice_id, 'max' => @num_slices}) unless slice_id.nil?
                            result = client.search(@options.merge(:body => Yajl.dump(slice_query) ))
                            es = Fluent::MultiEventStream.new
                      Severity: Minor
                      Found in lib/fluent/plugin/in_elasticsearch.rb - About 45 mins to fix

                      Cognitive Complexity

                      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                      A method's cognitive complexity is based on a few simple rules:

                      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                      • Code is considered more complex for each "break in the linear flow of the code"
                      • Code is considered more complex when "flow breaking structures are nested"

                      Further reading

                      Method handle_error has 6 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                        def handle_error(response, tag, chunk, bulk_message_count, extracted_values, unpacked_msg_arr)
                      Severity: Minor
                      Found in lib/fluent/plugin/elasticsearch_error_handler.rb - About 45 mins to fix

                        Method append_record_to_messages has 5 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                            def append_record_to_messages(op, meta, header, record, msgs)
                        Severity: Minor
                        Found in lib/fluent/plugin/out_elasticsearch_data_stream.rb - About 35 mins to fix
                          Severity
                          Category
                          Status
                          Source
                          Language