pack_stats 0.0.4 → 0.0.6

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: 43fc659730748dbbe47795bd71e3b421b746b8a76b1f8fe4c8d058161c3175b6
4
- data.tar.gz: f5ad0c0e321f701bd7f426a67faaca0988a00ac5b47c44995139818918e4c540
3
+ metadata.gz: 24c2ef393916e7e08d2b7c227d747eb07e34ddc1c544c423f48e5797ca9a6483
4
+ data.tar.gz: 819e2a8238a33a664f7586701892d26bc265adb17afb54943ce1a156a58b62d0
5
5
  SHA512:
6
- metadata.gz: 2d4d160bc1584c09a97c271a1f45a38b56183730f65c8a9235b85add2eb45e30a2e403ea19a13364b2a5e06fba41bbad4a36fb4e42adab96b205cadb61e117d4
7
- data.tar.gz: 99d1de19334442e788ff48e27a3c980891e0cdfffb6327667dd3338e62b45499762e5d55580244fcac6771c87e3c05a93fe3589445c9ed9a09b22072d040a9ba
6
+ metadata.gz: ce1303c2c2be91aa338b89df57af5f9a59ff76615b95f0733ded2f3543c052c10e47ee3c1e6b01d9b9820edac47609077113d1749211f69c90a8f4cc923fc499
7
+ data.tar.gz: 32f66cbfa1c998c65591d34c0a076a421e13cd01de7c130d49fa28fae1512396aed7261f27fe458f43f347bbc41abc70253af9c1590ceb4fc8652f0dcb52b84b
@@ -17,10 +17,11 @@ module PackStats
17
17
  raise StandardError.new("Metrics names must not exceed 200 characters: #{name}") # rubocop:disable Style/RaiseArgs
18
18
  end
19
19
 
20
+ all_tags = [*tags, max_enforcements_tag]
20
21
  new(
21
22
  name: name,
22
23
  count: count,
23
- tags: tags
24
+ tags: all_tags
24
25
  )
25
26
  end
26
27
 
@@ -35,5 +36,16 @@ module PackStats
35
36
  other.count == self.count &&
36
37
  other.tags == self.tags
37
38
  end
39
+
40
+ sig { params(tag_value: T::Boolean).void }
41
+ def self.set_max_enforcements_tag(tag_value)
42
+ @max_enforcements_tag = T.let(@max_enforcements_tag, T.nilable(Tag))
43
+ @max_enforcements_tag = Tag.new(key: 'max_enforcements', value: tag_value ? 'true' : 'false')
44
+ end
45
+
46
+ sig { returns(Tag) }
47
+ def self.max_enforcements_tag
48
+ @max_enforcements_tag || Tag.new(key: 'max_enforcements', value: 'false')
49
+ end
38
50
  end
39
51
  end
@@ -9,7 +9,6 @@ require 'pack_stats/private/metrics/packwerk_checker_usage'
9
9
  require 'pack_stats/private/metrics/rubocop_usage'
10
10
  require 'pack_stats/private/metrics/packages'
11
11
  require 'pack_stats/private/metrics/packages_by_team'
12
- require 'pack_stats/private/metrics/nested_packs'
13
12
 
14
13
  module PackStats
15
14
  module Private
@@ -29,7 +28,6 @@ module PackStats
29
28
  *Metrics::Files.get_metrics(source_code_files, app_name),
30
29
  *Metrics::Packages.get_package_metrics(packages, app_name),
31
30
  *Metrics::PackagesByTeam.get_package_metrics_by_team(packages, app_name),
32
- *Metrics::NestedPacks.get_nested_package_metrics(packages, app_name)
33
31
  ]
34
32
  end
35
33
 
data/lib/pack_stats.rb CHANGED
@@ -39,7 +39,9 @@ module PackStats
39
39
  # See note on get_metrics
40
40
  packaged_source_code_locations: T.nilable(T::Array[Pathname]),
41
41
  # See note on get_metrics
42
- use_gusto_legacy_names: T::Boolean
42
+ use_gusto_legacy_names: T::Boolean,
43
+ # See note on get_metrics
44
+ max_enforcements_tag_value: T::Boolean
43
45
  ).void
44
46
  end
45
47
  def self.report_to_datadog!(
@@ -50,7 +52,8 @@ module PackStats
50
52
  report_time: Time.now, # rubocop:disable Rails/TimeZone
51
53
  verbose: false,
52
54
  packaged_source_code_locations: [],
53
- use_gusto_legacy_names: false
55
+ use_gusto_legacy_names: false,
56
+ max_enforcements_tag_value: false
54
57
  )
