diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-11 18:09:37 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-11 18:09:37 +0300 |
commit | a210c43e0aca0311cc1d3d381763b25979ec72dc (patch) | |
tree | 0325d173da7a6e7bd6c2cdf450d0aa1c4e142d0f /lib/gitlab/usage_counters | |
parent | c9687bdf58e9d4a9c3942f587bd4841f42e3b5de (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/usage_counters')
-rw-r--r-- | lib/gitlab/usage_counters/common.rb | 30 | ||||
-rw-r--r-- | lib/gitlab/usage_counters/pod_logs.rb | 11 |
2 files changed, 41 insertions, 0 deletions
diff --git a/lib/gitlab/usage_counters/common.rb b/lib/gitlab/usage_counters/common.rb new file mode 100644 index 00000000000..a5bdac430f4 --- /dev/null +++ b/lib/gitlab/usage_counters/common.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +module Gitlab + module UsageCounters + class Common + class << self + def increment(project_id) + Gitlab::Redis::SharedState.with { |redis| redis.hincrby(base_key, project_id, 1) } + end + + def usage_totals + Gitlab::Redis::SharedState.with do |redis| + total_sum = 0 + + totals = redis.hgetall(base_key).each_with_object({}) do |(project_id, count), result| + total_sum += result[project_id.to_i] = count.to_i + end + + totals[:total] = total_sum + totals + end + end + + def base_key + raise NotImplementedError + end + end + end + end +end diff --git a/lib/gitlab/usage_counters/pod_logs.rb b/lib/gitlab/usage_counters/pod_logs.rb new file mode 100644 index 00000000000..94e29d2fad7 --- /dev/null +++ b/lib/gitlab/usage_counters/pod_logs.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Gitlab + module UsageCounters + class PodLogs < Common + def self.base_key + 'POD_LOGS_USAGE_COUNTS' + end + end + end +end |