debian-mirror-gitlab/lib/gitlab/usage/metrics/instrumentations/redis_metric.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

62 lines
1.4 KiB
Ruby
Raw Normal View History

2021-10-27 15:23:28 +05:30
# frozen_string_literal: true
module Gitlab
module Usage
module Metrics
module Instrumentations
# Usage example
#
# In metric YAML definition:
#
# instrumentation_class: RedisMetric
# options:
# event: pushes
2022-10-11 01:57:18 +05:30
# prefix: source_code
2021-10-27 15:23:28 +05:30
#
class RedisMetric < BaseMetric
2022-10-11 01:57:18 +05:30
include Gitlab::UsageDataCounters::RedisCounter
USAGE_PREFIX = "USAGE_"
2021-10-27 15:23:28 +05:30
def initialize(time_frame:, options: {})
super
raise ArgumentError, "'event' option is required" unless metric_event.present?
2022-10-11 01:57:18 +05:30
raise ArgumentError, "'prefix' option is required" unless prefix.present?
2021-10-27 15:23:28 +05:30
end
def metric_event
options[:event]
end
2022-10-11 01:57:18 +05:30
def prefix
options[:prefix]
2021-10-27 15:23:28 +05:30
end
2022-10-11 01:57:18 +05:30
def include_usage_prefix?
options.fetch(:include_usage_prefix, true)
2021-10-27 15:23:28 +05:30
end
def value
redis_usage_data do
2022-10-11 01:57:18 +05:30
total_count(redis_key)
2021-10-27 15:23:28 +05:30
end
end
def suggested_name
Gitlab::Usage::Metrics::NameSuggestion.for(:redis)
end
2022-10-11 01:57:18 +05:30
private
def redis_key
key = "#{prefix}_#{metric_event}".upcase
key.prepend(USAGE_PREFIX) if include_usage_prefix?
key
end
2021-10-27 15:23:28 +05:30
end
end
end
end
end