poise-profiler 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,19 @@
1
+ #
2
+ # Copyright 2016, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', '~> 12.6.0'
@@ -0,0 +1,19 @@
1
+ #
2
+ # Copyright 2016, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', '~> 12.6'
@@ -0,0 +1,21 @@
1
+ #
2
+ # Copyright 2016, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', github: 'chef/chef'
20
+ gem 'halite', github: 'poise/halite'
21
+ # gem 'poise-boiler', github: 'poise/poise-boiler'
@@ -0,0 +1,215 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'spec_helper'
18
+ require 'poise'
19
+
20
+ # Monkey-patch this in for Chef pre-12.4.
21
+ class Chef::EventDispatch::Dispatcher
22
+ attr_reader :subscribers
23
+ end
24
+
25
+ # Dummy error to use below.
26
+ class DummyError < RuntimeError
27
+ end
28
+
29
+ describe 'cheftie' do
30
+ step_into(:ruby_block)
31
+ let(:output) { [] }
32
+ let(:events) { chef_runner.send(:client).events }
33
+ let(:wrapped_chef_run) do
34
+ # Force the complete/failed events to trigger because ChefSpec doesn't
35
+ # normally run them.
36
+ begin
37
+ events.library_file_loaded(nil)
38
+ chef_run
39
+ rescue Exception => ex
40
+ events.run_failed(ex)
41
+ raise unless ex.is_a?(DummyError)
42
+ else
43
+ events.run_completed(chef_run.node)
44
+ end
45
+ end
46
+ subject { wrapped_chef_run; output.join('') }
47
+ before do
48
+ # Divert log output for analysis.
49
+ _output = output
50
+ allow(events).to receive(:stream_output) {|tag, line| _output << line }
51
+ # Clear the handler's internal state.
52
+ PoiseProfiler::Handler.instance.reset!
53
+ if Gem::Version.create(Chef::VERSION) <= Gem::Version.create('12.2.1')
54
+ PoiseProfiler::Handler.instance.monkey_patch_old_chef!
55
+ end
56
+ end
57
+
58
+ context 'with a single resource' do
59
+ recipe(subject: false) do
60
+ ruby_block 'test' do
61
+ block { }
62
+ end
63
+ end
64
+
65
+ it do
66
+ is_expected.to match(
67
+ %r{\APoise Profiler:
68
+ Time Resource
69
+ ------------ -------------
70
+ \s*([\d.]+) ruby_block\[test\]
71
+
72
+ Time Class
73
+ ------------ -------------
74
+ \s*([\d.]+) Chef::Resource::RubyBlock
75
+
76
+ Profiler JSON: \{.*?\}
77
+ \Z})
78
+ end
79
+ end # /context with a single resource
80
+
81
+ context 'with a failed run' do
82
+ recipe(subject: false) do
83
+ ruby_block 'test' do
84
+ block { raise DummyError }
85
+ end
86
+ ruby_block 'test2' do
87
+ block { }
88
+ end
89
+ end
90
+ before do
91
+ # Suppress the normal formatter output for errors.
92
+ events.subscribers.reject! {|s| (s.respond_to?(:is_formatter?) && s.is_formatter?) || s.is_a?(Chef::Formatters::Base) }
93
+ end
94
+
95
+ it do
96
+ is_expected.to match(
97
+ %r{\APoise Profiler:
98
+ Time Resource
99
+ ------------ -------------
100
+ \s*([\d.]+) ruby_block\[test\]
101
+
102
+ Time Class
103
+ ------------ -------------
104
+ \s*([\d.]+) Chef::Resource::RubyBlock
105
+
106
+ Profiler JSON: \{.*?\}
107
+ \Z})
108
+ end
109
+ end # /context with a failed run
110
+
111
+ context 'with two resources' do
112
+ recipe(subject: false) do
113
+ ruby_block 'test' do
114
+ block { }
115
+ end
116
+ ruby_block 'test2' do
117
+ block { sleep(0.1) }
118
+ end
119
+ end
120
+
121
+ it do
122
+ is_expected.to match(
123
+ %r{\APoise Profiler:
124
+ Time Resource
125
+ ------------ -------------
126
+ \s*([\d.]+) ruby_block\[test2\]
127
+ \s*([\d.]+) ruby_block\[test\]
128
+
129
+ Time Class
130
+ ------------ -------------
131
+ \s*([\d.]+) Chef::Resource::RubyBlock
132
+
133
+ Profiler JSON: \{.*?\}
134
+ \Z})
135
+ expect($1.to_f + $2.to_f).to eq $3.to_f
136
+ end
137
+ end # /context with two resources
138
+
139
+ context 'with inner resources' do
140
+ resource(:my_resource, unwrap_notifying_block: false)
141
+ provider(:my_resource) do
142
+ include Poise
143
+
144
+ def action_run
145
+ notifying_block do
146
+ ruby_block 'test' do
147
+ block { }
148
+ end
149
+ end
150
+ end
151
+ end
152
+ recipe(subject: false) do
153
+ my_resource 'test'
154
+ end
155
+
156
+ it do
157
+ is_expected.to match(
158
+ %r{\APoise Profiler:
159
+ Time Resource
160
+ ------------ -------------
161
+ \s*([\d.]+) my_resource\[test\]
162
+ \s*([\d.]+) ruby_block\[test\]
163
+
164
+ Time Class
165
+ ------------ -------------
166
+ \s*([\d.]+) Chef::Resource::MyResource
167
+ \s*([\d.]+) Chef::Resource::RubyBlock
168
+
169
+ Profiler JSON: \{.*?\}
170
+ \Z})
171
+ expect($1).to eq $3
172
+ expect($2).to eq $4
173
+ end
174
+ end # /context with inner resources
175
+
176
+ context 'with test resources' do
177
+ resource(:poise_test, unwrap_notifying_block: false)
178
+ provider(:poise_test) do
179
+ include Poise
180
+
181
+ def action_run
182
+ notifying_block do
183
+ ruby_block 'test' do
184
+ block { }
185
+ end
186
+ end
187
+ end
188
+ end
189
+ recipe(subject: false) do
190
+ poise_test 'test'
191
+ end
192
+
193
+ it do
194
+ is_expected.to match(
195
+ %r{\APoise Profiler:
196
+ Time Resource
197
+ ------------ -------------
198
+ \s*([\d.]+) ruby_block\[test\]
199
+
200
+ Time Test Resource
201
+ ------------ -------------
202
+ \s*([\d.]+) poise_test\[test\]
203
+
204
+ Time Class
205
+ ------------ -------------
206
+ \s*([\d.]+) Chef::Resource::PoiseTest
207
+ \s*([\d.]+) Chef::Resource::RubyBlock
208
+
209
+ Profiler JSON: \{.*?\}
210
+ \Z})
211
+ expect($1).to eq $4
212
+ expect($2).to eq $3
213
+ end
214
+ end # /context with test resources
215
+ end
@@ -0,0 +1,31 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'spec_helper'
18
+ require 'mixlib/shellout'
19
+
20
+ # Only run these tests on Travis because otherwise slow and annoying.
21
+ describe 'integration', if: ENV['TRAVIS_SECURE_ENV_VARS'] do
22
+ subject do
23
+ Mixlib::ShellOut.new('rake travis:integration', cwd: File.expand_path('../../..', __FILE__)).tap(&:run_command)
24
+ end
25
+
26
+ it do
27
+ # Don't run this extra times.
28
+ expect(subject.exitstatus).to eq 0
29
+ expect(subject.stdout).to include 'Poise Profiler:'
30
+ end
31
+ end
@@ -0,0 +1,19 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'poise_boiler/spec_helper'
18
+ require 'poise_profiler'
19
+ require 'poise_profiler/cheftie'
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: poise-profiler
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Noah Kantrowitz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: halite
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mixlib-shellout
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: poise
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: poise-boiler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ description: A Chef cookbook for profiling performance in CI.
70
+ email:
71
+ - noah@coderanger.net
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".kitchen.yml"
78
+ - ".travis.yml"
79
+ - CHANGELOG.md
80
+ - Gemfile
81
+ - LICENSE
82
+ - README.md
83
+ - Rakefile
84
+ - chef/recipes/default.rb
85
+ - lib/poise_profiler.rb
86
+ - lib/poise_profiler/cheftie.rb
87
+ - lib/poise_profiler/handler.rb
88
+ - lib/poise_profiler/version.rb
89
+ - poise-profiler.gemspec
90
+ - test/cookbook/metadata.rb
91
+ - test/cookbook/recipes/default.rb
92
+ - test/docker/docker.ca
93
+ - test/docker/docker.pem
94
+ - test/gemfiles/chef-12.0.gemfile
95
+ - test/gemfiles/chef-12.1.gemfile
96
+ - test/gemfiles/chef-12.2.gemfile
97
+ - test/gemfiles/chef-12.3.gemfile
98
+ - test/gemfiles/chef-12.4.gemfile
99
+ - test/gemfiles/chef-12.5.gemfile
100
+ - test/gemfiles/chef-12.6.gemfile
101
+ - test/gemfiles/chef-12.gemfile
102
+ - test/gemfiles/master.gemfile
103
+ - test/spec/default_spec.rb
104
+ - test/spec/integration_spec.rb
105
+ - test/spec/spec_helper.rb
106
+ homepage: https://github.com/poise/poise-profiler
107
+ licenses:
108
+ - Apache 2.0
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.4.8
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: A Chef cookbook for profiling performance in CI.
130
+ test_files:
131
+ - test/cookbook/metadata.rb
132
+ - test/cookbook/recipes/default.rb
133
+ - test/docker/docker.ca
134
+ - test/docker/docker.pem
135
+ - test/gemfiles/chef-12.0.gemfile
136
+ - test/gemfiles/chef-12.1.gemfile
137
+ - test/gemfiles/chef-12.2.gemfile
138
+ - test/gemfiles/chef-12.3.gemfile
139
+ - test/gemfiles/chef-12.4.gemfile
140
+ - test/gemfiles/chef-12.5.gemfile
141
+ - test/gemfiles/chef-12.6.gemfile
142
+ - test/gemfiles/chef-12.gemfile
143
+ - test/gemfiles/master.gemfile
144
+ - test/spec/default_spec.rb
145
+ - test/spec/integration_spec.rb
146
+ - test/spec/spec_helper.rb
147
+ has_rdoc: