poise-profiler 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +60 -16
  3. data/CHANGELOG.md +6 -0
  4. data/Gemfile +1 -1
  5. data/README.md +1 -1
  6. data/lib/poise_profiler.rb +2 -1
  7. data/lib/poise_profiler/base.rb +121 -0
  8. data/lib/poise_profiler/cheftie.rb +4 -20
  9. data/lib/poise_profiler/config.rb +68 -0
  10. data/lib/poise_profiler/core_ext.rb +19 -0
  11. data/lib/poise_profiler/core_ext/cookbook_version.rb +42 -0
  12. data/lib/poise_profiler/core_ext/dispatcher.rb +45 -0
  13. data/lib/poise_profiler/core_ext/event_base.rb +41 -0
  14. data/lib/poise_profiler/core_ext/run_context.rb +53 -0
  15. data/lib/poise_profiler/{handler.rb → timing.rb} +7 -41
  16. data/lib/poise_profiler/version.rb +1 -1
  17. data/test/gemfiles/chef-12.0.gemfile +4 -0
  18. data/test/gemfiles/chef-12.1.gemfile +4 -0
  19. data/test/gemfiles/chef-12.10.gemfile +23 -0
  20. data/test/gemfiles/chef-12.11.gemfile +23 -0
  21. data/test/gemfiles/chef-12.12.gemfile +22 -0
  22. data/test/gemfiles/chef-12.13.gemfile +22 -0
  23. data/test/gemfiles/chef-12.14.gemfile +19 -0
  24. data/test/gemfiles/chef-12.15.gemfile +19 -0
  25. data/test/gemfiles/chef-12.16.gemfile +19 -0
  26. data/test/gemfiles/chef-12.17.gemfile +19 -0
  27. data/test/gemfiles/chef-12.18.gemfile +19 -0
  28. data/test/gemfiles/chef-12.19.gemfile +19 -0
  29. data/test/gemfiles/chef-12.2.gemfile +4 -0
  30. data/test/gemfiles/chef-12.3.gemfile +4 -0
  31. data/test/gemfiles/chef-12.4.gemfile +5 -2
  32. data/test/gemfiles/chef-12.5.gemfile +4 -0
  33. data/test/gemfiles/chef-12.6.gemfile +4 -0
  34. data/test/gemfiles/chef-12.7.gemfile +23 -0
  35. data/test/gemfiles/chef-12.8.gemfile +23 -0
  36. data/test/gemfiles/chef-12.9.gemfile +23 -0
  37. data/test/gemfiles/chef-12.gemfile +1 -1
  38. data/test/gemfiles/chef-13.0.gemfile +19 -0
  39. data/test/gemfiles/chef-13.gemfile +19 -0
  40. data/test/gemfiles/master.gemfile +1 -0
  41. data/test/spec/config_spec.rb +61 -0
  42. data/test/spec/integration_spec.rb +1 -1
  43. data/test/spec/{default_spec.rb → timing_spec.rb} +44 -10
  44. metadata +45 -7
@@ -17,3 +17,7 @@
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
19
  gem 'chef', '~> 12.5.1'
20
+ gem 'rack', '< 2'
21
+ gem 'foodcritic', '< 8'
22
+ gem 'fauxhai', '<= 3.9.0'
23
+ gem 'chefspec', '< 6'
@@ -17,3 +17,7 @@
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
19
  gem 'chef', '~> 12.6.0'
20
+ gem 'rack', '< 2'
21
+ gem 'foodcritic', '< 8'
22
+ gem 'fauxhai', '<= 3.9.0'
23
+ gem 'chefspec', '< 6'
@@ -0,0 +1,23 @@
1
+ #
2
+ # Copyright 2017, 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.7.2'
20
+ gem 'rack', '< 2'
21
+ gem 'foodcritic', '< 8'
22
+ gem 'fauxhai', '<= 3.9.0'
23
+ gem 'chefspec', '< 6'
@@ -0,0 +1,23 @@
1
+ #
2
+ # Copyright 2017, 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.8.1'
20
+ gem 'rack', '< 2'
21
+ gem 'foodcritic', '< 8'
22
+ gem 'fauxhai', '<= 3.9.0'
23
+ gem 'chefspec', '< 6'
@@ -0,0 +1,23 @@
1
+ #
2
+ # Copyright 2017, 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.9.41'
20
+ gem 'rack', '< 2'
21
+ gem 'foodcritic', '< 8'
22
+ gem 'fauxhai', '<= 3.9.0'
23
+ gem 'chefspec', '< 6'
@@ -16,4 +16,4 @@
16
16
 
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
- gem 'chef', '~> 12.6'
19
+ gem 'chef', '~> 12.19'
@@ -0,0 +1,19 @@
1
+ #
2
+ # Copyright 2017, 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', '~> 13.0.113'
@@ -0,0 +1,19 @@
1
+ #
2
+ # Copyright 2017, 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', '~> 13.0'
@@ -18,4 +18,5 @@ eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
19
  gem 'chef', github: 'chef/chef'
