Module: PackStats

Extended by:
T::Sig
Defined in:
lib/pack_stats/tag.rb,
lib/pack_stats.rb,
lib/pack_stats/tags.rb,
lib/pack_stats/private.rb,
lib/pack_stats/gauge_metric.rb,
lib/pack_stats/private/metrics.rb,
lib/pack_stats/private/metrics/files.rb,
lib/pack_stats/private/datadog_reporter.rb,
lib/pack_stats/private/metrics/packages.rb,
lib/pack_stats/private/source_code_file.rb,
lib/pack_stats/private/metrics/dependencies.rb,
lib/pack_stats/private/metrics/public_usage.rb,
lib/pack_stats/private/metrics/packages_by_team.rb,
lib/pack_stats/private/metrics/packwerk_checker_usage.rb

Overview

typed: strict frozen_string_literal: true

Defined Under Namespace

Modules: Tags Classes: GaugeMetric, Tag

Constant Summary collapse

ROOT_PACKAGE_NAME =
T.let('root'.freeze, String)
DEFAULT_COMPONENTIZED_SOURCE_CODE_LOCATIONS =
T.let(
  [
    Pathname.new('components'),
    Pathname.new('gems'),
  ].freeze, T::Array[Pathname]
)

Class Method Summary collapse

Class Method Details

.get_metrics(source_code_pathnames:, componentized_source_code_locations:, app_name:, packaged_source_code_locations: [], max_enforcements_tag_value: false) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/pack_stats.rb', line 91

def self.get_metrics(
  source_code_pathnames:,
  componentized_source_code_locations:,
  app_name:,
  packaged_source_code_locations: [],
  max_enforcements_tag_value: false
)

  GaugeMetric.set_max_enforcements_tag(max_enforcements_tag_value)

  Private::DatadogReporter.get_metrics(
    source_code_files: source_code_files(
      source_code_pathnames: source_code_pathnames,
      componentized_source_code_locations: componentized_source_code_locations,
    ),
    app_name: app_name
  )
end

.report_to_datadog!(datadog_client:, app_name:, source_code_pathnames:, componentized_source_code_locations: DEFAULT_COMPONENTIZED_SOURCE_CODE_LOCATIONS, report_time: Time.now, verbose: false, packaged_source_code_locations: [], max_enforcements_tag_value: false) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/pack_stats.rb', line 45

def self.report_to_datadog!(
  datadog_client:,
  app_name:,
  source_code_pathnames:,
  componentized_source_code_locations: DEFAULT_COMPONENTIZED_SOURCE_CODE_LOCATIONS,
  report_time: Time.now, # rubocop:disable Rails/TimeZone
  verbose: false,
  packaged_source_code_locations: [],
  max_enforcements_tag_value: false
)

  all_metrics = self.get_metrics(
    source_code_pathnames: source_code_pathnames,
    componentized_source_code_locations: componentized_source_code_locations,
    app_name: app_name,
    max_enforcements_tag_value: max_enforcements_tag_value,
  )

  # This helps us debug what metrics are being sent
  if verbose
    all_metrics.each do |metric|
      puts "Sending metric: #{metric}"
    end
  end

  Private::DatadogReporter.report!(
    datadog_client: datadog_client,
    report_time: report_time,
    metrics: all_metrics
  )
end