pack_stats 0.0.1 → 0.0.3

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: 60606e6b527c76b27deaac01ad5991ebe06ec7db76bc5fe9eb707d0cfdde9c56
4
- data.tar.gz: ec768521fe361499a52bb29b59b97d23249ef9bd6a9c1bc3c543c8d46d6ccc08
3
+ metadata.gz: 3f84f807ac7cd49095073c3da4a5f99fd2a4ba84a56b9740eb6d039ab310f720
4
+ data.tar.gz: 538a48f38b02506d4841c5f1c2be9d117c9623cc137315d353bb82547762cfe6
5
5
  SHA512:
6
- metadata.gz: f33cff3e350f90dbd71cf07433df45bfc170fd9c2101e5713cae1976e034385af98fbc76eddc01ac0ed78009f6e23f2b2f43797999d1fd6e8405fbdb50c013b1
7
- data.tar.gz: f04b2b9ac1e3cdf3fcdf0811a1d2a9d1b0a8b2864278ed892caf61c1676fcf762839d24f03ef0f7625895ec37287dcaf3cc034c7ab672468d9b5b1ccf18a15a6
6
+ metadata.gz: 9396f5f105aaadadcc5260d8eaf5beaa3bcc35bf053261b3c73c2c07bfe7e95d0a92e524e110ae842ed8507d87fa1581a76db95c097cae7d1e4da9a7b46b7c9c
7
+ data.tar.gz: bf1650ae0da82fcfdb29d25b09359c9f112aeb2a395b339f7a162d0963491b2fc0ccec54aa1e52ba178669c505023c301d456cf468372d9233fa2c3bdc93e42c
data/README.md CHANGED
@@ -38,13 +38,6 @@ PackStats.report_to_datadog!(
38
38
  # Example: [Pathname.new("./gems")]
39
39
  #
40
40
  componentized_source_code_locations: componentized_source_code_locations,
41
- #
42
- # A file is determined to be packaged if it exists in any of these directories.
43
- # This is an array of `Pathname`. `Pathname` can be relative or absolute paths.
44
- #
45
- # Example: [Pathname.new("./packs")]
46
- #
47
- packaged_source_code_locations: packaged_source_code_locations,
48
41
  )
