dropsonde 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2b344789cd257a8cae81d53150c1ab50fe0cf20716c4fce306446a2c207c7e2
4
- data.tar.gz: 563788ccfcf13c75feb8529e4870ba65a0679a1d461eda2413cd401c0c52decd
3
+ metadata.gz: 05a4a694cd3915ec7c3683c7c8250fd1f857d07ef8fb6cae80c832404b35e3ce
4
+ data.tar.gz: 95245d11a85ef50539f86182cc458246178ffb24ff409bd04fbef9a0a23342ef
5
5
  SHA512:
6
- metadata.gz: 5006cf40dd17e018b6af805ae6192d5cc8b1842b981a4eba6895966a7ace7ee13365b9bae976169adaad1399ee9ca767d10b56cef56542ba5420cd04cecafdb6
7
- data.tar.gz: ebda439d8baeec73d04887fb03b745acb2a11b9af8621f8992ad585b9ea9380f4c5732f88a5c17661f8123cba8125dc781d2929302a0954511bd6fae221c78f4
6
+ metadata.gz: a8eed2636ad7735accf3e3f6bacbcb16bae84514b3503e718eb96426ca0bbe6a39a06a9ea06727714b6e578ac4a3bd9ddd6fe76f9bebb4c1d63c084b3503c44b
7
+ data.tar.gz: 2d1c1cf87cef36cdcb196cab0c135970020389462b99b0ff8447dcefe3ae1f381da31a93ad29a34fedbfd6134eeba2b8c58a3ee30069021c74e3972a857f5950
data/CHANGELOG.md CHANGED
@@ -1,11 +1,25 @@
1
1
  # Changelog
2
2
 
3
- ## [0.0.7](https://github.com/puppetlabs/dropsonde/tree/0.0.7) (2022-02-10)
3
+ ## [0.0.8](https://github.com/puppetlabs/dropsonde/tree/0.0.8) (2022-08-29)
4
4
 
