summaryrefslogtreecommitdiff
path: root/lib/gitlab/usage_data_counters
diff options
context:
space:
mode:
authorAlex Kalderimis <akalderimis@gitlab.com>2019-07-21 01:26:19 +0000
committerDouwe Maan <douwe@gitlab.com>2019-07-21 01:26:19 +0000
commit7320758611b8d8c28fb179f970e015a72357b94d (patch)
treec74e9e90c6f0fd35f5b3cf08466c2947b39128ca /lib/gitlab/usage_data_counters
parent66394bd1b7c98d7a6abbeade068b8b9c1b838ddf (diff)
downloadgitlab-ce-7320758611b8d8c28fb179f970e015a72357b94d.tar.gz
Count wiki page creation
This adds a counter to count page creation, which is reflected in the usage-data we collect. The number created is stored in Redis, avoiding DB access.
Diffstat (limited to 'lib/gitlab/usage_data_counters')
-rw-r--r--lib/gitlab/usage_data_counters/web_ide_counter.rb8
-rw-r--r--lib/gitlab/usage_data_counters/wiki_page_counter.rb32
2 files changed, 40 insertions, 0 deletions
diff --git a/lib/gitlab/usage_data_counters/web_ide_counter.rb b/lib/gitlab/usage_data_counters/web_ide_counter.rb
index 899ad0db9c0..0718c1dd761 100644
--- a/lib/gitlab/usage_data_counters/web_ide_counter.rb
+++ b/lib/gitlab/usage_data_counters/web_ide_counter.rb
@@ -33,6 +33,14 @@ module Gitlab
def total_views_count
total_count(VIEWS_COUNT_KEY)
end
+
+ def totals
+ {
+ web_ide_commits: total_commits_count,
+ web_ide_views: total_views_count,
+ web_ide_merge_requests: total_merge_requests_count
+ }
+ end
end
end
end
diff --git a/lib/gitlab/usage_data_counters/wiki_page_counter.rb b/lib/gitlab/usage_data_counters/wiki_page_counter.rb
new file mode 100644
index 00000000000..c8b59a3160c
--- /dev/null
+++ b/lib/gitlab/usage_data_counters/wiki_page_counter.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+module Gitlab::UsageDataCounters
+ class WikiPageCounter
+ extend RedisCounter
+
+ KNOWN_EVENTS = %w[create update delete].map(&:freeze).freeze
+
+ UnknownEvent = Class.new(StandardError)
+
+ class << self
+ # Each event gets a unique Redis key
+ def redis_key(event)
+ raise UnknownEvent, event unless KNOWN_EVENTS.include?(event.to_s)
+
+ "USAGE_WIKI_PAGES_#{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| ["wiki_pages_#{e}".to_sym, read(e)] }.to_h
+ end
+ end
+ end
+end