2019-07-17 19:45:35 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module UsageDataCounters
|
|
|
|
class WebIdeCounter
|
|
|
|
extend RedisCounter
|
2020-05-13 20:07:47 -04:00
|
|
|
KNOWN_EVENTS = %i[commits views merge_requests previews terminals pipelines].freeze
|
2020-05-05 23:09:33 -04:00
|
|
|
PREFIX = 'web_ide'
|
2019-07-17 19:45:35 -04:00
|
|
|
|
|
|
|
class << self
|
|
|
|
def increment_commits_count
|
2020-05-05 23:09:33 -04:00
|
|
|
increment(redis_key('commits'))
|
2019-07-17 19:45:35 -04:00
|
|
|
end
|
2019-07-19 07:11:27 -04:00
|
|
|
|
|
|
|
def increment_merge_requests_count
|
2020-05-05 23:09:33 -04:00
|
|
|
increment(redis_key('merge_requests'))
|
2019-07-19 07:11:27 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def increment_views_count
|
2020-05-05 23:09:33 -04:00
|
|
|
increment(redis_key('views'))
|
2019-07-19 07:11:27 -04:00
|
|
|
end
|
2019-07-20 21:26:19 -04:00
|
|
|
|
2020-05-11 14:09:55 -04:00
|
|
|
def increment_terminals_count
|
|
|
|
increment(redis_key('terminals'))
|
|
|
|
end
|
|
|
|
|
2020-05-13 20:07:47 -04:00
|
|
|
def increment_pipelines_count
|
|
|
|
increment(redis_key('pipelines'))
|
|
|
|
end
|
|
|
|
|
2019-11-06 04:06:23 -05:00
|
|
|
def increment_previews_count
|
|
|
|
return unless Gitlab::CurrentSettings.web_ide_clientside_preview_enabled?
|
|
|
|
|
2020-05-05 23:09:33 -04:00
|
|
|
increment(redis_key('previews'))
|
2019-11-06 04:06:23 -05:00
|
|
|
end
|
|
|
|
|
2020-05-05 23:09:33 -04:00
|
|
|
def totals
|
|
|
|
KNOWN_EVENTS.map { |event| [counter_key(event), total_count(redis_key(event))] }.to_h
|
2019-11-06 04:06:23 -05:00
|
|
|
end
|
|
|
|
|
2020-05-05 23:09:33 -04:00
|
|
|
def fallback_totals
|
|
|
|
KNOWN_EVENTS.map { |event| [counter_key(event), -1] }.to_h
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def redis_key(event)
|
|
|
|
"#{PREFIX}_#{event}_count".upcase
|
|
|
|
end
|
|
|
|
|
|
|
|
def counter_key(event)
|
|
|
|
"#{PREFIX}_#{event}".to_sym
|
2019-07-20 21:26:19 -04:00
|
|
|
end
|
2019-07-17 19:45:35 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|