summaryrefslogtreecommitdiff
path: root/lib/gitlab/usage/metrics/aggregates/sources/redis_hll.rb
blob: 009b8e6254352d4ce774b4e26a83d8b9e022e60b (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
# frozen_string_literal: true

module Gitlab
  module Usage
    module Metrics
      module Aggregates
        module Sources
          UnionNotAvailable = Class.new(AggregatedMetricError)

          class RedisHll
            extend Calculations::Intersection
            def self.calculate_metrics_union(metric_names:, start_date:, end_date:, recorded_at: nil)
              union = Gitlab::UsageDataCounters::HLLRedisCounter
                .calculate_events_union(event_names: metric_names, start_date: start_date, end_date: end_date)

              return union if union >= 0

              raise UnionNotAvailable, "Union data not available for #{metric_names}"
            end
          end
        end
      end
    end
  end
end