Class: PackStats::Private::Metrics::Dependencies

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/pack_stats/private/metrics/dependencies.rb

Class Method Summary collapse

Class Method Details

.get_metrics(prefix, packages, app_name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/pack_stats/private/metrics/dependencies.rb', line 11

def self.get_metrics(prefix, packages, app_name)
  all_metrics = T.let([], T::Array[GaugeMetric])
  inbound_explicit_dependency_by_package = {}
  packages.each do |package|
    package.dependencies.each do |explicit_dependency|
      inbound_explicit_dependency_by_package[explicit_dependency] ||= []
      inbound_explicit_dependency_by_package[explicit_dependency] << package.name
    end
  end

  packages.each do |package| # rubocop:disable Style/CombinableLoops
    package_tags = Metrics.tags_for_package(package, app_name)

    #
    # EXPLICIT DEPENDENCIES
    #
    package.dependencies.each do |explicit_dependency|
      to_package = ParsePackwerk.find(explicit_dependency)
      if to_package.nil?
        raise StandardError, "Could not find matching package #{explicit_dependency}"
      end

      owner = Private.package_owner(to_package)
      tags = package_tags + [Tag.for('other_package', Metrics.humanized_package_name(explicit_dependency))] + Metrics.tags_for_other_team(owner)
      all_metrics << GaugeMetric.for('by_package.dependencies.by_other_package.count', 1, tags)
    end

    all_metrics << GaugeMetric.for('by_package.dependencies.count', package.dependencies.count, package_tags)
    all_metrics << GaugeMetric.for('by_package.depended_on.count', inbound_explicit_dependency_by_package[package.name]&.count || 0, package_tags)
  end

  all_metrics
end