debian-mirror-gitlab/lib/tasks/gitlab/usage_data.rake

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

101 lines
4 KiB
Ruby
Raw Normal View History

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
2022-04-04 11:22:00 +05:30
puts Gitlab::Usage::ServicePingReport.for(output: :metrics_queries).to_yaml
2020-11-24 15:15:51 +05:30
end
desc 'GitLab | UsageData | Generate raw SQLs for usage ping in JSON'
task dump_sql_in_json: :environment do
2022-04-04 11:22:00 +05:30
puts Gitlab::Json.pretty_generate(Gitlab::Usage::ServicePingReport.for(output: :metrics_queries))
2020-11-24 15:15:51 +05:30
end
2021-02-22 17:27:13 +05:30
desc 'GitLab | UsageData | Generate usage ping in JSON'
task generate: :environment do
2022-04-04 11:22:00 +05:30
puts Gitlab::Json.pretty_generate(Gitlab::Usage::ServicePingReport.for(output: :all_metrics_values))
2021-02-22 17:27:13 +05:30
end
2022-10-11 01:57:18 +05:30
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
2021-02-22 17:27:13 +05:30
desc 'GitLab | UsageData | Generate usage ping and send it to Versions Application'
task generate_and_send: :environment do
2022-10-11 01:57:18 +05:30
response = GitlabServicePingWorker.new.perform('triggered_from_cron' => false)
2021-02-22 17:27:13 +05:30
2022-10-11 01:57:18 +05:30
puts response.body, response.code, response.message, response.headers.inspect
2021-02-22 17:27:13 +05:30
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
2022-11-25 23:54:43 +05:30
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-11-11 11:23:49 +05:30
end
2022-10-11 01:57:18 +05:30
desc 'GitLab | UsageDataMetrics | Generate raw SQL metrics queries for RSpec'
task generate_sql_metrics_queries: :environment do
2023-03-04 22:38:38 +05:30
require 'active_support/testing/time_helpers'
include ActiveSupport::Testing::TimeHelpers
2022-10-11 01:57:18 +05:30
path = Rails.root.join('tmp', 'test')
2023-03-04 22:38:38 +05:30
queries = travel_to(Time.utc(2021, 1, 1)) do
2022-10-11 01:57:18 +05:30
Gitlab::Usage::ServicePingReport.for(output: :metrics_queries)
end
FileUtils.mkdir_p(path)
2022-11-25 23:54:43 +05:30
File.write(File.join(path, 'sql_metrics_queries.json'), Gitlab::Json.pretty_generate(queries))
end
# 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'] }
2022-10-11 01:57:18 +05:30
end
2022-11-25 23:54:43 +05:30
# Events for templates included in a .gitlab-ci.yml using include:template
def explicit_template_includes
Gitlab::UsageDataCounters::CiTemplateUniqueCounter.ci_templates("lib/gitlab/ci/templates/").each_with_object([]) do |template, result|
expanded_template_name = Gitlab::UsageDataCounters::CiTemplateUniqueCounter.expand_template_name(template)
next unless expanded_template_name # guard against templates unavailable on FOSS
2021-11-18 22:05:49 +05:30
2022-11-25 23:54:43 +05:30
event_name = Gitlab::UsageDataCounters::CiTemplateUniqueCounter.ci_template_event_name(expanded_template_name, :repository_source)
result << 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,
'aggregation' => 'weekly'
}
end
2022-11-25 23:54:43 +05:30
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-11-24 15:15:51 +05:30
end
end