49
42
  ```
50
43
 
@@ -53,7 +53,7 @@ module PackStats
53
53
  sig { returns(T::Array[ParsePackwerk::Violation]) }
54
54
  def cross_group_violations
55
55
  all_violations = members.flat_map do |member|
56
- ParsePackwerk::DeprecatedReferences.for(member).violations
56
+ ParsePackwerk::PackageTodo.for(member).violations
57
57
  end
58
58
 
59
59
  all_violations.select do |violation|
@@ -63,7 +63,7 @@ module PackStats
63
63
  raise StandardError, "Could not find matching package #{to_package_name}"
64
64
  end
65
65
 
66
- tags = package_tags + [Tag.for('to_package', Metrics.humanized_package_name(to_package_name))] + Metrics.tags_for_to_team(CodeOwnership.for_package(to_package)&.name)
66
+ tags = package_tags + [Tag.for('to_package', Metrics.humanized_package_name(to_package_name))] + Metrics.tags_for_to_team(Private.package_owner(to_package))
67
67
  all_metrics << GaugeMetric.for('by_package.outbound_dependency_violations.per_package.count', Metrics.file_count(violations.select(&:dependency?)), tags)
68
68
  all_metrics << GaugeMetric.for('by_package.outbound_privacy_violations.per_package.count', Metrics.file_count(violations.select(&:privacy?)), tags)
69
69
  end
@@ -89,7 +89,8 @@ module PackStats
89
89
  raise StandardError, "Could not find matching package #{explicit_dependency}"
90
90
  end
91
91
 
92
- tags = package_tags + [Tag.for('to_package', Metrics.humanized_package_name(explicit_dependency))] + Metrics.tags_for_to_team(CodeOwnership.for_package(to_package)&.name)
92
+ owner = Private.package_owner(to_package)
93
+ tags = package_tags + [Tag.for('to_package', Metrics.humanized_package_name(explicit_dependency))] + Metrics.tags_for_to_team(owner)
93
94
  all_metrics << GaugeMetric.for('by_package.outbound_explicit_dependencies.per_package.count', 1, tags)
94
95
  end
95
96
 
@@ -17,7 +17,8 @@ module PackStats
17
17
  all_metrics = T.let([], T::Array[GaugeMetric])
18
18
  app_level_tag = Tag.for('app', app_name)
19
19
 
20
- all_packages.group_by { |package| CodeOwnership.for_package(package)&.name }.each do |team_name, packages_by_team|
20
+
21
+ all_packages.group_by { |package| Private.package_owner(package) }.each do |team_name, packages_by_team|
21
22
  # We look at `all_packages` because we care about ALL inbound violations across all teams
22
23
  inbound_violations_by_package = all_packages.flat_map(&:violations).group_by(&:to_package_name)
23
24
 
@@ -51,7 +52,7 @@ module PackStats
51
52
  raise StandardError, "Could not find matching package #{violation.to_package_name}"
52
53
  end
53
54
 
54
- CodeOwnership.for_package(to_package)&.name
55
+ Private.package_owner(to_package)
55
56
  end
56
57
 
57
58
  grouped_outbound_violations.each do |to_team_name, violations|
@@ -12,7 +12,6 @@ module PackStats
12
12
  # Later, we might find a way we can get this directly from `packwerk`
13
13
  class PackwerkChecker < T::Struct
14
14
  const :setting, String
15
- const :strict_mode, String
16
15
  end
17
16
 
18
17
  sig { params(prefix: String, packages: T::Array[ParsePackwerk::Package], package_tags: T::Array[Tag]).returns(T::Array[GaugeMetric]) }
@@ -20,22 +19,21 @@ module PackStats
20
19
  metrics = T.let([], T::Array[GaugeMetric])
21
20
 
22
21
  checkers = [
23
- PackwerkChecker.new(setting: 'enforce_dependencies', strict_mode: 'enforce_dependencies_strictly'),
24
- PackwerkChecker.new(setting: 'enforce_privacy', strict_mode: 'enforce_privacy_strictly')
22
+ PackwerkChecker.new(setting: 'enforce_dependencies'),
23
+ PackwerkChecker.new(setting: 'enforce_privacy')
25
24
  ]
26
25
 
27
26
  checkers.each do |checker|
28
27
  ['false', 'true', 'strict'].each do |enabled_mode|
29
28
  count_of_packages = ParsePackwerk.all.count do |package|
30
- strict_mode = package.metadata[checker.strict_mode]
31
- enabled = YAML.load_file(package.yml)[checker.setting]
29
+ checker_setting = YAML.load_file(package.yml)[checker.setting]
32
30
  case enabled_mode
33
31
  when 'false'
34
- !enabled
32
+ !checker_setting
35
33
  when 'true'
36
- enabled && !strict_mode
34
+ checker_setting && checker_setting != 'strict'
37
35
  when 'strict'
38
- !!strict_mode
36
+ checker_setting == 'strict'
39
37
  end
40
38
  end
41
39
 
@@ -17,7 +17,7 @@ module PackStats
17
17
  [
18
18
  Tag.new(key: 'package', value: humanized_package_name(package.name)),
19
19
  Tag.new(key: 'app', value: app_name),
20
- *Metrics.tags_for_team(CodeOwnership.for_package(package)&.name),
20
+ *Metrics.tags_for_team(Private.package_owner(package)),
21
21
  ]
22
22
  end
23
23
 
@@ -48,6 +48,13 @@ module PackStats
48
48
  new_metric
49
49
  end
50
50
  end
51
+
52
+ sig { params(package: ParsePackwerk::Package).returns(T.nilable(String) )}
53
+ def self.package_owner(package)
54
+ pack = Packs.find(package.name)
55
+ return nil if pack.nil?
56
+ CodeOwnership.for_package(pack)&.name
57
+ end
51
58
  end
52
59
 
53
60
  private_constant :Private
data/lib/pack_stats.rb CHANGED
@@ -7,6 +7,7 @@ require 'benchmark'
7
7
  require 'code_teams'
8
8
  require 'code_ownership'
9
9
  require 'pathname'
10
+ require 'packs'
10
11
  require 'pack_stats/private'
11
12
  require 'pack_stats/private/source_code_file'
12
13
  require 'pack_stats/private/datadog_reporter'
@@ -27,23 +28,17 @@ module PackStats
27
28
  ].freeze, T::Array[Pathname]
28
29
  )
29
30
 
30
- DEFAULT_PACKAGED_SOURCE_CODE_LOCATIONS = T.let(
31
- [
32
- Pathname.new('packs'),
33
- Pathname.new('packages'),
34
- ].freeze, T::Array[Pathname]
35
- )
36
-
37
31
  sig do
38
32
  params(
39
33
  datadog_client: Dogapi::Client,
40
34
  app_name: String,
41
35
  source_code_pathnames: T::Array[Pathname],
42
36
  componentized_source_code_locations: T::Array[Pathname],
43
- packaged_source_code_locations: T::Array[Pathname],
44
37
  report_time: Time,
45
38
  verbose: T::Boolean,
46
39
  # See note on get_metrics
40
+ packaged_source_code_locations: T.nilable(T::Array[Pathname]),
41
+ # See note on get_metrics
47
42
  use_gusto_legacy_names: T::Boolean
48
43
  ).void
49
44
  end
@@ -52,16 +47,15 @@ module PackStats
52
47
  app_name:,
53
48
  source_code_pathnames:,
54
49
  componentized_source_code_locations: DEFAULT_COMPONENTIZED_SOURCE_CODE_LOCATIONS,
55
- packaged_source_code_locations: DEFAULT_PACKAGED_SOURCE_CODE_LOCATIONS,
56
50
  report_time: Time.now, # rubocop:disable Rails/TimeZone
57
51
  verbose: false,
52
+ packaged_source_code_locations: [],
58
53
  use_gusto_legacy_names: false
59
54
  )
60
55
 
61
56
  all_metrics = self.get_metrics(
62
57
  source_code_pathnames: source_code_pathnames,
63
58
  componentized_source_code_locations: componentized_source_code_locations,
64
- packaged_source_code_locations: packaged_source_code_locations,
65
59
  app_name: app_name,
66
60
  use_gusto_legacy_names: use_gusto_legacy_names,
67
61
  )
@@ -88,8 +82,9 @@ module PackStats
88
82
  params(
89
83
  source_code_pathnames: T::Array[Pathname],
90
84
  componentized_source_code_locations: T::Array[Pathname],
91
- packaged_source_code_locations: T::Array[Pathname],
92
85
  app_name: String,
86
+ # This field is deprecated
87
+ packaged_source_code_locations: T.nilable(T::Array[Pathname]),
93
88
  # It is not recommended to set this to true.
94
89
  # Gusto uses this to preserve historical trends in Dashboards as the names of
95
90
  # things changed, but new dashboards can use names that better match current tooling conventions.
@@ -100,15 +95,14 @@ module PackStats
100
95
  def self.get_metrics(
101
96
  source_code_pathnames:,
102
97
  componentized_source_code_locations:,
103
- packaged_source_code_locations:,
104
98
  app_name:,
99
+ packaged_source_code_locations: [],
105
100
  use_gusto_legacy_names: false
106
101
  )
107
102
  all_metrics = Private::DatadogReporter.get_metrics(
108
103
  source_code_files: source_code_files(
109
104
  source_code_pathnames: source_code_pathnames,
110
105
  componentized_source_code_locations: componentized_source_code_locations,
111
- packaged_source_code_locations: packaged_source_code_locations
112
106
  ),
113
107
  app_name: app_name
114
108
  )
@@ -124,18 +118,21 @@ module PackStats
124
118
  params(
125
119
  source_code_pathnames: T::Array[Pathname],
126
120
  componentized_source_code_locations: T::Array[Pathname],
127
- packaged_source_code_locations: T::Array[Pathname]
128
121
  ).returns(T::Array[Private::SourceCodeFile])
129
122
  end
130
123
  def self.source_code_files(
131
124
  source_code_pathnames:,
132
- componentized_source_code_locations:,
133
- packaged_source_code_locations:
125
+ componentized_source_code_locations:
134
126
  )
135
127
 
136
128
  # Sorbet has the wrong signatures for `Pathname#find`, whoops!
137
129
  componentized_file_set = Set.new(componentized_source_code_locations.select(&:exist?).flat_map { |pathname| T.unsafe(pathname).find.to_a })
138
- packaged_file_set = Set.new(packaged_source_code_locations.select(&:exist?).flat_map { |pathname| T.unsafe(pathname).find.to_a })
130
+
131
+ packaged_file_set = Packs.all.flat_map do |pack|
132
+ pack.relative_path.find.to_a
133
+ end
134
+
135
+ packaged_file_set = Set.new(packaged_file_set)
139
136
 
140
137
  source_code_pathnames.map do |pathname|
141
138
  componentized_file = componentized_file_set.include?(pathname)