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

26 lines
1 KiB
Ruby
Raw Normal View History

2020-01-01 13:55:28 +05:30
namespace :gitlab do
desc "GitLab | Generate Sample Prometheus Data"
task :generate_sample_prometheus_data, [:environment_id] => :gitlab_environment do |_, args|
environment = Environment.find(args[:environment_id])
metrics = PrometheusMetric.where(project_id: [environment.project.id, nil])
query_variables = Gitlab::Prometheus::QueryVariables.call(environment)
sample_metrics_directory_name = Metrics::SampleMetricsService::DIRECTORY
FileUtils.mkdir_p(sample_metrics_directory_name)
2020-03-09 13:42:32 +05:30
sample_metrics_intervals = [30.minutes, 180.minutes, 8.hours, 24.hours, 72.hours, 7.days]
2020-01-01 13:55:28 +05:30
metrics.each do |metric|
query = metric.query % query_variables
next unless metric.identifier
2020-03-09 13:42:32 +05:30
result = sample_metrics_intervals.each_with_object({}) do |interval, memo|
memo[interval.to_i / 60] = environment.prometheus_adapter.prometheus_client.query_range(query, start: interval.ago)
end
2020-01-01 13:55:28 +05:30
File.write("#{sample_metrics_directory_name}/#{metric.identifier}.yml", result.to_yaml)
end
end
end