Module: Contrast::Utils::Reporting::ApplicationActivityBatchUtils

Included in:
Agent::Middleware, Agent::Protect::WorthWatchingInputAnalyzer
Defined in:
lib/contrast/utils/reporting/application_activity_batch_utils.rb

Overview

ApplicationActivityBatchUtils handles batching and reporting of ApplicationActivity events to TeamServer at a set interval

Constant Summary collapse

DEFAULT_REPORTING_INTERVAL_MS =
30_000.cs__freeze

Instance Method Summary collapse

Instance Method Details

#activity_batchObject

Returns Contrast::Agent::Reporting::ApplicationActivity.

Returns:

  • Contrast::Agent::Reporting::ApplicationActivity



41
42
43
44
45
46
# File 'lib/contrast/utils/reporting/application_activity_batch_utils.rb', line 41

def activity_batch
  return @activity_batch unless @activity_batch.nil?

  reset_activity_batch
  @activity_batch
end

#add_activity_to_batch(activity) ⇒ Object

Merge a ApplicationActivity into the ApplicationActivityBatch

Parameters:



22
23
24
25
26
27
28
# File 'lib/contrast/utils/reporting/application_activity_batch_utils.rb', line 22

def add_activity_to_batch activity
  return unless activity
  return if activity.defend.attackers.empty?

  merge_attackers(activity)
  activity_batch.attach_inventory(activity.inventory) unless activity.inventory.empty?
end

#batch_ageInteger

Returns time when activity batch was created in ms.

Returns:

  • (Integer)

    time when activity batch was created in ms



16
17
18
# File 'lib/contrast/utils/reporting/application_activity_batch_utils.rb', line 16

def batch_age
  @_batch_age ||= Contrast::Utils::Timer.now_ms
end

#report_batchObject

If the batch can be reported, mask the data and add it to the reporting queue, then reset the activity_batch



31
32
33
34
35
36
37
38
# File 'lib/contrast/utils/reporting/application_activity_batch_utils.rb', line 31

def report_batch
  return unless report_batch?
  return unless (reporter = Contrast::Agent.reporter)

  Contrast::Agent::Reporting::Masker.mask(activity_batch)
  reporter&.send_event(activity_batch)
  reset_activity_batch
end