5
- [Full Changelog](https://github.com/puppetlabs/dropsonde/compare/v0.0.6...0.0.7)
5
+ [Full Changelog](https://github.com/puppetlabs/dropsonde/compare/v0.0.7...0.0.8)
6
6
 
7
7
  **Merged pull requests:**
8
8
 
9
+ - \[maint\] correct cache [\#29](https://github.com/puppetlabs/dropsonde/pull/29) ([binford2k](https://github.com/binford2k))
10
+ - \[maint\] rubocop style fixes [\#28](https://github.com/puppetlabs/dropsonde/pull/28) ([binford2k](https://github.com/binford2k))
11
+ - Fix example generation [\#27](https://github.com/puppetlabs/dropsonde/pull/27) ([binford2k](https://github.com/binford2k))
12
+ - unused modules [\#26](https://github.com/puppetlabs/dropsonde/pull/26) ([binford2k](https://github.com/binford2k))
13
+ - Adding changelog generation to Rakefile [\#23](https://github.com/puppetlabs/dropsonde/pull/23) ([binford2k](https://github.com/binford2k))
14
+
15
+ ## [v0.0.7](https://github.com/puppetlabs/dropsonde/tree/v0.0.7) (2022-02-10)
16
+
17
+ [Full Changelog](https://github.com/puppetlabs/dropsonde/compare/v0.0.6...v0.0.7)
18
+
19
+ **Merged pull requests:**
20
+
21
+ - Releasing v00.7 [\#22](https://github.com/puppetlabs/dropsonde/pull/22) ([binford2k](https://github.com/binford2k))
22
+ - Releasing v00.7 [\#21](https://github.com/puppetlabs/dropsonde/pull/21) ([binford2k](https://github.com/binford2k))
9
23
  - update server language [\#20](https://github.com/puppetlabs/dropsonde/pull/20) ([binford2k](https://github.com/binford2k))
10
24
  - Updates the telemetry endpoint to a stable URL [\#19](https://github.com/puppetlabs/dropsonde/pull/19) ([MikaelSmith](https://github.com/MikaelSmith))
11
25
  - docs updates now that it's shipped [\#18](https://github.com/puppetlabs/dropsonde/pull/18) ([binford2k](https://github.com/binford2k))
@@ -7,11 +7,13 @@ require 'puppet_forge'
7
7
 
8
8
  # cache class
9
9
  class Dropsonde::Cache
10
+ @@cache = nil # rubocop:disable Style/ClassVars
10
11
  @autoupdate = false
11
12
 
12
- def initialize(path, ttl, autoupdate)
13
+ def initialize(path = '~/.dropsonde', ttl = 7, autoupdate = true) # rubocop:disable Style/OptionalBooleanParameter
14
+ path = File.expand_path(path)
13
15
  FileUtils.mkdir_p(path)
14
- @path = "#{File.expand_path(path)}/forge.json"
16
+ @path = "#{path}/forge.json"
15
17
  @ttl = ttl
16
18
  @autoupdate = autoupdate
17
19
 
@@ -27,10 +29,14 @@ class Dropsonde::Cache
27
29
  PuppetForge.user_agent = 'Dropsonde Telemetry Client/0.0.1'
28
30
  end
29
31
 
30
- def modules
32
+ def self.modules
31
33
  @@cache['modules']
32
34
  end
33
35
 
36
+ def modules
37
+ Dropsonde::Cache.modules
38
+ end
39
+
34
40
  def cache
35
41
  @@cache
36
42
  end
@@ -71,12 +71,11 @@ class Dropsonde::Metrics::Dependencies
71
71
  # make it easier to write data aggregation queries without access to the
72
72
  # actual private data that users have submitted.
73
73
 
74
- dropsonde_cache = Dropsonde::Cache.new('foo', 7, true)
75
74
  versions = ['>= 1.5.2', '>= 4.3.2', '>= 3.0.0 < 4.0.0', '>= 2.2.1 < 5.0.0', '>= 5.0.0 < 7.0.0', '>= 4.11.0']
76
75
  [
77
- dependencies: dropsonde_cache.modules
78
- .sample(rand(250))
79
- .map do |item|
76
+ dependencies: Dropsonde::Cache.modules
77
+ .sample(rand(250))
78
+ .map do |item|
80
79
  {
81
80
  name: item,
82
81
  version_requirement: versions.sample,
@@ -5,6 +5,8 @@ class Dropsonde::Metrics::Modules
5
5
  def self.initialize_modules
6
6
  # require any libraries needed here -- no need to load puppet; it's already initialized
7
7
  # All plugins are initialized before any metrics are generated.
8
+ require 'puppet/info_service'
9
+ require 'puppet/info_service/class_information_service'
8
10
  end
9
11
 
10
12
  def self.description
@@ -64,6 +66,46 @@ class Dropsonde::Metrics::Modules
64
66
  "name": 'classes',
65
67
  "type": 'RECORD',
66
68
  },
69
+ {
70
+ "fields": [
71
+ {
72
+ "description": 'The module name',
73
+ "mode": 'NULLABLE',
74
+ "name": 'name',
75
+ "type": 'STRING',
76
+ },
77
+ {
78
+ "description": 'The module slug (author-name)',
79
+ "mode": 'NULLABLE',
80
+ "name": 'slug',
81
+ "type": 'STRING',
82
+ },
83
+ {
84
+ "description": 'The module version',
85
+ "mode": 'NULLABLE',
86
+ "name": 'version',
87
+ "type": 'STRING',
88
+ },
89
+ ],
90
+ "description": 'List of modules whose classes are not declared in any environments.',
91
+ "mode": 'REPEATED',
92
+ "name": 'unused_modules',
93
+ "type": 'RECORD',
94
+ },
95
+ {
96
+ "fields": [
97
+ {
98
+ "description": 'The class name',
99
+ "mode": 'NULLABLE',
100
+ "name": 'name',
101
+ "type": 'STRING',
102
+ },
103
+ ],
104
+ "description": 'List of unused classes in all environments.',
105
+ "mode": 'REPEATED',
106
+ "name": 'unused_classes',
107
+ "type": 'RECORD',
108
+ },
67
109
  ]
68
110
  end
69
111
 
@@ -102,13 +144,45 @@ class Dropsonde::Metrics::Modules
102
144
  count: results.count { |row| row['title'] == title },
103
145
  }
104
146
  }.compact
147
+
148
+ # now lets get a list of all classes so we can identify which are unused
149
+ infoservice = Puppet::InfoService::ClassInformationService.new
150
+ env_hash = {}
151
+ environments.each do |env|
152
+ manifests = Puppet.lookup(:environments).get(env).modules.reduce([]) do |acc, mod|
153
+ next acc unless mod.forge_module?
154
+
155
+ acc.concat mod.all_manifests
156
+ end
157
+ env_hash[env] = manifests
158
+ end
159
+
160
+ klasses_per_env = infoservice.classes_per_environment(env_hash)
161
+
162
+ installed_classes = klasses_per_env.reduce([]) do |klasses, (_key, env)|
163
+ names = env.reduce([]) do |acc, (_file, contents)|
164
+ acc.concat(contents[:classes].map { |c| c[:name] })
165
+ end
166
+
167
+ klasses.concat names
168
+ end
169
+
170
+ unused_modules = installed_classes.map { |c| c.split('::').first }.sort.uniq
171
+ classes.each { |c| unused_modules.delete(c[:name].split('::').first.downcase) }
172
+
173
+ unused_classes = installed_classes.dup
174
+ classes.each { |c| unused_classes.delete(c[:name].downcase) }
105
175
  else
106
176
  classes = []
177
+ unused_modules = []
178
+ unused_classes = []
107
179
  end
108
180
 
109
181
  [
110
182
  { modules: modules },
111
183
  { classes: classes },
184
+ { unused_modules: unused_modules },
185
+ { unused_classes: unused_classes },
112
186
  ]
113
187
  end
114
188
 
@@ -119,25 +193,30 @@ class Dropsonde::Metrics::Modules
119
193
 
120
194
  versions = ['1.3.2', '0.0.1', '0.1.2', '1.0.0', '3.0.2', '7.10', '6.1.0', '2.1.0', '1.4.0']
121
195
  classes = ['', '::Config', '::Service', '::Server', '::Client', '::Packages']
122
- dropsonde_cache = Dropsonde::Cache.new('foo', 7, true)
123
196
  [
124
- modules: dropsonde_cache.modules
125
- .sample(rand(100))
126
- .map do |item|
197
+ modules: Dropsonde::Cache.modules
198
+ .sample(rand(100))
199
+ .map do |item|
127
200
  {
128
201
  name: item.split('-').last,
129
202
  slug: item,
130
203
  version: versions.sample,
131
204
  }
132
205
  end,
133
- classes: dropsonde_cache.modules
134
- .sample(rand(500))
135
- .map do |item|
206
+ classes: Dropsonde::Cache.modules
207
+ .sample(rand(500))
208
+ .map do |item|
136
209
  {
137
210
  name: item.split('-').last.capitalize + classes.sample,
138
211
  count: rand(750),
139
212
  }
140
213
  end,
214
+ unused_modules: Dropsonde::Cache.modules
215
+ .sample(rand(500))
216
+ .map { |item| item.split('-').last },
217
+ unused_classes: Dropsonde::Cache.modules
218
+ .sample(rand(500))
219
+ .map { |item| item.split('-').last.capitalize + classes.sample },
141
220
  ]
142
221
  end
143
222
 
@@ -100,10 +100,9 @@ class Dropsonde::Metrics::Platforms
100
100
  platforms = %w[RedHat Debian Windows Suse FreeBSD Darwin Archlinux AIX]
101
101
  classes = ['', '::Config', '::Service', '::Server', '::Client', '::Packages']
102
102
 
103
- dropsonde_cache = Dropsonde::Cache.new('foo', 7, true)
104
- data = dropsonde_cache.modules
105
- .sample(rand(35))
106
- .map { |item|
103
+ data = Dropsonde::Cache.modules
104
+ .sample(rand(35))
105
+ .map { |item|
107
106
  name = item.split('-').last.capitalize + classes.sample
108
107
 
109
108
  rand(5).times.map do
@@ -54,7 +54,7 @@ class Dropsonde::Metrics::Puppetfiles
54
54
  next unless File.file? puppetfile
55
55
 
56
56
  tokens = Ripper.sexp(File.read(puppetfile)).flatten
57
- indices = tokens.map.with_index { |a, i| a == :command ? i : nil }.compact
57
+ indices = tokens.map.with_index { |a, i| (a == :command) ? i : nil }.compact
58
58
 
59
59
  indices.map { |i| tokens[i + 2] }
60
60
  }.flatten.compact
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Dropsonde
4
- VERSION = '0.0.7'
4
+ VERSION = '0.0.8'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dropsonde
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Ford
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-10 00:00:00.000000000 Z
11
+ date: 2022-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -164,7 +164,7 @@ homepage: https://github.com/puppetlabs/dropsonde
164
164
  licenses:
165
165
  - Apache-2.0
166
166
  metadata: {}
167
- post_install_message:
167
+ post_install_message:
168
168
  rdoc_options: []
169
169
  require_paths:
170
170
  - lib
@@ -179,8 +179,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  requirements: []
182
- rubygems_version: 3.1.4
183
- signing_key:
182
+ rubygems_version: 3.1.6
183
+ signing_key:
184
184
  specification_version: 4
185
185
  summary: A simple telemetry probe for gathering usage information about Puppet infrastructures.
186
186
  test_files: []