55
58
 
56
59
  all_metrics = self.get_metrics(
@@ -58,6 +61,7 @@ module PackStats
58
61
  componentized_source_code_locations: componentized_source_code_locations,
59
62
  app_name: app_name,
60
63
  use_gusto_legacy_names: use_gusto_legacy_names,
64
+ max_enforcements_tag_value: max_enforcements_tag_value,
61
65
  )
62
66
 
63
67
  # This helps us debug what metrics are being sent
@@ -89,7 +93,12 @@ module PackStats
89
93
  # Gusto uses this to preserve historical trends in Dashboards as the names of
90
94
  # things changed, but new dashboards can use names that better match current tooling conventions.
91
95
  # The behavior of setting this parameter to true might change without warning
92
- use_gusto_legacy_names: T::Boolean
96
+ use_gusto_legacy_names: T::Boolean,
97
+ # You can set this to `true` to tag all metrics with `max_enforcements:true`.
98
+ # This is useful if you want to submit two sets of metrics:
99
+ # Once with the violation counts as configured in the app
100
+ # Another time with the violation counts after turning on all enforcements and running `bin/packwerk update`.
101
+ max_enforcements_tag_value: T::Boolean
93
102
  ).returns(T::Array[GaugeMetric])
94
103
  end
95
104
  def self.get_metrics(
@@ -97,8 +106,12 @@ module PackStats
97
106
  componentized_source_code_locations:,
98
107
  app_name:,
99
108
  packaged_source_code_locations: [],
100
- use_gusto_legacy_names: false
109
+ use_gusto_legacy_names: false,
110
+ max_enforcements_tag_value: false
101
111
  )
