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

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

54 lines
1.3 KiB
Ruby
Raw Normal View History

2021-06-08 01:23:25 +05:30
# frozen_string_literal: true
module Gitlab
module Usage
module Metrics
module Instrumentations
class RedisHLLMetric < BaseMetric
# Usage example
#
2021-09-04 01:27:46 +05:30
# In metric YAML defintion
# instrumentation_class: RedisHLLMetric
# events:
# - g_analytics_valuestream
2021-06-08 01:23:25 +05:30
# end
2021-09-04 01:27:46 +05:30
def initialize(time_frame:, options: {})
super
raise ArgumentError, "options events are required" unless metric_events.present?
end
def metric_events
options[:events]
2021-06-08 01:23:25 +05:30
end
def value
redis_usage_data do
2021-09-04 01:27:46 +05:30
event_params = time_constraints.merge(event_names: metric_events)
2021-06-08 01:23:25 +05:30
Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(**event_params)
end
end
2021-09-04 01:27:46 +05:30
def suggested_name
2021-10-27 15:23:28 +05:30
Gitlab::Usage::Metrics::NameSuggestion.for(:redis)
2021-09-04 01:27:46 +05:30
end
2021-06-08 01:23:25 +05:30
private
def time_constraints
case time_frame
when '28d'
2021-09-04 01:27:46 +05:30
monthly_time_range
2021-06-08 01:23:25 +05:30
when '7d'
2021-09-04 01:27:46 +05:30
weekly_time_range
2021-06-08 01:23:25 +05:30
else
2021-09-04 01:27:46 +05:30
raise "Unknown time frame: #{time_frame} for RedisHLLMetric"
2021-06-08 01:23:25 +05:30
end
end
end
end
end
end
end