2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab::UsageDataCounters
|
|
|
|
class BaseCounter
|
|
|
|
extend RedisCounter
|
|
|
|
|
|
|
|
UnknownEvent = Class.new(StandardError)
|
|
|
|
|
|
|
|
class << self
|
|
|
|
def redis_key(event)
|
2020-01-01 13:55:28 +05:30
|
|
|
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(UnknownEvent.new, event: event) unless known_events.include?(event.to_s)
|
2019-10-12 21:52:04 +05:30
|
|
|
|
|
|
|
"USAGE_#{prefix}_#{event}".upcase
|
|
|
|
end
|
|
|
|
|
|
|
|
def count(event)
|
|
|
|
increment(redis_key event)
|
|
|
|
end
|
|
|
|
|
|
|
|
def read(event)
|
|
|
|
total_count(redis_key event)
|
|
|
|
end
|
|
|
|
|
|
|
|
def totals
|
|
|
|
known_events.map { |e| ["#{prefix}_#{e}".to_sym, read(e)] }.to_h
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def known_events
|
|
|
|
self::KNOWN_EVENTS
|
|
|
|
end
|
|
|
|
|
|
|
|
def prefix
|
|
|
|
self::PREFIX
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|