ManageIQ/ovirt_metrics

View on GitHub

Showing 10 of 10 total issues

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

  def self.metrics_to_hashes(metrics, related_metrics, column_definitions, href_method)
    counters_by_id              = {}
    counter_values_by_id_and_ts = {}

    metrics.each do |metric|
Severity: Minor
Found in lib/ovirt_metrics.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

Similar blocks of code found in 3 locations. Consider refactoring.
Open

    "disk_usage_rate_average" => {
      :ovirt_key    => :disk_usage_rate_average,
      :ovirt_method => lambda { |metrics| VmDiskSamplesHistory.disk_usage_rate_average_in_kilobytes_per_second(metrics[:disk]) },
      :counter      => {
        :counter_key           => "disk_usage_rate_average",
Severity: Minor
Found in lib/ovirt_metrics/column_definitions.rb and 2 other locations - About 20 mins to fix
lib/ovirt_metrics/column_definitions.rb on lines 65..75
lib/ovirt_metrics/column_definitions.rb on lines 85..95

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 28.

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

Similar blocks of code found in 3 locations. Consider refactoring.
Open

    "net_usage_rate_average" => {
      :ovirt_key    => :net_usage_rate_average,
      :ovirt_method => lambda { |metrics| VmInterfaceSamplesHistory.net_usage_rate_average_in_kilobytes_per_second(metrics[:nic]) },
      :counter      => {
        :counter_key           => "net_usage_rate_average",
Severity: Minor
Found in lib/ovirt_metrics/column_definitions.rb and 2 other locations - About 20 mins to fix
lib/ovirt_metrics/column_definitions.rb on lines 51..61
lib/ovirt_metrics/column_definitions.rb on lines 85..95

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 28.

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

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

    "mem_usage_absolute_average" => {
      :ovirt_key    => :mem_usage_absolute_average,
      :ovirt_method => lambda { |metrics| metrics[:metric].memory_usage_percent.to_f },
      :counter      => {
        :counter_key           => "mem_usage_absolute_average",
Severity: Minor
Found in lib/ovirt_metrics/column_definitions.rb and 1 other location - About 20 mins to fix
lib/ovirt_metrics/column_definitions.rb on lines 3..13

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 28.

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

Similar blocks of code found in 3 locations. Consider refactoring.
Open

    "net_usage_rate_average" => {
      :ovirt_key    => :net_usage_rate_average,
      :ovirt_method => lambda { |metrics| HostInterfaceSamplesHistory.net_usage_rate_average_in_kilobytes_per_second(metrics[:nic]) },
      :counter      => {
        :counter_key           => "net_usage_rate_average",
Severity: Minor
Found in lib/ovirt_metrics/column_definitions.rb and 2 other locations - About 20 mins to fix
lib/ovirt_metrics/column_definitions.rb on lines 51..61
lib/ovirt_metrics/column_definitions.rb on lines 65..75

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 28.

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

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

    "cpu_usage_rate_average" => {
      :ovirt_key    => :cpu_usage_rate_average,
      :ovirt_method => lambda { |metrics| metrics[:metric].cpu_usage_percent.to_f },
      :counter      => {
        :counter_key           => "cpu_usage_rate_average",
Severity: Minor
Found in lib/ovirt_metrics/column_definitions.rb and 1 other location - About 20 mins to fix
lib/ovirt_metrics/column_definitions.rb on lines 31..41

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 28.

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

Use match? instead of =~ when MatchData is not used.
Open

    if e.message =~ /No connection pool.+found/
Severity: Minor
Found in lib/ovirt_metrics.rb by rubocop

In Ruby 2.4, String#match?, Regexp#match? and Symbol#match? have been added. The methods are faster than match. Because the methods avoid creating a MatchData object or saving backref. So, when MatchData is not used, use match? instead of match.

Example:

# bad
def foo
  if x =~ /re/
    do_something
  end
end

# bad
def foo
  if x.match(/re/)
    do_something
  end
end

# bad
def foo
  if /re/ === x
    do_something
  end
end

# good
def foo
  if x.match?(/re/)
    do_something
  end
end

# good
def foo
  if x =~ /re/
    do_something(Regexp.last_match)
  end
end

# good
def foo
  if x.match(/re/)
    do_something($~)
  end
end

# good
def foo
  if /re/ === x
    do_something($~)
  end
end

Unused block argument - evm_col. If it's necessary, use _ or _evm_col as an argument name to indicate that it won't be used.
Open

      column_definitions.each do |evm_col, info|
Severity: Minor
Found in lib/ovirt_metrics.rb by rubocop

Checks for unused block arguments.

Example:

# bad
do_something do |used, unused|
  puts used
end

do_something do |bar|
  puts :foo
end

define_method(:foo) do |bar|
  puts :baz
end

# good
do_something do |used, _unused|
  puts used
end

do_something do
  puts :foo
end

define_method(:foo) do |_bar|
  puts :baz
end

Example: IgnoreEmptyBlocks: true (default)

# good
do_something { |unused| }

Example: IgnoreEmptyBlocks: false

# bad
do_something { |unused| }

Example: AllowUnusedKeywordArguments: false (default)

# bad
do_something do |unused: 42|
  foo
end

Example: AllowUnusedKeywordArguments: true

# good
do_something do |unused: 42|
  foo
end

Do not set test_files in gemspec.
Open

  spec.test_files    = `git ls-files -- spec/*`.split("\n")
Severity: Minor
Found in ovirt_metrics.gemspec by rubocop

Checks that deprecated attributes are not set in a gemspec file. Removing deprecated attributes allows the user to receive smaller packed gems.

Example:

# bad
Gem::Specification.new do |spec|
  spec.name = 'your_cool_gem_name'
  spec.test_files = Dir.glob('test/**/*')
end

# bad
Gem::Specification.new do |spec|
  spec.name = 'your_cool_gem_name'
  spec.test_files += Dir.glob('test/**/*')
end

# good
Gem::Specification.new do |spec|
  spec.name = 'your_cool_gem_name'
end

metadata['rubygems_mfa_required'] must be set to 'true'.
Open

Gem::Specification.new do |spec|
  spec.name          = "ovirt_metrics"
  spec.version       = OvirtMetrics::VERSION
  spec.authors       = ["Oleg Barenboim", "Jason Frey"]
  spec.email         = ["chessbyte@gmail.com", "fryguy9@gmail.com"]
Severity: Minor
Found in ovirt_metrics.gemspec by rubocop

Requires a gemspec to have rubygems_mfa_required metadata set.

This setting tells RubyGems that MFA (Multi-Factor Authentication) is required for accounts to be able perform privileged operations, such as (see RubyGems' documentation for the full list of privileged operations):

  • gem push
  • gem yank
  • gem owner --add/remove
  • adding or removing owners using gem ownership page

This helps make your gem more secure, as users can be more confident that gem updates were pushed by maintainers.

Example:

# bad
Gem::Specification.new do |spec|
  # no `rubygems_mfa_required` metadata specified
end

# good
Gem::Specification.new do |spec|
  spec.metadata = {
    'rubygems_mfa_required' => 'true'
  }
end

# good
Gem::Specification.new do |spec|
  spec.metadata['rubygems_mfa_required'] = 'true'
end

# bad
Gem::Specification.new do |spec|
  spec.metadata = {
    'rubygems_mfa_required' => 'false'
  }
end

# good
Gem::Specification.new do |spec|
  spec.metadata = {
    'rubygems_mfa_required' => 'true'
  }
end

# bad
Gem::Specification.new do |spec|
  spec.metadata['rubygems_mfa_required'] = 'false'
end

# good
Gem::Specification.new do |spec|
  spec.metadata['rubygems_mfa_required'] = 'true'
end
Severity
Category
Status
Source
Language