blob: 140d56f0d42eb6e6e543a2b242118855c66c75ac (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# frozen_string_literal: true
module Gitlab
module Usage
module Metrics
module Instrumentations
class RedisHLLMetric < BaseMetric
# Usage example
#
# class CountUsersVisitingAnalyticsValuestreamMetric < RedisHLLMetric
# event_names :g_analytics_valuestream
# end
class << self
def event_names(events = nil)
@metric_events = events
end
attr_reader :metric_events
end
def value
redis_usage_data do
event_params = time_constraints.merge(event_names: self.class.metric_events)
Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(**event_params)
end
end
private
def time_constraints
case time_frame
when '28d'
{ start_date: 4.weeks.ago.to_date, end_date: Date.current }
when '7d'
{ start_date: 7.days.ago.to_date, end_date: Date.current }
else
raise "Unknown time frame: #{time_frame} for TimeConstraint"
end
end
end
end
end
end
end
|