capistrano-measure 0.8.1 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -0
- data/README.md +11 -0
- data/capistrano-measure.gemspec +1 -1
- data/lib/capistrano/measure/adapter.rb +38 -6
- data/lib/capistrano/measure/error.rb +5 -0
- data/lib/capistrano/measure/integration/capistrano_2.rb +1 -1
- data/lib/capistrano/measure/integration/capistrano_3.rb +1 -1
- data/lib/capistrano/measure/log_reporter.rb +32 -14
- data/lib/capistrano/measure/timer.rb +2 -2
- data/lib/capistrano/measure/version.rb +1 -1
- data/lib/capistrano/measure.rb +2 -1
- data/spec/capistrano/measure/adapter_spec.rb +27 -2
- data/spec/capistrano/measure/lib_reporter_spec.rb +18 -7
- data/spec/capistrano/measure/timer_spec.rb +3 -2
- metadata +10 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7985b11ba0b7a76c5839925a75d929a7991222ec
|
4
|
+
data.tar.gz: d9d5b4a4bb46921324ffe71b8b4769788bdd5d68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9afca2004487f749ba1863e190f7ec1716362e9fd9df5519293765533849a2a9e9287c72fa8c551240fafde5a0d8f6799739556004720f29e144aaa876c6216d
|
7
|
+
data.tar.gz: d9d7958f05359b27fdc8d54d943632572e81a73308d63126047be83b48ff00f169801160c6968efcdc11cf1302a7e7b7346071612d7c9423f0e7aeef11cb9d48
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
# Capistrano::Measure - deployment speed measure tool
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/capistrano-measure.svg)](https://badge.fury.io/rb/capistrano-measure)
|
3
|
+
[![Build Status](https://travis-ci.org/AMekss/capistrano-measure.svg?branch=master)](https://travis-ci.org/AMekss/capistrano-measure)
|
2
4
|
|
3
5
|
In order to improve something you have to measure it! This helps you measure performance of your Capistrano deployments by appending performance reports after each Capistrano execution
|
4
6
|
|
@@ -85,6 +87,15 @@ It will append every capistrano execution with similar report
|
|
85
87
|
I, [2014-10-23T18:10:31.386225 #14352] INFO -- : deploy 104s
|
86
88
|
I, [2014-10-23T18:10:31.386246 #14352] INFO -- : ==========================================================
|
87
89
|
|
90
|
+
### Settings
|
91
|
+
You could change threshold time to change the results duration's color.
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
set :alert_threshold, 10 # default 60 sec
|
95
|
+
set :warning_threshold, 5 # default 30 sec
|
96
|
+
set :measure_error_handling, :raise # default :silent
|
97
|
+
```
|
98
|
+
|
88
99
|
## Contributing
|
89
100
|
|
90
101
|
1. Fork it ( https://github.com/[my-github-username]/capistrano-measure/fork )
|
data/capistrano-measure.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
20
|
spec.add_dependency "capistrano", ">= 2", "< 4"
|
21
|
-
spec.add_dependency "
|
21
|
+
spec.add_dependency "colorize", '>= 0.8.1'
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.7"
|
24
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
@@ -8,21 +8,53 @@ module Capistrano
|
|
8
8
|
nil
|
9
9
|
end
|
10
10
|
|
11
|
-
def initialize(logger
|
12
|
-
@
|
13
|
-
@
|
11
|
+
def initialize(logger, config)
|
12
|
+
@logger = logger
|
13
|
+
@config = config
|
14
|
+
@valid = true
|
14
15
|
end
|
15
16
|
|
16
17
|
def before_task(task_name)
|
17
|
-
|
18
|
+
with_error_handling { timer.start(task_name) }
|
18
19
|
end
|
19
20
|
|
20
21
|
def after_task(task_name)
|
21
|
-
|
22
|
+
with_error_handling { timer.stop(task_name) }
|
22
23
|
end
|
23
24
|
|
24
25
|
def print_report
|
25
|
-
|
26
|
+
if valid?
|
27
|
+
log_reporter.render(timer.report_events)
|
28
|
+
else
|
29
|
+
log_reporter.render_error("Capistrano::Measure plugin encountered an error during performance evaluation and is not able to present a performance report, in order to `raise` and troubleshoot this error add `set :measure_error_handling, :raise` into your capistrano config")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
attr_reader :logger, :config
|
36
|
+
|
37
|
+
def log_reporter
|
38
|
+
@log_reporter ||= Capistrano::Measure::LogReporter.new(logger, config)
|
39
|
+
end
|
40
|
+
|
41
|
+
def timer
|
42
|
+
@timer ||= Capistrano::Measure::Timer.new
|
43
|
+
end
|
44
|
+
|
45
|
+
def debug?
|
46
|
+
config.fetch(:measure_error_handling, :silent) == :raise
|
47
|
+
end
|
48
|
+
|
49
|
+
def valid?
|
50
|
+
@valid
|
51
|
+
end
|
52
|
+
|
53
|
+
def with_error_handling
|
54
|
+
yield
|
55
|
+
rescue StandardError => e
|
56
|
+
@valid = false
|
57
|
+
raise e if debug?
|
26
58
|
end
|
27
59
|
|
28
60
|
end
|
@@ -3,7 +3,7 @@ module Capistrano
|
|
3
3
|
module Integration
|
4
4
|
module Capistrano3
|
5
5
|
def measure_adapter
|
6
|
-
@measure_adapter ||= Capistrano::Measure::Adapter.new
|
6
|
+
@measure_adapter ||= Capistrano::Measure::Adapter.new(::Logger.new(STDOUT), ::Capistrano::Configuration.env)
|
7
7
|
end
|
8
8
|
|
9
9
|
def insert_measure_tasks
|
@@ -1,33 +1,49 @@
|
|
1
|
-
require '
|
1
|
+
require 'colorized_string'
|
2
2
|
require 'logger'
|
3
3
|
|
4
4
|
module Capistrano
|
5
5
|
module Measure
|
6
6
|
class LogReporter
|
7
|
-
ALERT_TRASHOLD = 60
|
8
|
-
WARNING_TRASHOLD = 30
|
9
7
|
|
10
|
-
|
11
|
-
|
8
|
+
attr_reader :alert_threshold, :warning_threshold
|
9
|
+
|
10
|
+
DEFALUT_ALERT_THRESHOLD = 60
|
11
|
+
DEFAULT_WARNING_THRESHOLD = 30
|
12
|
+
|
13
|
+
def initialize(logger, config)
|
14
|
+
@logger = logger
|
15
|
+
@alert_threshold = config.fetch(:alert_threshold, DEFALUT_ALERT_THRESHOLD)
|
16
|
+
@warning_threshold = config.fetch(:warning_threshold, DEFAULT_WARNING_THRESHOLD)
|
12
17
|
end
|
13
18
|
|
14
19
|
def render(events)
|
15
20
|
return if events.to_a.empty?
|
16
21
|
|
17
|
-
|
18
|
-
|
19
|
-
|
22
|
+
with_layout do
|
23
|
+
events.each do |event|
|
24
|
+
log "#{'..' * event.indent}#{event.name} #{colorize_time(event.elapsed_time)}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
20
28
|
|
21
|
-
|
22
|
-
|
29
|
+
def render_error(message)
|
30
|
+
with_layout do
|
31
|
+
@logger.error message
|
23
32
|
end
|
24
|
-
log_sepertor
|
25
33
|
end
|
26
34
|
|
27
35
|
private
|
28
36
|
|
37
|
+
def with_layout
|
38
|
+
log_sepertor
|
39
|
+
log ColorizedString[" Performance Report"].green
|
40
|
+
log_sepertor
|
41
|
+
yield
|
42
|
+
log_sepertor
|
43
|
+
end
|
44
|
+
|
29
45
|
def log_sepertor
|
30
|
-
log "
|
46
|
+
log "=" * 60
|
31
47
|
end
|
32
48
|
|
33
49
|
def log(text)
|
@@ -36,10 +52,12 @@ module Capistrano
|
|
36
52
|
|
37
53
|
def colorize_time(time_spent)
|
38
54
|
return if time_spent.nil?
|
39
|
-
color
|
40
|
-
"#{time_spent}s".send(color)
|
55
|
+
ColorizedString["#{time_spent}s"].colorize(color(time_spent))
|
41
56
|
end
|
42
57
|
|
58
|
+
def color(time_spent)
|
59
|
+
(time_spent > alert_threshold ? :red : (time_spent > warning_threshold ? :yellow : :green))
|
60
|
+
end
|
43
61
|
end
|
44
62
|
end
|
45
63
|
end
|
@@ -42,7 +42,7 @@ module Capistrano
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def report_events
|
45
|
-
raise
|
45
|
+
raise ::Capistrano::Measure::Error, "Performance evaluation is not yet completed, as there are events still open: #{@open_events.map(&:name).join(', ')}" unless @open_events.empty?
|
46
46
|
return to_enum(__callee__) unless block_given?
|
47
47
|
|
48
48
|
(events + [Event.new]).each_cons(2) do |event, next_event|
|
@@ -55,7 +55,7 @@ module Capistrano
|
|
55
55
|
def close_event(event_name)
|
56
56
|
event = Event.new(event_name, :stop, Time.now, @indent-1)
|
57
57
|
open_event = @open_events.last
|
58
|
-
raise "
|
58
|
+
raise ::Capistrano::Measure::Error, "Cannot estimate time for event `#{event_name}`" unless event.eq?(open_event)
|
59
59
|
|
60
60
|
event.elapsed_time = (event.time - open_event.time).to_i
|
61
61
|
event
|
data/lib/capistrano/measure.rb
CHANGED
@@ -3,6 +3,7 @@ require 'capistrano/measure/version'
|
|
3
3
|
require 'capistrano/measure/timer'
|
4
4
|
require 'capistrano/measure/log_reporter'
|
5
5
|
require 'capistrano/measure/adapter'
|
6
|
+
require 'capistrano/measure/error'
|
6
7
|
|
7
8
|
case ::Capistrano::Measure::Adapter::capistrano_version
|
8
9
|
when 2
|
@@ -10,7 +11,7 @@ when 2
|
|
10
11
|
when 3
|
11
12
|
require 'capistrano/measure/integration/capistrano_3'
|
12
13
|
else
|
13
|
-
raise 'This version of Capistrano is not supported.'
|
14
|
+
raise ::Capistrano::Measure::Error, 'This version of Capistrano is not supported.'
|
14
15
|
end
|
15
16
|
|
16
17
|
module Capistrano
|
@@ -5,7 +5,8 @@ require 'capistrano/measure/adapter'
|
|
5
5
|
|
6
6
|
describe Capistrano::Measure::Adapter do
|
7
7
|
let(:logger) { ::StringLogger.new }
|
8
|
-
|
8
|
+
let(:config) { {} }
|
9
|
+
subject { Capistrano::Measure::Adapter.new(logger, config) }
|
9
10
|
|
10
11
|
it "end-to-end test" do
|
11
12
|
subject.before_task('root_task')
|
@@ -19,7 +20,31 @@ describe Capistrano::Measure::Adapter do
|
|
19
20
|
|
20
21
|
subject.print_report
|
21
22
|
|
22
|
-
expect(logger.to_s).
|
23
|
+
expect(logger.to_s).to include("Performance Report")
|
24
|
+
expect(logger.to_s).to include("root_task")
|
25
|
+
expect(logger.to_s).to include("..sub_task")
|
26
|
+
expect(logger.to_s).to include("....sub_task1")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "doesn't rise any errors by default" do
|
30
|
+
subject.before_task('root_task')
|
31
|
+
subject.after_task('sub_task')
|
32
|
+
|
33
|
+
subject.print_report
|
34
|
+
|
35
|
+
expect(logger.to_s).to include("Capistrano::Measure plugin encountered an error during performance evaluation")
|
36
|
+
end
|
37
|
+
|
38
|
+
it "raises an error in debug mode (and interrupts the deployment)" do
|
39
|
+
config[:measure_error_handling] = :raise
|
40
|
+
|
41
|
+
expect {
|
42
|
+
subject.before_task('root_task')
|
43
|
+
subject.after_task('sub_task')
|
44
|
+
|
45
|
+
subject.print_report
|
46
|
+
}.to raise_error(::Capistrano::Measure::Error)
|
47
|
+
|
23
48
|
end
|
24
49
|
|
25
50
|
describe "::capistrano_version" do
|
@@ -5,25 +5,36 @@ LogItem = Struct.new(:indent, :name, :elapsed_time)
|
|
5
5
|
|
6
6
|
describe Capistrano::Measure::LogReporter do
|
7
7
|
let(:logger) { ::StringLogger.new }
|
8
|
-
|
9
|
-
|
10
|
-
it "should be able to create with default logger" do
|
11
|
-
expect(::Logger).to receive(:new).with(STDOUT)
|
12
|
-
Capistrano::Measure::LogReporter.new
|
13
|
-
end
|
8
|
+
let(:config) { {} }
|
9
|
+
subject { Capistrano::Measure::LogReporter.new(logger, config) }
|
14
10
|
|
15
11
|
describe "#render" do
|
16
12
|
{green: [0, 30], yellow: [31, 60], red: [61, 100]}.each do |color, times|
|
17
13
|
times.each do |elapsed_time|
|
18
14
|
it "should render line with time in #{color} when elapsed time eq #{elapsed_time}" do
|
19
15
|
subject.render([LogItem.new(0, 'test', elapsed_time)])
|
20
|
-
colorized_time = "#{elapsed_time}s".
|
16
|
+
colorized_time = ColorizedString["#{elapsed_time}s"].colorize(color)
|
21
17
|
|
22
18
|
expect(logger.to_s).to include("test #{colorized_time}\n")
|
23
19
|
end
|
24
20
|
end
|
25
21
|
end
|
26
22
|
|
23
|
+
context "with changed thresholds" do
|
24
|
+
let(:config) { { warning_threshold: 20, alert_threshold: 30 } }
|
25
|
+
|
26
|
+
{green: [0, 20], yellow: [21, 30], red: [31, 100]}.each do |color, times|
|
27
|
+
times.each do |elapsed_time|
|
28
|
+
it "should render line with time in #{color} when elapsed time eq #{elapsed_time}" do
|
29
|
+
subject.render([LogItem.new(0, 'test', elapsed_time)])
|
30
|
+
colorized_time = ColorizedString["#{elapsed_time}s"].colorize(color)
|
31
|
+
|
32
|
+
expect(logger.to_s).to include("test #{colorized_time}\n")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
27
38
|
it "should not render empty report" do
|
28
39
|
subject.render([])
|
29
40
|
expect(logger.to_s).to eq ""
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'capistrano/measure/error'
|
2
3
|
require 'capistrano/measure/timer'
|
3
4
|
|
4
5
|
describe Capistrano::Measure::Timer do
|
@@ -75,14 +76,14 @@ describe Capistrano::Measure::Timer do
|
|
75
76
|
end
|
76
77
|
|
77
78
|
it "should raise exception with unstarted event" do
|
78
|
-
expect{ subject.stop('test123') }.to
|
79
|
+
expect{ subject.stop('test123') }.to raise_error(::Capistrano::Measure::Error)
|
79
80
|
end
|
80
81
|
end
|
81
82
|
|
82
83
|
describe "#report_events" do
|
83
84
|
it "should raise exception if called in the middle of process" do
|
84
85
|
subject.start('test')
|
85
|
-
expect{ subject.report_events }.to
|
86
|
+
expect{ subject.report_events }.to raise_error(::Capistrano::Measure::Error)
|
86
87
|
end
|
87
88
|
|
88
89
|
context "in completed state" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-measure
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artūrs Mekšs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capistrano
|
@@ -31,19 +31,19 @@ dependencies:
|
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '4'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
|
-
name:
|
34
|
+
name: colorize
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- - "
|
37
|
+
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
39
|
+
version: 0.8.1
|
40
40
|
type: :runtime
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- - "
|
44
|
+
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
46
|
+
version: 0.8.1
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: bundler
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -111,6 +111,7 @@ extra_rdoc_files: []
|
|
111
111
|
files:
|
112
112
|
- ".gitignore"
|
113
113
|
- ".rspec"
|
114
|
+
- ".travis.yml"
|
114
115
|
- Gemfile
|
115
116
|
- LICENSE.txt
|
116
117
|
- README.md
|
@@ -119,6 +120,7 @@ files:
|
|
119
120
|
- lib/capistrano-measure.rb
|
120
121
|
- lib/capistrano/measure.rb
|
121
122
|
- lib/capistrano/measure/adapter.rb
|
123
|
+
- lib/capistrano/measure/error.rb
|
122
124
|
- lib/capistrano/measure/integration/capistrano_2.rb
|
123
125
|
- lib/capistrano/measure/integration/capistrano_3.rb
|
124
126
|
- lib/capistrano/measure/log_reporter.rb
|
@@ -149,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
151
|
version: '0'
|
150
152
|
requirements: []
|
151
153
|
rubyforge_project:
|
152
|
-
rubygems_version: 2.
|
154
|
+
rubygems_version: 2.5.1
|
153
155
|
signing_key:
|
154
156
|
specification_version: 4
|
155
157
|
summary: Capistrano deployment speed measure tool
|