Class: ThreeScale::Backend::Stats::Aggregator

Inherits:
Object
  • Object
show all
Extended by:
Configurable, Logging, Keys, ThreeScale::Backend::StorageKeyHelpers
Defined in:
lib/3scale/backend/stats/aggregator.rb

Overview

This class contains several methods that deal with buckets, which are only used in the SaaS analytics system.

Class Method Summary collapse

Methods included from Logging

enable!, included

Methods included from Keys

application_key_prefix, application_response_code_value_key, application_usage_value_key, applications_key_prefix, changed_keys_bucket_key, changed_keys_key, counter_key, metric_key_prefix, response_code_key_prefix, service_key_prefix, service_response_code_value_key, service_usage_value_key, set_of_apps_with_traffic, transaction_keys

Methods included from ThreeScale::Backend::StorageKeyHelpers

encode_key

Methods included from Configurable

configuration, configuration=, included

Class Method Details

.process(transactions) ⇒ Object

This method stores the events in buckets if that option is enabled or if it was disable because of an emergency (not because a user did it manually), and Kinesis has already consumed all the pending buckets.



42
43
44
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
# File 'lib/3scale/backend/stats/aggregator.rb', line 42

def process(transactions)
  current_bucket = nil

  if configuration.can_create_event_buckets
    # Only disable indicating emergency if bucket storage is enabled.
    # Otherwise, we might indicate emergency when a user manually
    # disabled it previously.
    if Storage.enabled? && buckets_limit_exceeded?
      Storage.disable!(true)
      log_bucket_creation_disabled
    elsif save_in_bucket?
      Storage.enable! unless Storage.enabled?
      current_bucket = Time.now.utc.beginning_of_bucket(stats_bucket_size)
                                   .to_not_compact_s
    end
  end

  touched_apps = aggregate(transactions, current_bucket)

  ApplicationEvents.generate(touched_apps.values)
  update_alerts(transactions)
  begin
    ApplicationEvents.ping
  rescue ApplicationEvents::PingFailed => e
    # we could not ping the frontend, log it
    logger.notify e
  end
end