Welcome to mirror list, hosted at ThFree Co, Russian Federation.

time_series_storable.rb « usage « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 83f62b8c1c7a8f9ca3e690569d12a961d2ce0fc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# frozen_string_literal: true

module Gitlab
  module Usage
    module TimeSeriesStorable
      # requires a #redis_key(event, date) method to be defined
      def keys_for_aggregation(events:, start_date:, end_date:)
        # we always keep 1 week of margin
        # .end_of_week is necessary to make sure this works for 1 week long periods too
        end_date = end_date.end_of_week - 1.week
        (start_date.to_date..end_date.to_date).flat_map do |date|
          events.map { |event| redis_key(event, date) }
        end.uniq
      end

      def apply_time_aggregation(key, time)
        year_week = time.strftime('%G-%V')
        "#{key}-#{year_week}"
      end
    end
  end
end