112
+
113
+ GaugeMetric.set_max_enforcements_tag(max_enforcements_tag_value)
114
+
102
115
  all_metrics = Private::DatadogReporter.get_metrics(
103
116
  source_code_files: source_code_files(
104
117
  source_code_pathnames: source_code_pathnames,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pack_stats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gusto Engineers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-06 00:00:00.000000000 Z
11
+ date: 2023-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: code_teams
@@ -193,7 +193,6 @@ files:
193
193
  - lib/pack_stats/private/datadog_reporter.rb
194
194
  - lib/pack_stats/private/metrics.rb
195
195
  - lib/pack_stats/private/metrics/files.rb
196
- - lib/pack_stats/private/metrics/nested_packs.rb
197
196
  - lib/pack_stats/private/metrics/packages.rb
198
197
  - lib/pack_stats/private/metrics/packages_by_team.rb
199
198
  - lib/pack_stats/private/metrics/packwerk_checker_usage.rb
@@ -1,137 +0,0 @@
1
- # typed: strict
2
- # frozen_string_literal: true
3
-
4
- module PackStats
5
- module Private
6
- module Metrics
7
- class NestedPacks
8
- extend T::Sig
9
-
10
- class PackGroup < T::Struct
11
- extend T::Sig
12
-
13
- const :name, String
14
- const :root, ParsePackwerk::Package
15
- const :members, T::Array[ParsePackwerk::Package]
16
-
17
- sig { params(packages: T::Array[ParsePackwerk::Package]).returns(T::Array[PackGroup]) }
18
- def self.all_from(packages)
19
- packs_by_group = {}
20
-
21
- packages.each do |package|
22
- # For a child pack, package.directory is `packs/fruits/apples` (i.e. the directory of the package.yml file).
23
- # The package.directory.dirname is therefore `packs/fruits`.
24
- # For a standalone pack, package.directory.dirname is `packs`
25
- # A pack with no parent is in a pack group of its own name
26
- root = ParsePackwerk.find(package.directory.dirname.to_s) || package
27
- # Mark the parent pack and child pack as being in the pack group of the parent
28
- packs_by_group[root.name] ||= { root: root, members: [] }
29
- packs_by_group[root.name][:members] << package
30
- end
31
-
32
- packs_by_group.map do |name, pack_data|
33
- PackGroup.new(
34
- name: name,
35
- root: pack_data[:root],
36
- members: pack_data[:members],
37
- )
38
- end
39
- end
40
-
41
- sig { returns(Integer) }
42
- def children_pack_count
43
- members.count do |package|
44
- package.name != root.name
45
- end
46
- end
47
-
48
- sig { returns(T::Boolean) }
49
- def has_parent?
50
- children_pack_count > 0
51
- end
52
-
53
- sig { returns(T::Array[ParsePackwerk::Violation]) }
54
- def cross_group_violations
55
- all_violations = members.flat_map do |member|
56
- ParsePackwerk::PackageTodo.for(member).violations
57
- end
58
-
59
- all_violations.select do |violation|
60
- !members.map(&:name).include?(violation.to_package_name)
61
- end
62
- end
63
- end
64
-
65
- sig do
66
- params(
67
- packages: T::Array[ParsePackwerk::Package],
68
- app_name: String
69
- ).returns(T::Array[GaugeMetric])
70
- end
71
- def self.get_nested_package_metrics(packages, app_name)
72
- all_metrics = []
73
- app_level_tag = Tag.for('app', app_name)
74
- package_tags = T.let([app_level_tag], T::Array[Tag])
75
-
76
- pack_groups = PackGroup.all_from(packages)
77
- all_pack_groups_count = pack_groups.count
78
- child_pack_count = pack_groups.sum(&:children_pack_count)
79
- parent_pack_count = pack_groups.count(&:has_parent?)
80
- all_cross_pack_group_violations = pack_groups.flat_map(&:cross_group_violations)
81
-
82
- all_metrics << GaugeMetric.for('all_pack_groups.count', all_pack_groups_count, package_tags)
83
- all_metrics << GaugeMetric.for('child_packs.count', child_pack_count, package_tags)
84
- all_metrics << GaugeMetric.for('parent_packs.count', parent_pack_count, package_tags)
85
- all_metrics << GaugeMetric.for('all_pack_groups.privacy_violations.count', Metrics.file_count(all_cross_pack_group_violations.select(&:privacy?)), package_tags)
86
- all_metrics << GaugeMetric.for('all_pack_groups.dependency_violations.count', Metrics.file_count(all_cross_pack_group_violations.select(&:dependency?)), package_tags)\
87
-
88
- packs_by_group = {}
89
- pack_groups.each do |pack_group|
90
- pack_group.members.each do |member|
91
- packs_by_group[member.name] = pack_group.name
92
- end
93
- end
94
-
95
- inbound_violations_by_pack_group = {}
96
- all_cross_pack_group_violations.group_by(&:to_package_name).each do |to_package_name, violations|
97
- violations.each do |violation|
98
- pack_group_for_violation = packs_by_group[violation.to_package_name]
99
- inbound_violations_by_pack_group[pack_group_for_violation] ||= []
100
- inbound_violations_by_pack_group[pack_group_for_violation] << violation
101
- end
102
- end
103
-
104
- pack_groups.each do |pack_group|
105
- tags = [
106
- *package_tags,
107
- Tag.for('pack_group', Metrics.humanized_package_name(pack_group.name)),
108
- ]
109
-
110
- outbound_dependency_violations = pack_group.cross_group_violations.select(&:dependency?)
111
- inbound_privacy_violations = inbound_violations_by_pack_group.fetch(pack_group.name, []).select(&:privacy?)
112
- all_metrics << GaugeMetric.for('by_pack_group.outbound_dependency_violations.count', Metrics.file_count(outbound_dependency_violations), tags)
113
- all_metrics << GaugeMetric.for('by_pack_group.inbound_privacy_violations.count', Metrics.file_count(inbound_privacy_violations), tags)
114
- end
115
-
116
- pack_groups.each do |from_pack_group|
117
- violations_by_to_pack_group = from_pack_group.cross_group_violations.group_by do |violation|
118
- packs_by_group[violation.to_package_name]
119
- end
120
- violations_by_to_pack_group.each do |to_pack_group_name, violations|
121
- tags = [
122
- *package_tags,
123
- Tag.for('pack_group', Metrics.humanized_package_name(from_pack_group.name)),
124
- Tag.for('to_pack_group', Metrics.humanized_package_name(to_pack_group_name)),
125
- ]
126
-
127
- all_metrics << GaugeMetric.for('by_pack_group.outbound_dependency_violations.per_pack_group.count', Metrics.file_count(violations.select(&:dependency?)), tags)
128
- all_metrics << GaugeMetric.for('by_pack_group.outbound_privacy_violations.per_pack_group.count', Metrics.file_count(violations.select(&:privacy?)), tags)
129
- end
130
- end
131
-
132
- all_metrics
133
- end
134
- end
135
- end
136
- end
137
- end