debian-mirror-gitlab/lib/tasks/gitlab/packages/events.rake

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

77 lines
2.6 KiB
Ruby
Raw Normal View History

2021-03-11 19:13:27 +05:30
# frozen_string_literal: true
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-03-08 18:12:59 +05:30
Rake::Task["gitlab:packages:events:generate_counts"].invoke
2021-02-22 17:27:13 +05:30
Rake::Task["gitlab:packages:events:generate_unique"].invoke
2021-06-08 01:23:25 +05:30
rescue StandardError => e
2021-02-22 17:27:13 +05:30
logger.error("Error building events list: #{e}")
end
2021-03-08 18:12:59 +05:30
task generate_counts: :environment do
2021-09-04 01:27:46 +05:30
logger = Logger.new($stdout)
2021-01-29 00:20:46 +05:30
logger.info('Building list of package events...')
2021-03-08 18:12:59 +05:30
path = Gitlab::UsageDataCounters::PackageEventCounter::KNOWN_EVENTS_PATH
File.open(path, "w") { |file| file << counter_events_list.to_yaml }
2021-02-22 17:27:13 +05:30
logger.info("Events file `#{path}` generated successfully")
2021-06-08 01:23:25 +05:30
rescue StandardError => e
2021-02-22 17:27:13 +05:30
logger.error("Error building events list: #{e}")
end
task generate_unique: :environment do
2021-09-04 01:27:46 +05:30
logger = Logger.new($stdout)
2021-02-22 17:27:13 +05:30
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")
2021-06-08 01:23:25 +05:30
rescue StandardError => e
2021-01-29 00:20:46 +05:30
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|
2021-03-08 18:12:59 +05:30
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",
2021-01-29 00:20:46 +05:30
"aggregation" => "weekly",
2021-04-17 20:07:23 +05:30
"redis_slot" => "package"
2021-01-29 00:20:46 +05:30
}
end
2021-03-08 18:12:59 +05:30
events.concat(events_definition)
2021-01-29 00:20:46 +05:30
end
end
2021-02-22 17:27:13 +05:30
2021-03-08 18:12:59 +05:30
events.sort_by { |event| event["name"] }.uniq
2021-02-22 17:27:13 +05:30
end
2021-03-08 18:12:59 +05:30
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
2021-01-29 00:20:46 +05:30
end
end
end
end