fabric8io/fluent-plugin-kubernetes_metadata_filter

View on GitHub

Showing 24 of 24 total issues

Method configure has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring.
Open

    def configure(conf)
      super

      require 'kubeclient'
      require 'lru_redux'
Severity: Minor
Found in lib/fluent/plugin/filter_kubernetes_metadata.rb - About 7 hrs 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_pod_metadata has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
Open

    def get_pod_metadata(key, namespace_name, pod_name, time, batch_miss_cache)
      metadata = {}
      ids = @id_cache[key]
      if ids.nil?
        @stats.bump(:id_cache_miss)
Severity: Minor
Found in lib/fluent/plugin/kubernetes_metadata_cache_strategy.rb - About 5 hrs 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 configure has 92 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def configure(conf)
      super

      require 'kubeclient'
      require 'lru_redux'
Severity: Major
Found in lib/fluent/plugin/filter_kubernetes_metadata.rb - About 3 hrs to fix

    Method parse_pod_metadata has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

        def parse_pod_metadata(pod_object)
          labels = ''
          labels = syms_to_strs(pod_object[:metadata][:labels].to_h) unless (@skip_labels || @skip_pod_labels)
    
          annotations = match_annotations(syms_to_strs(pod_object[:metadata][:annotations].to_h))
    Severity: Minor
    Found in lib/fluent/plugin/kubernetes_metadata_common.rb - About 3 hrs 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

    File filter_kubernetes_metadata.rb has 293 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require_relative 'kubernetes_metadata_cache_strategy'
    require_relative 'kubernetes_metadata_common'
    require_relative 'kubernetes_metadata_stats'
    require_relative 'kubernetes_metadata_util'
    require_relative 'kubernetes_metadata_watch_namespaces'
    Severity: Minor
    Found in lib/fluent/plugin/filter_kubernetes_metadata.rb - About 3 hrs to fix

      Method process_pod_watcher_notices has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

          def process_pod_watcher_notices(watcher)
            watcher.each do |notice|
              # store version we processed to not reprocess it ... do not unset when there is no version in response
              version = ( # TODO: replace with &.dig once we are on ruby 2.5+
                notice[:object] && notice[:object][:metadata] && notice[:object][:metadata][:resourceVersion]
      Severity: Minor
      Found in lib/fluent/plugin/kubernetes_metadata_watch_pods.rb - About 2 hrs 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_pod_metadata has 63 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def get_pod_metadata(key, namespace_name, pod_name, time, batch_miss_cache)
            metadata = {}
            ids = @id_cache[key]
            if ids.nil?
              @stats.bump(:id_cache_miss)
      Severity: Major
      Found in lib/fluent/plugin/kubernetes_metadata_cache_strategy.rb - About 2 hrs to fix

        Method get_metadata_for_record has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_metadata_for_record(namespace_name, pod_name, container_name, cache_key, create_time, batch_miss_cache, docker_id)
              metadata = {
                'docker' => { 'container_id' => "" },
                'kubernetes' => {
                  'container_name' => container_name,
        Severity: Minor
        Found in lib/fluent/plugin/filter_kubernetes_metadata.rb - About 2 hrs 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 set_up_namespace_thread has 59 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def set_up_namespace_thread
              # Any failures / exceptions in the initial setup should raise
              # Fluent:ConfigError, so that users can inspect potential errors in
              # the configuration.
              namespace_watcher = start_namespace_watch
        Severity: Major
        Found in lib/fluent/plugin/kubernetes_metadata_watch_namespaces.rb - About 2 hrs to fix

          Method set_up_pod_thread has 59 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def set_up_pod_thread
                # Any failures / exceptions in the initial setup should raise
                # Fluent:ConfigError, so that users can inspect potential errors in
                # the configuration.
                pod_watcher = start_pod_watch
          Severity: Major
          Found in lib/fluent/plugin/kubernetes_metadata_watch_pods.rb - About 2 hrs to fix

            Method set_up_namespace_thread has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
            Open

                def set_up_namespace_thread
                  # Any failures / exceptions in the initial setup should raise
                  # Fluent:ConfigError, so that users can inspect potential errors in
                  # the configuration.
                  namespace_watcher = start_namespace_watch
            Severity: Minor
            Found in lib/fluent/plugin/kubernetes_metadata_watch_namespaces.rb - About 2 hrs 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_namespace_watcher_notices has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
            Open

                def process_namespace_watcher_notices(watcher)
                  watcher.each do |notice|
                    case notice[:type]
                    when 'MODIFIED'
                      reset_namespace_watch_retry_stats
            Severity: Minor
            Found in lib/fluent/plugin/kubernetes_metadata_watch_namespaces.rb - About 2 hrs 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 set_up_pod_thread has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
            Open

                def set_up_pod_thread
                  # Any failures / exceptions in the initial setup should raise
                  # Fluent:ConfigError, so that users can inspect potential errors in
                  # the configuration.
                  pod_watcher = start_pod_watch
            Severity: Minor
            Found in lib/fluent/plugin/kubernetes_metadata_watch_pods.rb - About 2 hrs 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

            Consider simplifying this complex logical expression.
            Open

                  if @lookup_from_k8s_field && record.key?('kubernetes') && record.key?('docker') &&
                      record['kubernetes'].respond_to?(:has_key?) && record['docker'].respond_to?(:has_key?) &&
                      record['kubernetes'].key?('namespace_name') &&
                      record['kubernetes'].key?('pod_name') &&
                      record['kubernetes'].key?('container_name') &&
            Severity: Critical
            Found in lib/fluent/plugin/filter_kubernetes_metadata.rb - About 2 hrs to fix

              Method parse_pod_metadata has 48 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def parse_pod_metadata(pod_object)
                    labels = ''
                    labels = syms_to_strs(pod_object[:metadata][:labels].to_h) unless (@skip_labels || @skip_pod_labels)
              
                    annotations = match_annotations(syms_to_strs(pod_object[:metadata][:annotations].to_h))
              Severity: Minor
              Found in lib/fluent/plugin/kubernetes_metadata_common.rb - About 1 hr to fix

                Method process_pod_watcher_notices has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    def process_pod_watcher_notices(watcher)
                      watcher.each do |notice|
                        # store version we processed to not reprocess it ... do not unset when there is no version in response
                        version = ( # TODO: replace with &.dig once we are on ruby 2.5+
                          notice[:object] && notice[:object][:metadata] && notice[:object][:metadata][:resourceVersion]
                Severity: Minor
                Found in lib/fluent/plugin/kubernetes_metadata_watch_pods.rb - About 1 hr to fix

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

                      def filter(tag, time, record)
                        tag_match_data = tag.match(@tag_to_kubernetes_name_regexp_compiled)
                        batch_miss_cache = {}
                        if tag_match_data
                          cache_key =  if tag_match_data.names.include?('pod_uuid') && !tag_match_data['pod_uuid'].nil?
                  Severity: Minor
                  Found in lib/fluent/plugin/filter_kubernetes_metadata.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 process_namespace_watcher_notices has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      def process_namespace_watcher_notices(watcher)
                        watcher.each do |notice|
                          case notice[:type]
                          when 'MODIFIED'
                            reset_namespace_watch_retry_stats
                  Severity: Minor
                  Found in lib/fluent/plugin/kubernetes_metadata_watch_namespaces.rb - About 1 hr to fix

                    Method get_metadata_for_record has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        def get_metadata_for_record(namespace_name, pod_name, container_name, cache_key, create_time, batch_miss_cache, docker_id)
                          metadata = {
                            'docker' => { 'container_id' => "" },
                            'kubernetes' => {
                              'container_name' => container_name,
                    Severity: Minor
                    Found in lib/fluent/plugin/filter_kubernetes_metadata.rb - About 1 hr to fix

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

                          def fetch_pod_metadata(namespace_name, pod_name)
                            log.trace("fetching pod metadata: #{namespace_name}/#{pod_name}")
                            options = {
                              resource_version: '0' # Fetch from API server cache instead of etcd quorum read
                            }
                      Severity: Minor
                      Found in lib/fluent/plugin/filter_kubernetes_metadata.rb - About 1 hr to fix
                        Severity
                        Category
                        Status
                        Source
                        Language