2020-11-24 15:15:51 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module UsageDataCounters
|
|
|
|
class KubernetesAgentCounter < BaseCounter
|
|
|
|
PREFIX = 'kubernetes_agent'
|
2021-06-08 01:23:25 +05:30
|
|
|
KNOWN_EVENTS = %w[gitops_sync k8s_api_proxy_request].freeze
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
class << self
|
2021-06-08 01:23:25 +05:30
|
|
|
def increment_event_counts(events)
|
|
|
|
validate!(events)
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
events.each do |event, incr|
|
|
|
|
# rather then hitting redis for this no-op, we return early
|
|
|
|
next if incr == 0
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
increment_by(redis_key(event), incr)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def validate!(events)
|
|
|
|
events.each do |event, incr|
|
|
|
|
raise ArgumentError, "unknown event #{event}" unless event.in?(KNOWN_EVENTS)
|
|
|
|
raise ArgumentError, "#{event} count must be greater than or equal to zero" if incr < 0
|
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|