20
20
  gem 'halite', github: 'poise/halite'
21
+ gem 'ohai', github: 'chef/ohai'
21
22
  # gem 'poise-boiler', github: 'poise/poise-boiler'
@@ -0,0 +1,61 @@
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
+
19
+ describe PoiseProfiler::Config do
20
+ subject { described_class.new }
21
+ around do |ex|
22
+ old_env = ENV.to_h
23
+ ENV.delete_if {|key, value| key.downcase.start_with?('poise') }
24
+ begin
25
+ ex.run
26
+ ensure
27
+ ENV.clear
28
+ ENV.update(old_env)
29
+ end
30
+ end
31
+ before do
32
+ if defined?(Chef.node)
33
+ Chef.set_node(chef_run.node)
34
+ end
35
+ end
36
+
37
+ context 'with $POISE_PROFILER_OPTION' do
38
+ before { ENV['POISE_PROFILER_OPTION'] = 'value' }
39
+ its([:option]) { is_expected.to eq 'value' }
40
+ end # /context with $POISE_PROFILER_OPTION
41
+
42
+ context 'with $POISE_PROFILER_OPTION=true' do
43
+ before { ENV['POISE_PROFILER_OPTION'] = 'true' }
44
+ its([:option]) { is_expected.to be true }
45
+ end # /context with $POISE_PROFILER_OPTION=true
46
+
47
+ context 'with $POISE_PROFILER_OPTION=1' do
48
+ before { ENV['POISE_PROFILER_OPTION'] = '1' }
49
+ its([:option]) { is_expected.to eq 1 }
50
+ end # /context with $POISE_PROFILER_OPTION=1
51
+
52
+ # Attribute config is only supported when the global node is available.
53
+ if defined?(Chef.node)
54
+ context 'with node attributes' do
55
+ let(:default_attributes) do
56
+ {'poise-profiler' => {'option' => 'value'}}
57
+ end
58
+ its([:option]) { is_expected.to eq 'value' }
59
+ end # /context with node attributes
60
+ end
61
+ end
@@ -26,6 +26,6 @@ describe 'integration', if: ENV['TRAVIS_SECURE_ENV_VARS'] do
26
26
  it do
27
27
  # Don't run this extra times.
28
28
  expect(subject.exitstatus).to eq 0
29
- expect(subject.stdout).to include 'Poise Profiler:'
29
+ expect(subject.stdout).to include 'Poise Profiler Timing:'
30
30
  end
31
31
  end
@@ -26,7 +26,7 @@ end
26
26
  class DummyError < RuntimeError
27
27
  end
28
28
 
29
- describe 'cheftie' do
29
+ describe PoiseProfiler::Timing do
30
30
  step_into(:ruby_block)
31
31
  let(:output) { [] }
32
32
  let(:events) { chef_runner.send(:client).events }
@@ -48,14 +48,21 @@ describe 'cheftie' do
48
48
  # Divert log output for analysis.
49
49
  _output = output
50
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!
51
+ # Re-set-up the handler. Also clears internal state to be safe.
52
+ described_class.install!
53
+ end
54
+ around do |ex|
55
+ old_env = ENV.to_h
56
+ begin
57
+ ex.run
58
+ ensure
59
+ ENV.clear
60
+ ENV.update(old_env)
55
61
  end
56
62
  end
57
63
 
58
64
  context 'with a single resource' do
65
+ before { ENV['CI'] = 'true' }
59
66
  recipe(subject: false) do
60
67
  ruby_block 'test' do
61
68
  block { }
@@ -64,7 +71,7 @@ describe 'cheftie' do
64
71
 
65
72
  it do
