Commit 26c44b87 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Merge branch 'support-multiple-events-file' into 'master'

Support multiple HLL redis counter files

See merge request gitlab-org/gitlab!46956
parents 637fb5eb 3e902a65
......@@ -15,9 +15,9 @@ module Gitlab
CategoryMismatch = Class.new(EventError)
UnknownAggregationOperator = Class.new(EventError)
KNOWN_EVENTS_PATH = 'lib/gitlab/usage_data_counters/known_events.yml'
KNOWN_EVENTS_PATH = 'lib/gitlab/usage_data_counters/known_events/*.yml'
ALLOWED_AGGREGATIONS = %i(daily weekly).freeze
AGGREGATED_METRICS_PATH = 'lib/gitlab/usage_data_counters/aggregated_metrics.yml'
AGGREGATED_METRICS_PATH = 'lib/gitlab/usage_data_counters/aggregated_metrics/*.yml'
ALLOWED_METRICS_AGGREGATIONS = %w[ANY].freeze
# Track event on entity_id
......@@ -102,6 +102,14 @@ module Gitlab
end
end
def known_events
@known_events ||= load_events(KNOWN_EVENTS_PATH)
end
def aggregated_metrics
@aggregated_metrics ||= load_events(AGGREGATED_METRICS_PATH)
end
private
def calculate_count_for_aggregation(aggregation, start_date:, end_date:)
......@@ -141,12 +149,10 @@ module Gitlab
end
end
def known_events
@known_events ||= load_yaml_from_path(KNOWN_EVENTS_PATH)
end
def aggregated_metrics
@aggregated_metrics ||= (load_yaml_from_path(AGGREGATED_METRICS_PATH) || [])
def load_events(wildcard)
Dir[wildcard].each_with_object([]) do |path, events|
events.push(*load_yaml_from_path(path))
end
end
def load_yaml_from_path(path)
......
......@@ -14,12 +14,10 @@ RSpec.describe 'aggregated metrics' do
end
let_it_be(:known_events) do
YAML.load_file(
Rails.root.join(Gitlab::UsageDataCounters::HLLRedisCounter::KNOWN_EVENTS_PATH)
).map(&:with_indifferent_access)
Gitlab::UsageDataCounters::HLLRedisCounter.known_events
end
YAML.load_file(Rails.root.join(Gitlab::UsageDataCounters::HLLRedisCounter::AGGREGATED_METRICS_PATH))&.map(&:with_indifferent_access).tap do |aggregated_metrics|
Gitlab::UsageDataCounters::HLLRedisCounter.aggregated_metrics.tap do |aggregated_metrics|
it 'all events has unique name' do
event_names = aggregated_metrics&.map { |event| event[:name] }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment