Class: ThreeScale::Backend::Stats::Storage

Inherits:
Object
  • Object
show all
Extended by:
Memoizer::Decorator
Defined in:
lib/3scale/backend/stats/storage.rb

Class Method Summary collapse

Methods included from Memoizer::Decorator

included

Class Method Details

.bucket_readerObject



58
59
60
61
62
# File 'lib/3scale/backend/stats/storage.rb', line 58

def bucket_reader
  @bucket_reader ||= BucketReader.new(config.stats.bucket_size,
                                      bucket_storage,
                                      storage)
end

.bucket_storageObject



54
55
56
# File 'lib/3scale/backend/stats/storage.rb', line 54

def bucket_storage
  @bucket_storage ||= BucketStorage.new(stats_storage)
end

.disable!(emergency = false) ⇒ Object

Bucket storage can be disabled because an ‘emergency’ happened. If too many buckets accumulate, we disable the feature because the memory occupied by Redis can grow very quickly. Check the code in the Aggregator class to check the conditions that trigger this ‘emergency’.



36
37
38
39
40
41
42
43
44
# File 'lib/3scale/backend/stats/storage.rb', line 36

def disable!(emergency = false)
  storage.del(STATS_ENABLED_KEY)

  if emergency
    storage.set(DISABLED_BECAUSE_EMERGENCY_KEY, '1')
  else
    storage.del(DISABLED_BECAUSE_EMERGENCY_KEY)
  end
end

.enable!Object



27
28
29
# File 'lib/3scale/backend/stats/storage.rb', line 27

def enable!
  storage.set(STATS_ENABLED_KEY, '1')
end

.enabled?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/3scale/backend/stats/storage.rb', line 22

def enabled?
  storage.get(STATS_ENABLED_KEY).to_i == 1
end

.kinesis_adapterObject



64
65
66
67
68
69
70
# File 'lib/3scale/backend/stats/storage.rb', line 64

def kinesis_adapter
  @kinesis_adapter ||= Analytics::Kinesis::Adapter.new(
    config.kinesis_stream_name,
    kinesis_client,
    stats_storage
  )
end

.last_disable_was_emergency?Boolean

Returns whether the last time that bucket storage was disabled was because of an emergency. Notice that this method can return ‘true’ even when enabled? is true.

Returns:

  • (Boolean)


49
50
51
# File 'lib/3scale/backend/stats/storage.rb', line 49

def last_disable_was_emergency?
  storage.get(DISABLED_BECAUSE_EMERGENCY_KEY).to_i == 1
end