diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-17 00:08:00 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-17 00:08:00 +0300 |
commit | 69d6d3ca2013e97cfd2d89449669ea7bf475f4e9 (patch) | |
tree | 2cc4227ebfc52b7603691f06b0b8e09e030e8428 /lib/tasks | |
parent | 01fdcf49b1553c22ae116fe96cedd7b91d02225c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/tasks')
-rw-r--r-- | lib/tasks/gitlab/generate_sample_prometheus_data.rake | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/tasks/gitlab/generate_sample_prometheus_data.rake b/lib/tasks/gitlab/generate_sample_prometheus_data.rake new file mode 100644 index 00000000000..a988494ca61 --- /dev/null +++ b/lib/tasks/gitlab/generate_sample_prometheus_data.rake @@ -0,0 +1,20 @@ +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) + + metrics.each do |metric| + query = metric.query % query_variables + result = environment.prometheus_adapter.prometheus_client.query_range(query, start: 7.days.ago) + + next unless metric.identifier + + File.write("#{sample_metrics_directory_name}/#{metric.identifier}.yml", result.to_yaml) + end + end +end |