chef-apply 0.4.12 → 0.4.13
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.
- checksums.yaml +4 -4
- data/chef-apply.gemspec +1 -1
- data/lib/chef_apply/action/base.rb +1 -1
- data/lib/chef_apply/cli.rb +5 -7
- data/lib/chef_apply/startup.rb +9 -2
- data/lib/chef_apply/telemeter.rb +8 -130
- data/lib/chef_apply/telemeter/patch.rb +1 -1
- data/lib/chef_apply/version.rb +1 -1
- metadata +6 -7
- data/lib/chef_apply/telemeter/sender.rb +0 -121
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40458ce08a16fb6db8c58202ac973c791d653be6b32700a493779ba1ff540dd2
|
4
|
+
data.tar.gz: 68a27c1c83e4009fb29b2fc355091f52bb23f25ea3465069e278982db67b353f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da9d028ca6b0033430f5c8740a1f6c6317eff7331e59ad48d0e198f2fca2f905cb3ea9fa482d0c4366003028bcc5e301cc0c994adfba621ed487637a7348b50a
|
7
|
+
data.tar.gz: aab2c0073c5e20a56045b750044964d336b84da4d2e36085c2efc13386a24d7631d9c8fc2e75a2018189cb694f0adb3779225b5ebab70b892dfaac508e2af632
|
data/chef-apply.gemspec
CHANGED
@@ -54,7 +54,7 @@ Gem::Specification.new do |spec|
|
|
54
54
|
spec.add_dependency "tty-spinner" # Pretty output for status updates in the CLI
|
55
55
|
spec.add_dependency "chef", ">= 15.0" # Needed to load cookbooks
|
56
56
|
spec.add_dependency "chef-cli", ">= 1.0.3 " # Policyfile
|
57
|
-
spec.add_dependency "chef-telemetry", "
|
57
|
+
spec.add_dependency "chef-telemetry", ">= 1.0.2"
|
58
58
|
spec.add_dependency "license-acceptance", "~> 1.0", ">= 1.0.11"
|
59
59
|
|
60
60
|
spec.add_development_dependency "bundler"
|
data/lib/chef_apply/cli.rb
CHANGED
@@ -65,22 +65,20 @@ module ChefApply
|
|
65
65
|
|
66
66
|
def run
|
67
67
|
# Perform a timing and capture of the run. Individual methods and actions may perform
|
68
|
-
# nested Telemeter.timed_*_capture or Telemeter.capture calls in their operation, and
|
68
|
+
# nested Chef::Telemeter.timed_*_capture or Chef::Telemeter.capture calls in their operation, and
|
69
69
|
# they will be captured in the same telemetry session.
|
70
|
-
|
71
|
-
|
72
|
-
# passwords in host name, or in ad-hoc converge properties.
|
73
|
-
Telemeter.timed_run_capture([:redacted]) do
|
70
|
+
|
71
|
+
Chef::Telemeter.timed_run_capture([:redacted]) do
|
74
72
|
begin
|
75
73
|
perform_run
|
76
74
|
rescue Exception => e
|
77
75
|
@rc = handle_run_error(e)
|
78
76
|
end
|
79
77
|
end
|
80
|
-
rescue => e
|
78
|
+
rescue => e # can occur if exception thrown in error handling
|
81
79
|
@rc = handle_run_error(e)
|
82
80
|
ensure
|
83
|
-
Telemeter.commit
|
81
|
+
Chef::Telemeter.commit
|
84
82
|
exit @rc
|
85
83
|
end
|
86
84
|
|
data/lib/chef_apply/startup.rb
CHANGED
@@ -17,7 +17,7 @@
|
|
17
17
|
require "chef_apply/config"
|
18
18
|
require "chef_apply/text"
|
19
19
|
require "chef_apply/ui/terminal"
|
20
|
-
require "chef_apply/telemeter
|
20
|
+
require "chef_apply/telemeter"
|
21
21
|
require "chef/log"
|
22
22
|
require "chef/config"
|
23
23
|
module ChefApply
|
@@ -130,7 +130,14 @@ module ChefApply
|
|
130
130
|
end
|
131
131
|
|
132
132
|
def start_telemeter_upload
|
133
|
-
|
133
|
+
cfg = {
|
134
|
+
enabled: Config.telemetry[:enabled],
|
135
|
+
dev: Config.telemetry[:dev_mode],
|
136
|
+
payload_dir: Config.telemetry_path,
|
137
|
+
installation_identifier_file: Config.telemetry_installation_identifier_file,
|
138
|
+
session_file: Config.telemetry_session_file,
|
139
|
+
}
|
140
|
+
Chef::Telemeter.setup(cfg)
|
134
141
|
end
|
135
142
|
|
136
143
|
def setup_workstation_user_directories
|
data/lib/chef_apply/telemeter.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#
|
2
|
-
# Copyright:: Copyright (c) 2018 Chef Software Inc.
|
2
|
+
# Copyright:: Copyright (c) 2018-2019 Chef Software Inc.
|
3
|
+
# Author:: Marc A. Paradise <marc.paradise@gmail.com>
|
3
4
|
# License:: Apache License, Version 2.0
|
4
5
|
#
|
5
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -13,48 +14,14 @@
|
|
13
14
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
15
|
# See the License for the specific language governing permissions and
|
15
16
|
# limitations under the License.
|
16
|
-
#
|
17
|
-
|
18
|
-
require "benchmark"
|
19
|
-
require "forwardable"
|
20
|
-
require "singleton"
|
21
|
-
require "json"
|
22
|
-
require "digest/sha1"
|
23
|
-
require "securerandom"
|
24
|
-
require "chef_apply/version"
|
25
|
-
require "chef_apply/config"
|
26
|
-
require "yaml"
|
27
17
|
|
18
|
+
require "chef/telemeter"
|
19
|
+
# Monkey patch the telemetry lib to respect our config.toml
|
20
|
+
# entry for telemetry.
|
21
|
+
require "chef_apply/telemeter/patch"
|
28
22
|
module ChefApply
|
29
|
-
|
30
|
-
# This definites the Telemeter interface. Implementation thoughts for
|
31
|
-
# when we unstub it:
|
32
|
-
# - let's track the call sequence; most of our calls will be nested inside
|
33
|
-
# a main 'timed_capture', and it would be good to see ordering within nested calls.
|
34
23
|
class Telemeter
|
35
|
-
|
36
|
-
DEFAULT_INSTALLATION_GUID = "00000000-0000-0000-0000-000000000000".freeze
|
37
|
-
|
38
|
-
class << self
|
39
|
-
extend Forwardable
|
40
|
-
def_delegators :instance, :timed_capture, :capture, :commit, :timed_action_capture, :timed_run_capture
|
41
|
-
def_delegators :instance, :pending_event_count, :last_event, :enabled?
|
42
|
-
def_delegators :instance, :make_event_payload
|
43
|
-
end
|
44
|
-
|
45
|
-
attr_reader :events_to_send, :run_timestamp
|
46
|
-
|
47
|
-
def enabled?
|
48
|
-
require "telemetry/decision"
|
49
|
-
ChefApply::Config.telemetry.enable && !Telemetry::Decision.env_opt_out?
|
50
|
-
end
|
51
|
-
|
52
|
-
def initialize
|
53
|
-
@events_to_send = []
|
54
|
-
@run_timestamp = Time.now.utc.strftime("%FT%TZ")
|
55
|
-
end
|
56
|
-
|
57
|
-
def timed_action_capture(action, &block)
|
24
|
+
def self.timed_action_capture(action, &block)
|
58
25
|
# Note: we do not directly capture hostname for privacy concerns, but
|
59
26
|
# using a sha1 digest will allow us to anonymously see
|
60
27
|
# unique hosts to derive number of hosts affected by a command
|
@@ -67,96 +34,7 @@ module ChefApply
|
|
67
34
|
target_data[:hostname_sha1] = Digest::SHA1.hexdigest(target.hostname.downcase)
|
68
35
|
target_data[:transport_type] = target.transport_type
|
69
36
|
end
|
70
|
-
timed_capture(:action, { action: action.name, target: target_data }, &block)
|
71
|
-
end
|
72
|
-
|
73
|
-
def timed_run_capture(arguments, &block)
|
74
|
-
timed_capture(:run, arguments: arguments, &block)
|
75
|
-
end
|
76
|
-
|
77
|
-
def capture(name, data = {})
|
78
|
-
# Adding it to the head of the list will ensure that the
|
79
|
-
# sequence of events is preserved when we send the final payload
|
80
|
-
payload = make_event_payload(name, data)
|
81
|
-
@events_to_send.unshift payload
|
82
|
-
end
|
83
|
-
|
84
|
-
def timed_capture(name, data = {})
|
85
|
-
time = Benchmark.measure { yield }
|
86
|
-
data[:duration] = time.real
|
87
|
-
capture(name, data)
|
88
|
-
end
|
89
|
-
|
90
|
-
def commit
|
91
|
-
if enabled?
|
92
|
-
session = convert_events_to_session
|
93
|
-
write_session(session)
|
94
|
-
end
|
95
|
-
@events_to_send = []
|
37
|
+
Chef::Telemeter.timed_capture(:action, { action: action.name, target: target_data }, &block)
|
96
38
|
end
|
97
|
-
|
98
|
-
def make_event_payload(name, data)
|
99
|
-
{
|
100
|
-
event: name,
|
101
|
-
properties: {
|
102
|
-
installation_id: installation_id,
|
103
|
-
run_timestamp: run_timestamp,
|
104
|
-
host_platform: host_platform,
|
105
|
-
event_data: data,
|
106
|
-
},
|
107
|
-
}
|
108
|
-
end
|
109
|
-
|
110
|
-
def installation_id
|
111
|
-
@installation_id ||=
|
112
|
-
begin
|
113
|
-
File.read(ChefApply::Config.telemetry_installation_identifier_file).chomp
|
114
|
-
rescue
|
115
|
-
ChefApply::Log.info "could not read #{ChefApply::Config.telemetry_installation_identifier_file} - using default id"
|
116
|
-
DEFAULT_INSTALLATION_GUID
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
# For testing.
|
121
|
-
def pending_event_count
|
122
|
-
@events_to_send.length
|
123
|
-
end
|
124
|
-
|
125
|
-
def last_event
|
126
|
-
@events_to_send.last
|
127
|
-
end
|
128
|
-
|
129
|
-
private
|
130
|
-
|
131
|
-
def host_platform
|
132
|
-
@host_platform ||= case RUBY_PLATFORM
|
133
|
-
when /mswin|mingw|windows/
|
134
|
-
"windows"
|
135
|
-
else
|
136
|
-
RUBY_PLATFORM.split("-")[1]
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
def convert_events_to_session
|
141
|
-
YAML.dump({ "version" => ChefApply::VERSION,
|
142
|
-
"entries" => @events_to_send })
|
143
|
-
end
|
144
|
-
|
145
|
-
def write_session(session)
|
146
|
-
File.write(next_filename, convert_events_to_session)
|
147
|
-
end
|
148
|
-
|
149
|
-
def next_filename
|
150
|
-
id = 0
|
151
|
-
filename = ""
|
152
|
-
loop do
|
153
|
-
id += 1
|
154
|
-
filename = File.join(ChefApply::Config.telemetry_path,
|
155
|
-
"telemetry-payload-#{id}.yml")
|
156
|
-
break unless File.exist?(filename)
|
157
|
-
end
|
158
|
-
filename
|
159
|
-
end
|
160
|
-
|
161
39
|
end
|
162
40
|
end
|
data/lib/chef_apply/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-apply
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chef Software, Inc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mixlib-cli
|
@@ -182,16 +182,16 @@ dependencies:
|
|
182
182
|
name: chef-telemetry
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
184
184
|
requirements:
|
185
|
-
- - "
|
185
|
+
- - ">="
|
186
186
|
- !ruby/object:Gem::Version
|
187
|
-
version: 0.
|
187
|
+
version: 1.0.2
|
188
188
|
type: :runtime
|
189
189
|
prerelease: false
|
190
190
|
version_requirements: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
|
-
- - "
|
192
|
+
- - ">="
|
193
193
|
- !ruby/object:Gem::Version
|
194
|
-
version: 0.
|
194
|
+
version: 1.0.2
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
196
|
name: license-acceptance
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|
@@ -269,7 +269,6 @@ files:
|
|
269
269
|
- lib/chef_apply/target_resolver.rb
|
270
270
|
- lib/chef_apply/telemeter.rb
|
271
271
|
- lib/chef_apply/telemeter/patch.rb
|
272
|
-
- lib/chef_apply/telemeter/sender.rb
|
273
272
|
- lib/chef_apply/text.rb
|
274
273
|
- lib/chef_apply/text/error_translation.rb
|
275
274
|
- lib/chef_apply/text/text_wrapper.rb
|
@@ -1,121 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright:: Copyright (c) 2018 Chef Software Inc.
|
3
|
-
# License:: Apache License, Version 2.0
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
#
|
17
|
-
|
18
|
-
require "telemetry"
|
19
|
-
require "chef_apply/telemeter"
|
20
|
-
require "chef_apply/telemeter/patch"
|
21
|
-
require "chef_apply/log"
|
22
|
-
require "chef_apply/version"
|
23
|
-
|
24
|
-
module ChefApply
|
25
|
-
class Telemeter
|
26
|
-
class Sender
|
27
|
-
attr_reader :session_files
|
28
|
-
|
29
|
-
def self.start_upload_thread
|
30
|
-
# Find the files before we spawn the thread - otherwise
|
31
|
-
# we may accidentally pick up the current run's session file if it
|
32
|
-
# finishes before the thread scans for new files
|
33
|
-
session_files = Sender.find_session_files
|
34
|
-
sender = Sender.new(session_files)
|
35
|
-
Thread.new { sender.run }
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.find_session_files
|
39
|
-
ChefApply::Log.info("Looking for telemetry data to submit")
|
40
|
-
session_search = File.join(ChefApply::Config.telemetry_path, "telemetry-payload-*.yml")
|
41
|
-
session_files = Dir.glob(session_search)
|
42
|
-
ChefApply::Log.info("Found #{session_files.length} sessions to submit")
|
43
|
-
session_files
|
44
|
-
end
|
45
|
-
|
46
|
-
def initialize(session_files)
|
47
|
-
@session_files = session_files
|
48
|
-
end
|
49
|
-
|
50
|
-
def run
|
51
|
-
if ChefApply::Telemeter.enabled?
|
52
|
-
ChefApply::Log.info("Telemetry enabled, beginning upload of previous session(s)")
|
53
|
-
# dev mode telemetry gets sent to a different location
|
54
|
-
if ChefApply::Config.telemetry.dev
|
55
|
-
ENV["CHEF_TELEMETRY_ENDPOINT"] ||= "https://telemetry-acceptance.chef.io"
|
56
|
-
end
|
57
|
-
session_files.each { |path| process_session(path) }
|
58
|
-
else
|
59
|
-
# If telemetry is not enabled, just clean up and return. Even though
|
60
|
-
# the telemetry gem will not send if disabled, log output saying that we're submitting
|
61
|
-
# it when it has been disabled can be alarming.
|
62
|
-
ChefApply::Log.info("Telemetry disabled, clearing any existing session captures without sending them.")
|
63
|
-
session_files.each { |path| FileUtils.rm_rf(path) }
|
64
|
-
end
|
65
|
-
FileUtils.rm_rf(ChefApply::Config.telemetry_session_file)
|
66
|
-
ChefApply::Log.info("Terminating, nothing more to do.")
|
67
|
-
rescue => e
|
68
|
-
ChefApply::Log.fatal "Sender thread aborted: '#{e}' failed at #{e.backtrace[0]}"
|
69
|
-
end
|
70
|
-
|
71
|
-
def process_session(path)
|
72
|
-
ChefApply::Log.info("Processing telemetry entries from #{path}")
|
73
|
-
content = load_and_clear_session(path)
|
74
|
-
submit_session(content)
|
75
|
-
end
|
76
|
-
|
77
|
-
def submit_session(content)
|
78
|
-
# Each file contains the actions taken within a single run of the chef tool.
|
79
|
-
# Each run is one session, so we'll first remove remove the session file
|
80
|
-
# to force creating a new one.
|
81
|
-
FileUtils.rm_rf(ChefApply::Config.telemetry_session_file)
|
82
|
-
# We'll use the version captured in the sesion file
|
83
|
-
entries = content["entries"]
|
84
|
-
cli_version = content["version"]
|
85
|
-
total = entries.length
|
86
|
-
telemetry = Telemetry.new(product: "chef-workstation",
|
87
|
-
origin: "command-line",
|
88
|
-
product_version: cli_version,
|
89
|
-
install_context: "omnibus")
|
90
|
-
total = entries.length
|
91
|
-
entries.each_with_index do |entry, x|
|
92
|
-
submit_entry(telemetry, entry, x + 1, total)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def submit_entry(telemetry, entry, sequence, total)
|
97
|
-
ChefApply::Log.info("Submitting telemetry entry #{sequence}/#{total}: #{entry} ")
|
98
|
-
telemetry.deliver(entry)
|
99
|
-
ChefApply::Log.info("Entry #{sequence}/#{total} submitted.")
|
100
|
-
rescue => e
|
101
|
-
# No error handling in telemetry lib, so at least track the failrue
|
102
|
-
ChefApply::Log.error("Failed to send entry #{sequence}/#{total}: #{e}")
|
103
|
-
ChefApply::Log.error("Backtrace: #{e.backtrace} ")
|
104
|
-
end
|
105
|
-
|
106
|
-
private
|
107
|
-
|
108
|
-
def load_and_clear_session(path)
|
109
|
-
content = File.read(path)
|
110
|
-
# We'll remove it now instead of after we parse or submit it -
|
111
|
-
# if we fail to deliver, we don't want to be stuck resubmitting it if the problem
|
112
|
-
# was due to payload. This is a trade-off - if we get a transient error, the
|
113
|
-
# payload will be lost.
|
114
|
-
# TODO: Improve error handling so we can intelligently decide whether to
|
115
|
-
# retry a failed load or failed submit.
|
116
|
-
FileUtils.rm_rf(path)
|
117
|
-
YAML.load(content)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|