pack_stats 0.0.5 → 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24c2ef393916e7e08d2b7c227d747eb07e34ddc1c544c423f48e5797ca9a6483
|
4
|
+
data.tar.gz: 819e2a8238a33a664f7586701892d26bc265adb17afb54943ce1a156a58b62d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce1303c2c2be91aa338b89df57af5f9a59ff76615b95f0733ded2f3543c052c10e47ee3c1e6b01d9b9820edac47609077113d1749211f69c90a8f4cc923fc499
|
7
|
+
data.tar.gz: 32f66cbfa1c998c65591d34c0a076a421e13cd01de7c130d49fa28fae1512396aed7261f27fe458f43f347bbc41abc70253af9c1590ceb4fc8652f0dcb52b84b
|
@@ -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
|
|
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
|
+
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-05-
|
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
|