2021-01-29 00:20:46 +05:30
|
|
|
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-02-22 17:27:13 +05:30
|
|
|
Rake::Task["gitlab:packages:events:generate_guest"].invoke
|
|
|
|
Rake::Task["gitlab:packages:events:generate_unique"].invoke
|
|
|
|
rescue => e
|
|
|
|
logger.error("Error building events list: #{e}")
|
|
|
|
end
|
|
|
|
|
|
|
|
task generate_guest: :environment do
|
2021-01-29 00:20:46 +05:30
|
|
|
logger = Logger.new(STDOUT)
|
|
|
|
logger.info('Building list of package events...')
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
path = Gitlab::UsageDataCounters::GuestPackageEventCounter::KNOWN_EVENTS_PATH
|
|
|
|
File.open(path, "w") { |file| file << guest_events_list.to_yaml }
|
|
|
|
|
|
|
|
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...')
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
path = File.join(File.dirname(Gitlab::UsageDataCounters::HLLRedisCounter::KNOWN_EVENTS_PATH), 'package_events.yml')
|
2021-01-29 00:20:46 +05:30
|
|
|
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
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
private
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
def event_pairs
|
2021-02-22 17:27:13 +05:30
|
|
|
Packages::Event.event_types.keys.product(Packages::Event::EVENT_SCOPES.keys)
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def generate_unique_events_list
|
2021-02-22 17:27:13 +05:30
|
|
|
events = event_pairs.each_with_object([]) do |(event_type, event_scope), events|
|
|
|
|
Packages::Event.originator_types.keys.excluding('guest').each do |originator|
|
|
|
|
if name = Packages::Event.allowed_event_name(event_scope, event_type, originator)
|
2021-01-29 00:20:46 +05:30
|
|
|
events << {
|
|
|
|
"name" => name,
|
|
|
|
"category" => "#{event_scope}_packages",
|
|
|
|
"aggregation" => "weekly",
|
2021-02-22 17:27:13 +05:30
|
|
|
"redis_slot" => "package",
|
|
|
|
"feature_flag" => "collect_package_events_redis"
|
2021-01-29 00:20:46 +05:30
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
events.sort_by { |event| event["name"] }
|
|
|
|
end
|
|
|
|
|
|
|
|
def guest_events_list
|
|
|
|
event_pairs.map do |event_type, event_scope|
|
|
|
|
Packages::Event.allowed_event_name(event_scope, event_type, "guest")
|
|
|
|
end.compact.sort
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|