Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle nil values from benchmarks in Capistrano #159

Merged
merged 3 commits into from
Oct 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 21 additions & 24 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-03-23 17:40:12 -0400 using RuboCop version 0.49.1.
# on 2018-10-01 12:52:09 +0200 using RuboCop version 0.49.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 3
# Configuration parameters: Include.
# Include: **/Gemfile, **/gems.rb
Bundler/DuplicatedGem:
Exclude:
- 'Gemfile'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: Include, TreatCommentsAsGroupSeparators.
Expand Down Expand Up @@ -58,7 +51,7 @@ Layout/EmptyLines:
- 'lib/capistrano/datadog/v2.rb'
- 'lib/dogapi/facade.rb'

# Offense count: 60
# Offense count: 63
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
Expand Down Expand Up @@ -210,21 +203,21 @@ Lint/UselessAssignment:

# Offense count: 11
Metrics/AbcSize:
Max: 50
Max: 51

# Offense count: 15
# Offense count: 18
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 96

# Offense count: 1
# Offense count: 2
Metrics/CyclomaticComplexity:
Max: 7
Max: 8

# Offense count: 15
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 33
Max: 34

# Offense count: 2
# Configuration parameters: CountKeywordArgs.
Expand All @@ -233,7 +226,7 @@ Metrics/ParameterLists:

# Offense count: 1
Metrics/PerceivedComplexity:
Max: 8
Max: 9

# Offense count: 11
Style/AccessorMethodName:
Expand Down Expand Up @@ -316,7 +309,7 @@ Style/ConditionalAssignment:
Exclude:
- 'lib/capistrano/datadog.rb'

# Offense count: 19
# Offense count: 20
# Cop supports --auto-correct.
Style/DefWithParentheses:
Exclude:
Expand Down Expand Up @@ -380,12 +373,11 @@ Style/HashSyntax:
- 'lib/dogapi/v1/snapshot.rb'
- 'lib/dogapi/v1/tag.rb'

# Offense count: 16
# Offense count: 15
# Cop supports --auto-correct.
# Configuration parameters: MaxLineLength.
Style/IfUnlessModifier:
Exclude:
- 'Gemfile'
- 'lib/capistrano/datadog.rb'
- 'lib/capistrano/datadog/v2.rb'
- 'lib/capistrano/datadog/v3.rb'
Expand All @@ -401,7 +393,7 @@ Style/LineEndConcatenation:
Exclude:
- 'dogapi.gemspec'

# Offense count: 14
# Offense count: 15
# Cop supports --auto-correct.
Style/MethodCallWithoutArgsParentheses:
Exclude:
Expand All @@ -410,13 +402,13 @@ Style/MethodCallWithoutArgsParentheses:
- 'lib/dogapi/facade.rb'
- 'lib/dogapi/v1/event.rb'

# Offense count: 5
# Offense count: 4
# Cop supports --auto-correct.
Style/MultilineIfThen:
Exclude:
- 'lib/capistrano/datadog.rb'

# Offense count: 20
# Offense count: 21
# Cop supports --auto-correct.
Style/MutableConstant:
Enabled: false
Expand Down Expand Up @@ -478,6 +470,12 @@ Style/RedundantSelf:
- 'lib/dogapi/facade.rb'
- 'lib/dogapi/v1/metric.rb'

# Offense count: 1
# Cop supports --auto-correct.
Style/RescueModifier:
Exclude:
- 'lib/capistrano/datadog.rb'

# Offense count: 2
# Cop supports --auto-correct.
Style/SelfAssignment:
Expand All @@ -493,7 +491,7 @@ Style/SpecialGlobalVars:
Exclude:
- 'dogapi.gemspec'

# Offense count: 23
# Offense count: 22
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Expand All @@ -520,13 +518,12 @@ Style/TrailingCommaInLiteral:
- 'lib/dogapi/v1/snapshot.rb'
- 'lib/dogapi/v1/user.rb'

# Offense count: 3
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, MinSize, WordRegex.
# SupportedStyles: percent, brackets
Style/WordArray:
Exclude:
- 'Rakefile'
- 'examples/custom_event.rb'

# Offense count: 1
Expand Down
4 changes: 4 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ end
task :rubocop do
sh "rubocop"
end

task :rubocop_todo do
sh "rubocop --auto-gen-config"
end
7 changes: 5 additions & 2 deletions lib/capistrano/datadog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ def self.reporter()

def self.cap_version()
if @cap_version.nil? then
if Configuration.respond_to? :instance then
if !defined? Configuration
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Configuration is not defined at test time, library would eventually fail with an empty version but for testing is ok.

@cap_version = ''
elsif Configuration.respond_to? :instance
@cap_version = :v2
else
@cap_version = :v3
Expand Down Expand Up @@ -108,8 +110,9 @@ def report()
if !task[:application].nil? and !task[:application].empty? then
application = ' for ' + task[:application]
end
timing = Float(task[:timing]).round(2) rescue 'n/a'
title = "#{user}@#{hostname} ran #{name}#{application} on #{roles.join(', ')} "\
"with capistrano in #{task[:timing].round(2)} secs"
"with capistrano in #{timing} secs"
type = 'deploy'
alert_type = 'success'
source_type = 'capistrano'
Expand Down
36 changes: 36 additions & 0 deletions spec/unit/capistrano_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'spec_helper'
require 'capistrano/datadog'
require 'benchmark'

describe 'Capistrano' do
context 'Reporter' do
context 'report' do
before(:each) do
@task = {
name: 'ATask',
roles: [],
stage: 'AStage',
application: 'MyApp',
logs: [],
hosts: []
}
@reporter = Capistrano::Datadog.reporter
end

it 'normally works with float timing' do
@task[:timing] = 9.99999
expected = @task[:timing].round(2)
@reporter.instance_variable_set(:@tasks, [@task])
event = @reporter.report.first.first
expect(event.msg_title).to include("with capistrano in #{expected} secs")
end

it 'handles non-numeric timing' do
@task[:timing] = nil
@reporter.instance_variable_set(:@tasks, [@task])
event = @reporter.report.first.first
expect(event.msg_title).to include('with capistrano in n/a secs')
end
end
end
end