2019-09-30 21:07:59 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module UsageDataCounters
|
|
|
|
class WebIdeCounter
|
|
|
|
extend RedisCounter
|
2020-05-24 23:13:21 +05:30
|
|
|
KNOWN_EVENTS = %i[commits views merge_requests previews terminals pipelines].freeze
|
|
|
|
PREFIX = 'web_ide'
|
2019-09-30 21:07:59 +05:30
|
|
|
|
|
|
|
class << self
|
|
|
|
def increment_commits_count
|
2020-05-24 23:13:21 +05:30
|
|
|
increment(redis_key('commits'))
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
2019-10-12 21:52:04 +05:30
|
|
|
|
|
|
|
def increment_merge_requests_count
|
2020-05-24 23:13:21 +05:30
|
|
|
increment(redis_key('merge_requests'))
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
def increment_views_count
|
|
|
|
increment(redis_key('views'))
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
def increment_terminals_count
|
|
|
|
increment(redis_key('terminals'))
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
def increment_pipelines_count
|
|
|
|
increment(redis_key('pipelines'))
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
def increment_previews_count
|
|
|
|
return unless Gitlab::CurrentSettings.web_ide_clientside_preview_enabled?
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
increment(redis_key('previews'))
|
|
|
|
end
|
|
|
|
|
|
|
|
def totals
|
|
|
|
KNOWN_EVENTS.map { |event| [counter_key(event), total_count(redis_key(event))] }.to_h
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
def fallback_totals
|
|
|
|
KNOWN_EVENTS.map { |event| [counter_key(event), -1] }.to_h
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def redis_key(event)
|
|
|
|
"#{PREFIX}_#{event}_count".upcase
|
|
|
|
end
|
|
|
|
|
|
|
|
def counter_key(event)
|
|
|
|
"#{PREFIX}_#{event}".to_sym
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|