Class: Sqreen::Legacy::OldEventSubmissionStrategy

Inherits:
Object
  • Object
show all
Includes:
Sqreen::Log::Loggable
Defined in:
lib/sqreen/legacy/old_event_submission_strategy.rb

Overview

see also Sqreen::Signals::SignalsSubmissionStrategy usage in Sqreen:Session

Constant Summary collapse

RETRY_MANY =
301

Instance Method Summary collapse

Methods included from Sqreen::Log::Loggable

included, #logger

Constructor Details

#initialize(post_proc) ⇒ OldEventSubmissionStrategy

Returns a new instance of OldEventSubmissionStrategy.



20
21
22
# File 'lib/sqreen/legacy/old_event_submission_strategy.rb', line 20

def initialize(post_proc)
  @post_proc = post_proc
end

Instance Method Details

#post_attack(attack) ⇒ Object

Parameters:



31
32
33
# File 'lib/sqreen/legacy/old_event_submission_strategy.rb', line 31

def post_attack(attack)
  post('attack', EventToHash.convert_attack(attack), {}, RETRY_MANY)
end

#post_batch(events) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/sqreen/legacy/old_event_submission_strategy.rb', line 53

def post_batch(events)
  batch = events.map do |event|
    h = case event
        when AggregatedMetric
          logger.warn "Aggregated metric event in non-signal mode. Signals disabled at runtime?"
          next
        when Sqreen::Kit::Signals::Signal
          logger.warn "Signal event in non-signal mode"
          next
        when Sqreen::Kit::Signals::Trace
          logger.warn "Trace event in non-signal mode"
          next
        when Attack # in practice only found inside req rec
          EventToHash.convert_attack event
        when RemoteException
          EventToHash.convert_exception event
        when RequestRecord
          EventToHash.convert_request_record event
        else
          logger.warn "Unexpected event type: #{event}"
          next
        end
    h['event_type'] = event_kind(event)
    h
  end
  Sqreen.log.debug do
    tally = Hash[events.group_by(&:class).map { |k, v| [k, v.count] }]
    "Doing batch with the following tally of event types: #{tally}"
  end
  post('batch', { batch: batch.compact }, {}, RETRY_MANY)
end

#post_metrics(metrics) ⇒ Object



24
25
26
27
28
# File 'lib/sqreen/legacy/old_event_submission_strategy.rb', line 24

def post_metrics(metrics)
  return if metrics.nil? || metrics.empty?
  payload = { metrics: metrics.map { |m| EventToHash.convert_agg_metric(m) } }
  post('metrics', payload, {}, RETRY_MANY)
end

#post_request_record(request_record) ⇒ Object

Parameters:



36
37
38
39
# File 'lib/sqreen/legacy/old_event_submission_strategy.rb', line 36

def post_request_record(request_record)
  rr_hash = EventToHash.convert_request_record(request_record)
  post('request_record', rr_hash, {}, RETRY_MANY)
end

#post_sqreen_exception(exception) ⇒ Object

Post an exception to Sqreen for analysis

Parameters:



43
44
45
46
47
48
49
50
51
# File 'lib/sqreen/legacy/old_event_submission_strategy.rb', line 43

def post_sqreen_exception(exception)
  data = EventToHash.convert_exception(exception)
  post('sqreen_exception', data, {}, 5)
rescue StandardError => e
  logger.warn(format('Could not post exception (network down? %s) %s',
                     e.inspect,
                     exception.inspect))
  nil
end