2021-02-05 07:09:31 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-11-12 01:09:02 -05:00
|
|
|
require 'logger'
|
|
|
|
|
|
|
|
desc "GitLab | Packages | Events | Generate hll counter events file for packages"
|
|
|
|
namespace :gitlab do
|
|
|
|
namespace :packages do
|
|
|
|
namespace :events do
|
|
|
|
task generate: :environment do
|
2021-01-05 10:10:02 -05:00
|
|
|
Rake::Task["gitlab:packages:events:generate_counts"].invoke
|
2020-12-07 19:09:45 -05:00
|
|
|
Rake::Task["gitlab:packages:events:generate_unique"].invoke
|
|
|
|
rescue => e
|
|
|
|
logger.error("Error building events list: #{e}")
|
|
|
|
end
|
|
|
|
|
2021-01-05 10:10:02 -05:00
|
|
|
task generate_counts: :environment do
|
2020-11-12 01:09:02 -05:00
|
|
|
logger = Logger.new(STDOUT)
|
|
|
|
logger.info('Building list of package events...')
|
|
|
|
|
2021-01-05 10:10:02 -05:00
|
|
|
path = Gitlab::UsageDataCounters::PackageEventCounter::KNOWN_EVENTS_PATH
|
|
|
|
File.open(path, "w") { |file| file << counter_events_list.to_yaml }
|
2020-11-12 01:09:02 -05:00
|
|
|
|
2020-12-07 19:09:45 -05:00
|
|
|
logger.info("Events file `#{path}` generated successfully")
|
|
|
|
rescue => e
|
|
|
|
logger.error("Error building events list: #{e}")
|
|
|
|
end
|
|
|
|
|
|
|
|
task generate_unique: :environment do
|
|
|
|
logger = Logger.new(STDOUT)
|
|
|
|
logger.info('Building list of package events...')
|
|
|
|
|
|
|
|
path = File.join(File.dirname(Gitlab::UsageDataCounters::HLLRedisCounter::KNOWN_EVENTS_PATH), 'package_events.yml')
|
2020-11-12 01:09:02 -05:00
|
|
|
File.open(path, "w") { |file| file << generate_unique_events_list.to_yaml }
|
|
|
|
|
|
|
|
logger.info("Events file `#{path}` generated successfully")
|
|
|
|
rescue => e
|
|
|
|
logger.error("Error building events list: #{e}")
|
|
|
|
end
|
|
|
|
|
2020-12-07 19:09:45 -05:00
|
|
|
private
|
|
|
|
|
2020-11-12 01:09:02 -05:00
|
|
|
def event_pairs
|
2020-12-07 19:09:45 -05:00
|
|
|
Packages::Event.event_types.keys.product(Packages::Event::EVENT_SCOPES.keys)
|
2020-11-12 01:09:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def generate_unique_events_list
|
2020-11-30 19:09:28 -05:00
|
|
|
events = event_pairs.each_with_object([]) do |(event_type, event_scope), events|
|
2021-01-05 10:10:02 -05:00
|
|
|
Packages::Event.originator_types.keys.excluding('guest').each do |originator_type|
|
|
|
|
events_definition = Packages::Event.unique_counters_for(event_scope, event_type, originator_type).map do |event_name|
|
|
|
|
{
|
|
|
|
"name" => event_name,
|
|
|
|
"category" => "#{originator_type}_packages",
|
2020-11-12 01:09:02 -05:00
|
|
|
"aggregation" => "weekly",
|
2021-02-24 04:11:09 -05:00
|
|
|
"redis_slot" => "package"
|
2020-11-12 01:09:02 -05:00
|
|
|
}
|
|
|
|
end
|
2021-01-05 10:10:02 -05:00
|
|
|
|
|
|
|
events.concat(events_definition)
|
2020-11-12 01:09:02 -05:00
|
|
|
end
|
|
|
|
end
|
2020-11-30 19:09:28 -05:00
|
|
|
|
2021-01-05 10:10:02 -05:00
|
|
|
events.sort_by { |event| event["name"] }.uniq
|
2020-11-12 01:09:02 -05:00
|
|
|
end
|
2020-12-07 19:09:45 -05:00
|
|
|
|
2021-01-05 10:10:02 -05:00
|
|
|
def counter_events_list
|
|
|
|
counters = event_pairs.flat_map do |event_type, event_scope|
|
|
|
|
Packages::Event.originator_types.keys.flat_map do |originator_type|
|
|
|
|
Packages::Event.counters_for(event_scope, event_type, originator_type)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
counters.compact.sort.uniq
|
2020-12-07 19:09:45 -05:00
|
|
|
end
|
2020-11-12 01:09:02 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|