Class: PackStats::Private::DatadogReporter

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

Class Method Summary collapse

Class Method Details

.get_metrics(source_code_files:, app_name:) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/pack_stats/private/datadog_reporter.rb', line 24

def self.get_metrics(source_code_files:, app_name:)
  packages = ParsePackwerk.all

  [
    *Metrics::Files.get_metrics(source_code_files, app_name),
    *Metrics::Packages.get_package_metrics(packages, app_name),
    *Metrics::PackagesByTeam.get_package_metrics_by_team(packages, app_name),
  ]
end

.report!(datadog_client:, report_time:, metrics:) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/pack_stats/private/datadog_reporter.rb', line 43

def self.report!(datadog_client:, report_time:, metrics:)
  #
  # Batching the metrics sends a post request to DD
  # we want to split this up into chunks of 1000 so that as we add more metrics,
  # our payload is not rejected for being too large
  #
  metrics.each_slice(1000).each do |metric_slice|
    datadog_client.batch_metrics do
      metric_slice.each do |metric|
        datadog_client.emit_points(metric.name, [[report_time, metric.count]], type: 'gauge', tags: metric.tags.map(&:to_s))
      end
    end
  end
end