Class: ActiveEndpoint::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/active_endpoint/storage.rb

Constant Summary collapse

STORING_FIELDS =
[
  :body,
  :response,
  :started_at,
  :finished_at,
  :duration,
  :endpoint,
  :ip,
  :params,
  :path,
  :request_method,
  :url,
  :xhr
].freeze
LOGGING_FIELDS =
[
  :base_url,
  :content_charset,
  :content_length,
  :content_type,
  :fullpath,
  :http_version,
  :http_connection,
  :http_accept_encoding,
  :http_accept_language,
  :media_type,
  :media_type_params,
  :method,
  :path_info,
  :pattern,
  :port,
  :protocol,
  :server_name,
  :ssl
].freeze

Class Method Summary collapse

Class Method Details

.clean!(endpoint, period) ⇒ Object



77
78
79
# File 'lib/active_endpoint/storage.rb', line 77

def clean!(endpoint, period)
  ActiveEndpoint::Probe.registred.probe(endpoint).taken_before(period).destroy_all
end

.handle_creation(probe) ⇒ Object



71
72
73
74
75
# File 'lib/active_endpoint/storage.rb', line 71

def handle_creation(probe)
  probe.save
rescue => error
  ActiveEndpoint.logger.error('ActiveEndpoint::Probe', error)
end

.notifierObject



40
41
42
# File 'lib/active_endpoint/storage.rb', line 40

def notifier
  ActiveSupport::Notifications
end

.probe_params(transaction_id, probe) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/active_endpoint/storage.rb', line 44

def probe_params(transaction_id, probe)
  request = probe.delete(:request)
  request_body = request.delete(:body)

  response = probe.delete(:response)
  response_body = response.present? ? response[:body] : nil

  params = {
    uuid: transaction_id,
    response: response_body ? Base64.encode64(response_body) : '',
    started_at: probe[:created_at],
    finished_at: probe[:finished_at],
    duration: probe[:finished_at] ? (probe[:finished_at] - probe[:created_at]).second.round(3) : 0,
    body: request_body.is_a?(Puma::NullIO) ? '' : request_body
  }.merge(request)

  [params.dup.except(*LOGGING_FIELDS), params.dup.except(*STORING_FIELDS)]
end

.register!(params) ⇒ Object



67
68
69
# File 'lib/active_endpoint/storage.rb', line 67

def register!(params)
  handle_creation(ActiveEndpoint::UnregistredProbe.new(params.merge(endpoint: :unregistred)))
end

.store!(params) ⇒ Object



63
64
65
# File 'lib/active_endpoint/storage.rb', line 63

def store!(params)
  handle_creation(ActiveEndpoint::Probe.new(params))
end