66
73
  is_expected.to match(
67
- %r{\APoise Profiler:
74
+ %r{\APoise Profiler Timing:
68
75
  Time Resource
69
76
  ------------ -------------
70
77
  \s*([\d.]+) ruby_block\[test\]
@@ -79,6 +86,7 @@ Profiler JSON: \{.*?\}
79
86
  end # /context with a single resource
80
87
 
81
88
  context 'with a failed run' do
89
+ before { ENV['CI'] = 'true' }
82
90
  recipe(subject: false) do
83
91
  ruby_block 'test' do
84
92
  block { raise DummyError }
@@ -94,7 +102,7 @@ Profiler JSON: \{.*?\}
94
102
 
95
103
  it do
96
104
  is_expected.to match(
97
- %r{\APoise Profiler:
105
+ %r{\APoise Profiler Timing:
98
106
  Time Resource
99
107
  ------------ -------------
100
108
  \s*([\d.]+) ruby_block\[test\]
@@ -109,6 +117,7 @@ Profiler JSON: \{.*?\}
109
117
  end # /context with a failed run
110
118
 
111
119
  context 'with two resources' do
120
+ before { ENV['CI'] = 'true' }
112
121
  recipe(subject: false) do
113
122
  ruby_block 'test' do
114
123
  block { }
@@ -120,7 +129,7 @@ Profiler JSON: \{.*?\}
120
129
 
121
130
  it do
122
131
  is_expected.to match(
123
- %r{\APoise Profiler:
132
+ %r{\APoise Profiler Timing:
124
133
  Time Resource
125
134
  ------------ -------------
126
135
  \s*([\d.]+) ruby_block\[test2\]
@@ -137,6 +146,7 @@ Profiler JSON: \{.*?\}
137
146
  end # /context with two resources
138
147
 
139
148
  context 'with inner resources' do
149
+ before { ENV['CI'] = 'true' }
140
150
  resource(:my_resource, unwrap_notifying_block: false)
141
151
  provider(:my_resource) do
142
152
  include Poise
@@ -155,7 +165,7 @@ Profiler JSON: \{.*?\}
155
165
 
156
166
  it do
157
167
  is_expected.to match(
158
- %r{\APoise Profiler:
168
+ %r{\APoise Profiler Timing:
159
169
  Time Resource
160
170
  ------------ -------------
161
171
  \s*([\d.]+) my_resource\[test\]
@@ -174,6 +184,7 @@ Profiler JSON: \{.*?\}
174
184
  end # /context with inner resources
175
185
 
176
186
  context 'with test resources' do
187
+ before { ENV['CI'] = 'true' }
177
188
  resource(:poise_test, unwrap_notifying_block: false)
178
189
  provider(:poise_test) do
179
190
  include Poise
@@ -192,7 +203,7 @@ Profiler JSON: \{.*?\}
192
203
 
193
204
  it do
194
205
  is_expected.to match(
195
- %r{\APoise Profiler:
206
+ %r{\APoise Profiler Timing:
196
207
  Time Resource
197
208
  ------------ -------------
198
209
  \s*([\d.]+) ruby_block\[test\]
@@ -212,4 +223,27 @@ Profiler JSON: \{.*?\}
212
223
  expect($2).to eq $3
213
224
  end
214
225
  end # /context with test resources
226
+
227
+ context 'without $CI' do
228
+ before { ENV.delete('CI') }
229
+ recipe(subject: false) do
230
+ ruby_block 'test' do
231
+ block { }
232
+ end
233
+ end
234
+
235
+ it do
236
+ is_expected.to match(
237
+ %r{\APoise Profiler Timing:
238
+ Time Resource
239
+ ------------ -------------
240
+ \s*([\d.]+) ruby_block\[test\]
241
+
242
+ Time Class
243
+ ------------ -------------
244
+ \s*([\d.]+) Chef::Resource::RubyBlock
245
+
246
+ \Z})
247
+ end
248
+ end # /context without $CI
215
249
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poise-profiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noah Kantrowitz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-29 00:00:00.000000000 Z
11
+ date: 2017-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: halite
@@ -83,8 +83,15 @@ files:
83
83
  - Rakefile
84
84
  - chef/recipes/default.rb
85
85
  - lib/poise_profiler.rb
86
+ - lib/poise_profiler/base.rb
86
87
  - lib/poise_profiler/cheftie.rb
87
- - lib/poise_profiler/handler.rb
88
+ - lib/poise_profiler/config.rb
89
+ - lib/poise_profiler/core_ext.rb
90
+ - lib/poise_profiler/core_ext/cookbook_version.rb
91
+ - lib/poise_profiler/core_ext/dispatcher.rb
92
+ - lib/poise_profiler/core_ext/event_base.rb
93
+ - lib/poise_profiler/core_ext/run_context.rb
94
+ - lib/poise_profiler/timing.rb
88
95
  - lib/poise_profiler/version.rb
89
96
  - poise-profiler.gemspec
90
97
  - test/cookbook/metadata.rb
@@ -93,16 +100,32 @@ files:
93
100
  - test/docker/docker.pem
94
101
  - test/gemfiles/chef-12.0.gemfile
95
102
  - test/gemfiles/chef-12.1.gemfile
103
+ - test/gemfiles/chef-12.10.gemfile
104
+ - test/gemfiles/chef-12.11.gemfile
105
+ - test/gemfiles/chef-12.12.gemfile
106
+ - test/gemfiles/chef-12.13.gemfile
107
+ - test/gemfiles/chef-12.14.gemfile
108
+ - test/gemfiles/chef-12.15.gemfile
109
+ - test/gemfiles/chef-12.16.gemfile
110
+ - test/gemfiles/chef-12.17.gemfile
111
+ - test/gemfiles/chef-12.18.gemfile
112
+ - test/gemfiles/chef-12.19.gemfile
96
113
  - test/gemfiles/chef-12.2.gemfile
97
114
  - test/gemfiles/chef-12.3.gemfile
98
115
  - test/gemfiles/chef-12.4.gemfile
99
116
  - test/gemfiles/chef-12.5.gemfile
100
117
  - test/gemfiles/chef-12.6.gemfile
118
+ - test/gemfiles/chef-12.7.gemfile
119
+ - test/gemfiles/chef-12.8.gemfile
120
+ - test/gemfiles/chef-12.9.gemfile
101
121
  - test/gemfiles/chef-12.gemfile
122
+ - test/gemfiles/chef-13.0.gemfile
123
+ - test/gemfiles/chef-13.gemfile
102
124
  - test/gemfiles/master.gemfile
103
- - test/spec/default_spec.rb
125
+ - test/spec/config_spec.rb
104
126
  - test/spec/integration_spec.rb
105
127
  - test/spec/spec_helper.rb
128
+ - test/spec/timing_spec.rb
106
129
  homepage: https://github.com/poise/poise-profiler
107
130
  licenses:
108
131
  - Apache 2.0
@@ -123,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
146
  version: '0'
124
147
  requirements: []
125
148
  rubyforge_project:
126
- rubygems_version: 2.6.2
149
+ rubygems_version: 2.6.11
127
150
  signing_key:
128
151
  specification_version: 4
129
152
  summary: A Chef cookbook for profiling performance in CI.
@@ -134,14 +157,29 @@ test_files:
134
157
  - test/docker/docker.pem
135
158
  - test/gemfiles/chef-12.0.gemfile
136
159
  - test/gemfiles/chef-12.1.gemfile
160
+ - test/gemfiles/chef-12.10.gemfile
161
+ - test/gemfiles/chef-12.11.gemfile
162
+ - test/gemfiles/chef-12.12.gemfile
163
+ - test/gemfiles/chef-12.13.gemfile
164
+ - test/gemfiles/chef-12.14.gemfile
165
+ - test/gemfiles/chef-12.15.gemfile
166
+ - test/gemfiles/chef-12.16.gemfile
167
+ - test/gemfiles/chef-12.17.gemfile
168
+ - test/gemfiles/chef-12.18.gemfile
169
+ - test/gemfiles/chef-12.19.gemfile
137
170
  - test/gemfiles/chef-12.2.gemfile
138
171
  - test/gemfiles/chef-12.3.gemfile
139
172
  - test/gemfiles/chef-12.4.gemfile
140
173
  - test/gemfiles/chef-12.5.gemfile
141
174
  - test/gemfiles/chef-12.6.gemfile
175
+ - test/gemfiles/chef-12.7.gemfile
176
+ - test/gemfiles/chef-12.8.gemfile
177
+ - test/gemfiles/chef-12.9.gemfile
142
178
  - test/gemfiles/chef-12.gemfile
179
+ - test/gemfiles/chef-13.0.gemfile
180
+ - test/gemfiles/chef-13.gemfile
143
181
  - test/gemfiles/master.gemfile
144
- - test/spec/default_spec.rb
182
+ - test/spec/config_spec.rb
145
183
  - test/spec/integration_spec.rb
146
184
  - test/spec/spec_helper.rb
147
- has_rdoc:
185
+ - test/spec/timing_spec.rb