2021-02-05 07:09:31 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-09-09 17:08:33 -04:00
|
|
|
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
|
2022-02-08 10:12:33 -05:00
|
|
|
puts Gitlab::Usage::ServicePingReport.for(output: :metrics_queries).to_yaml
|
2020-09-09 17:08:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
desc 'GitLab | UsageData | Generate raw SQLs for usage ping in JSON'
|
|
|
|
task dump_sql_in_json: :environment do
|
2022-02-08 10:12:33 -05:00
|
|
|
puts Gitlab::Json.pretty_generate(Gitlab::Usage::ServicePingReport.for(output: :metrics_queries))
|
2020-09-09 17:08:33 -04:00
|
|
|
end
|
2020-12-03 10:09:46 -05:00
|
|
|
|
|
|
|
desc 'GitLab | UsageData | Generate usage ping in JSON'
|
|
|
|
task generate: :environment do
|
2022-02-08 10:12:33 -05:00
|
|
|
puts Gitlab::Json.pretty_generate(Gitlab::Usage::ServicePingReport.for(output: :all_metrics_values))
|
2020-12-03 10:09:46 -05:00
|
|
|
end
|
|
|
|
|
2022-09-02 17:10:02 -04:00
|
|
|
desc 'GitLab | UsageData | Generate non SQL data for usage ping in JSON'
|
|
|
|
task dump_non_sql_in_json: :environment do
|
|
|
|
puts Gitlab::Json.pretty_generate(Gitlab::Usage::ServicePingReport.for(output: :non_sql_metrics_values))
|
|
|
|
end
|
|
|
|
|
2020-12-03 10:09:46 -05:00
|
|
|
desc 'GitLab | UsageData | Generate usage ping and send it to Versions Application'
|
|
|
|
task generate_and_send: :environment do
|
2022-09-08 11:12:29 -04:00
|
|
|
response = GitlabServicePingWorker.new.perform('triggered_from_cron' => false)
|
2020-12-07 10:09:49 -05:00
|
|
|
|
2022-09-08 11:12:29 -04:00
|
|
|
puts response.body, response.code, response.message, response.headers.inspect
|
2020-12-03 10:09:46 -05:00
|
|
|
end
|
2021-01-25 13:09:03 -05:00
|
|
|
|
2021-05-07 08:10:27 -04:00
|
|
|
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-09-08 08:12:01 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2022-10-05 14:08:18 -04:00
|
|
|
all_includes = explicit_template_includes + implicit_auto_devops_includes
|
|
|
|
yaml = banner + YAML.dump(all_includes).gsub(/ *$/m, '')
|
|
|
|
|
|
|
|
File.write(Gitlab::UsageDataCounters::CiTemplateUniqueCounter::KNOWN_EVENTS_FILE_PATH, yaml)
|
2021-09-08 08:12:01 -04:00
|
|
|
end
|
|
|
|
|
2022-08-30 11:10:02 -04:00
|
|
|
desc 'GitLab | UsageDataMetrics | Generate raw SQL metrics queries for RSpec'
|
|
|
|
task generate_sql_metrics_queries: :environment do
|
|
|
|
path = Rails.root.join('tmp', 'test')
|
|
|
|
|
|
|
|
queries = Timecop.freeze(2021, 1, 1) do
|
|
|
|
Gitlab::Usage::ServicePingReport.for(output: :metrics_queries)
|
|
|
|
end
|
|
|
|
|
|
|
|
FileUtils.mkdir_p(path)
|
2022-10-12 08:09:35 -04:00
|
|
|
File.write(File.join(path, 'sql_metrics_queries.json'), Gitlab::Json.pretty_generate(queries))
|
2022-08-30 11:10:02 -04:00
|
|
|
end
|
|
|
|
|
2022-10-05 14:08:18 -04:00
|
|
|
# Events for templates included via YAML-less Auto-DevOps
|
|
|
|
def implicit_auto_devops_includes
|
|
|
|
Gitlab::UsageDataCounters::CiTemplateUniqueCounter
|
|
|
|
.all_included_templates('Auto-DevOps.gitlab-ci.yml')
|
|
|
|
.map { |template| implicit_auto_devops_event(template) }
|
|
|
|
.uniq
|
|
|
|
.sort_by { _1['name'] }
|
|
|
|
end
|
|
|
|
|
|
|
|
# Events for templates included in a .gitlab-ci.yml using include:template
|
|
|
|
def explicit_template_includes
|
2022-10-13 17:10:36 -04:00
|
|
|
Gitlab::UsageDataCounters::CiTemplateUniqueCounter.ci_templates("lib/gitlab/ci/templates/").each_with_object([]) do |template, result|
|
2022-10-05 14:08:18 -04:00
|
|
|
expanded_template_name = Gitlab::UsageDataCounters::CiTemplateUniqueCounter.expand_template_name(template)
|
2022-10-13 17:10:36 -04:00
|
|
|
next unless expanded_template_name # guard against templates unavailable on FOSS
|
|
|
|
|
2022-10-05 14:08:18 -04:00
|
|
|
event_name = Gitlab::UsageDataCounters::CiTemplateUniqueCounter.ci_template_event_name(expanded_template_name, :repository_source)
|
2021-10-04 14:12:46 -04:00
|
|
|
|
2022-10-13 17:10:36 -04:00
|
|
|
result << ci_template_event(event_name)
|
2021-09-08 08:12:01 -04:00
|
|
|
end
|
|
|
|
end
|
2021-10-04 14:12:46 -04:00
|
|
|
|
|
|
|
def ci_template_event(event_name)
|
|
|
|
{
|
|
|
|
'name' => event_name,
|
|
|
|
'category' => 'ci_templates',
|
|
|
|
'redis_slot' => Gitlab::UsageDataCounters::CiTemplateUniqueCounter::REDIS_SLOT,
|
|
|
|
'aggregation' => 'weekly'
|
|
|
|
}
|
|
|
|
end
|
2022-10-05 14:08:18 -04:00
|
|
|
|
|
|
|
def implicit_auto_devops_event(expanded_template_name)
|
|
|
|
event_name = Gitlab::UsageDataCounters::CiTemplateUniqueCounter.ci_template_event_name(expanded_template_name, :auto_devops_source)
|
|
|
|
ci_template_event(event_name)
|
|
|
|
end
|
2020-09-09 17:08:33 -04:00
|
|
|
end
|
|
|
|
end
|