Module: EventMeter

Defined in:
lib/event_meter.rb,
lib/event_meter/cli.rb,
lib/event_meter/keys.rb,
lib/event_meter/event.rb,
lib/event_meter/rails.rb,
lib/event_meter/errors.rb,
lib/event_meter/rollup.rb,
lib/event_meter/reports.rb,
lib/event_meter/version.rb,
lib/event_meter/index_key.rb,
lib/event_meter/path_name.rb,
lib/event_meter/processor.rb,
lib/event_meter/hash_input.rb,
lib/event_meter/auto_cleanup.rb,
lib/event_meter/time_buckets.rb,
lib/event_meter/write_result.rb,
lib/event_meter/configuration.rb,
lib/event_meter/event_payload.rb,
lib/event_meter/stores/namespace.rb,
lib/event_meter/report_definition.rb,
lib/event_meter/stores/redis_lock.rb,
lib/event_meter/stores/rollup/file.rb,
lib/event_meter/stores/stream/file.rb,
lib/event_meter/stores/file_helpers.rb,
lib/event_meter/stores/rollup/redis.rb,
lib/event_meter/stores/stream/redis.rb,
lib/event_meter/stores/lock_refresher.rb,
lib/event_meter/stores/cleanup_helpers.rb,
lib/event_meter/stores/rollup/postgres.rb,
lib/generators/event_meter/install_generator.rb,
lib/event_meter/stores/rollup/active_record_postgres.rb

Defined Under Namespace

Modules: Generators, HashInput, IndexKey, Keys, PathName, Rails, Stores, TimeBuckets Classes: AlreadyRecordedError, AutoCleanup, CLI, Configuration, ConfigurationError, DefinitionChangedError, DefinitionNotFoundError, Error, Event, EventPayload, LockLostError, Processor, ReportDefinition, Reports, Rollup, UnsupportedQueryError, WriteResult

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.cleanup_history(before:, events: nil, interval_state: true) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/event_meter.rb', line 65

def cleanup_history(before:, events: nil, interval_state: true)
  namespaced_rollup_storage.cleanup_history(
    before: time_value(before),
    events: Array(events).compact.map(&:to_s),
    interval_state: interval_state
  )
end

.compare(name, version:, before:, after:, by: {}) ⇒ Object



81
82
83
# File 'lib/event_meter.rb', line 81

def compare(name, version:, before:, after:, by: {})
  reports(name, version: version).compare(name, version: version, before: before, after: after, by: by)
end

.configurationObject



43
44
45
# File 'lib/event_meter.rb', line 43

def configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



38
39
40
41
# File 'lib/event_meter.rb', line 38

def configure
  yield configuration if block_given?
  configuration
end

.process_pending(name, version:, &block) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/event_meter.rb', line 51

def process_pending(name, version:, &block)
  definition = build_report_definition(name, version: version, &block)

  result = Processor.new(
    configuration: configuration,
    report_definition: definition,
    stream_storage: stream_storage,
    rollup_storage: rollup_storage_for(definition)
  ).process

  auto_cleanup_history unless result.locked
  result
end

.report_definition(name, version:) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/event_meter.rb', line 85

def report_definition(name, version:)
  storage = rollup_storage_for_name(name, version: version)
  stored = storage.report_definition(name: name, version: version)
  raise DefinitionNotFoundError, "no definition stored for #{name} v#{version}" unless stored

  ReportDefinition.from_h(stored).to_h
end

.resetObject



47
48
49
# File 'lib/event_meter.rb', line 47

def reset
  @configuration = Configuration.new
end

.rollup_storageObject



97
98
99
# File 'lib/event_meter.rb', line 97

def rollup_storage
  configuration.rollup_storage
end

.series(name, version:, from: nil, to: nil, every: :minute, by: {}) ⇒ Object



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

def series(name, version:, from: nil, to: nil, every: :minute, by: {})
  reports(name, version: version).series(name, version: version, from: from, to: to, every: every, by: by)
end

.start(name, attributes = nil, **keyword_attributes) ⇒ Object



32
33
34
35
36
# File 'lib/event_meter.rb', line 32

def start(name, attributes = nil, **keyword_attributes)
  Event.start(name, attributes, keyword_attributes, started_at: Time.now.utc)
rescue StandardError => error
  Event.failed(error)
end

.stream_storageObject



93
94
95
# File 'lib/event_meter.rb', line 93

def stream_storage
  configuration.stream_storage
end

.summary(name, version:, from: nil, to: nil, by: {}) ⇒ Object



73
74
75
# File 'lib/event_meter.rb', line 73

def summary(name, version:, from: nil, to: nil, by: {})
  reports(name, version: version).summary(name, version: version, from: from, to: to, by: by)
end