2021-03-11 19:13:27 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
namespace :gitlab do
|
|
|
|
namespace :usage_data do
|
|
|
|
desc 'GitLab | UsageData | Generate raw SQLs for usage ping in YAML'
|
|
|
|
task dump_sql_in_yaml: :environment do
|
|
|
|
puts Gitlab::UsageDataQueries.uncached_data.to_yaml
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'GitLab | UsageData | Generate raw SQLs for usage ping in JSON'
|
|
|
|
task dump_sql_in_json: :environment do
|
|
|
|
puts Gitlab::Json.pretty_generate(Gitlab::UsageDataQueries.uncached_data)
|
|
|
|
end
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
desc 'GitLab | UsageData | Generate usage ping in JSON'
|
|
|
|
task generate: :environment do
|
|
|
|
puts Gitlab::Json.pretty_generate(Gitlab::UsageData.uncached_data)
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'GitLab | UsageData | Generate usage ping and send it to Versions Application'
|
|
|
|
task generate_and_send: :environment do
|
2021-09-30 23:02:18 +05:30
|
|
|
result = ServicePing::SubmitService.new.execute
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
puts Gitlab::Json.pretty_generate(result.attributes)
|
|
|
|
end
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
desc 'GitLab | UsageDataMetrics | Generate usage ping from metrics definition YAML files in JSON'
|
|
|
|
task generate_from_yaml: :environment do
|
|
|
|
puts Gitlab::Json.pretty_generate(Gitlab::UsageDataMetrics.uncached_data)
|
|
|
|
end
|
2021-11-11 11:23:49 +05:30
|
|
|
|
|
|
|
desc 'GitLab | UsageDataMetrics | Generate known_events/ci_templates.yml based on template definitions'
|
|
|
|
task generate_ci_template_events: :environment do
|
|
|
|
banner = <<~BANNER
|
|
|
|
# This file is generated automatically by
|
|
|
|
# bin/rake gitlab:usage_data:generate_ci_template_events
|
|
|
|
#
|
|
|
|
# Do not edit it manually!
|
|
|
|
BANNER
|
|
|
|
|
|
|
|
repository_includes = ci_template_includes_hash(:repository_source)
|
|
|
|
auto_devops_jobs_includes = ci_template_includes_hash(:auto_devops_source, 'Jobs')
|
|
|
|
auto_devops_security_includes = ci_template_includes_hash(:auto_devops_source, 'Security')
|
2021-11-18 22:05:49 +05:30
|
|
|
all_includes = [
|
|
|
|
*repository_includes,
|
|
|
|
ci_template_event('p_ci_templates_implicit_auto_devops'),
|
|
|
|
*auto_devops_jobs_includes,
|
|
|
|
*auto_devops_security_includes
|
|
|
|
]
|
2021-11-11 11:23:49 +05:30
|
|
|
|
|
|
|
File.write(Gitlab::UsageDataCounters::CiTemplateUniqueCounter::KNOWN_EVENTS_FILE_PATH, banner + YAML.dump(all_includes).gsub(/ *$/m, ''))
|
|
|
|
end
|
|
|
|
|
|
|
|
def ci_template_includes_hash(source, template_directory = nil)
|
|
|
|
Gitlab::UsageDataCounters::CiTemplateUniqueCounter.ci_templates("lib/gitlab/ci/templates/#{template_directory}").map do |template|
|
2021-11-18 22:05:49 +05:30
|
|
|
expanded_template_name = Gitlab::UsageDataCounters::CiTemplateUniqueCounter.expand_template_name("#{template_directory}/#{template}")
|
|
|
|
event_name = Gitlab::UsageDataCounters::CiTemplateUniqueCounter.ci_template_event_name(expanded_template_name, source)
|
|
|
|
|
|
|
|
ci_template_event(event_name)
|
2021-11-11 11:23:49 +05:30
|
|
|
end
|
|
|
|
end
|
2021-11-18 22:05:49 +05:30
|
|
|
|
|
|
|
def ci_template_event(event_name)
|
|
|
|
{
|
|
|
|
'name' => event_name,
|
|
|
|
'category' => 'ci_templates',
|
|
|
|
'redis_slot' => Gitlab::UsageDataCounters::CiTemplateUniqueCounter::REDIS_SLOT,
|
|
|
|
'aggregation' => 'weekly'
|
|
|
|
}
|
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
end
|