diff --git a/files/gitlab-ctl-commands/lib/gitlab_ctl.rb b/files/gitlab-ctl-commands/lib/gitlab_ctl.rb index 58fe89127c95f26fb960175b1596c37b3105e127_ZmlsZXMvZ2l0bGFiLWN0bC1jb21tYW5kcy9saWIvZ2l0bGFiX2N0bC5yYg==..e88ad72727e62892df7dff1da8e134ea939f90cc_ZmlsZXMvZ2l0bGFiLWN0bC1jb21tYW5kcy9saWIvZ2l0bGFiX2N0bC5yYg== 100644 --- a/files/gitlab-ctl-commands/lib/gitlab_ctl.rb +++ b/files/gitlab-ctl-commands/lib/gitlab_ctl.rb @@ -15,7 +15,6 @@ # require_relative 'gitlab_ctl/pg_upgrade' -require_relative 'gitlab_ctl/prometheus_upgrade' require_relative 'gitlab_ctl/backup' require_relative 'gitlab_ctl/util' diff --git a/files/gitlab-ctl-commands/lib/gitlab_ctl/prometheus_upgrade.rb b/files/gitlab-ctl-commands/lib/gitlab_ctl/prometheus_upgrade.rb deleted file mode 100644 index 58fe89127c95f26fb960175b1596c37b3105e127_ZmlsZXMvZ2l0bGFiLWN0bC1jb21tYW5kcy9saWIvZ2l0bGFiX2N0bC9wcm9tZXRoZXVzX3VwZ3JhZGUucmI=..0000000000000000000000000000000000000000 --- a/files/gitlab-ctl-commands/lib/gitlab_ctl/prometheus_upgrade.rb +++ /dev/null @@ -1,94 +0,0 @@ -require 'optparse' -require 'fileutils' -require 'mixlib/shellout' -require_relative 'util' - -module GitlabCtl - class PrometheusUpgrade - attr_reader :v1_path, :v2_path, :backup_path, :binary_path - - # Sample output of prometheus --version is - # prometheus, version 1.8.2 (branch: master, revision: 6aa68e74cdc25a7d95f3f120ccc8eddd46e3c07b) - VERSION_REGEX = %r{.*?version (?<version>.*?) .*?}.freeze - - def initialize(base_path, home_dir) - @base_path = base_path - @home_dir = home_dir - @v1_path = File.join(home_dir, "data") - @v2_path = File.join(home_dir, "data2") - @backup_path = File.join(home_dir, "data_tmp") - @binary_path = File.join(base_path, "embedded", "bin", "prometheus") - end - - def is_version_2? - file_existence_check - end - - def file_existence_check - File.exist?(File.join(@home_dir, "data", "wal")) - end - - def prepare_directories - # Directory to store data in v2 format - FileUtils.mkdir_p(@v2_path) - system(*%W[chown --reference=#{@v1_path} #{@v2_path}]) - system(*%W[chmod --reference=#{@v1_path} #{@v2_path}]) - end - - def backup_data - # Backup existing v1 data to a temporary location - FileUtils.mv(@v1_path, @backup_path) - end - - def revert - # Delete intermediate directories and restore the original data - FileUtils.rm_rf(@v1_path) - FileUtils.rm_rf(@v2_path) - FileUtils.mv(@backup_path, @v1_path) - end - - def rename_directory - # We have already backed up the original data directory to @backup_path - # Delete it and rename v2 directory to that name - FileUtils.rm_rf(@v1_path) - FileUtils.mv(@v2_path, @v1_path) - end - - def prometheus_user - Etc.getpwuid(File.stat(@v1_path).uid).name - end - - def prometheus_group - Etc.getgrgid(File.stat(@v1_path).gid).name - end - - class << self - def parse_options(args) - node_attributes = GitlabCtl::Util.get_node_attributes - - options = { - home_dir: node_attributes.dig(:monitoring, :prometheus, :home), - skip_reconfigure: false, - wait: true, - } - OptionParser.new do |opts| - opts.on('-s', '--skip-data-migration', 'Obsolete flag, ignored.') - - opts.on('--skip-reconfigure', 'Skip reconfigure when upgrading.') do - options[:skip_reconfigure] = true - end - - opts.on('-dDIR', '--home-dir=DIR', "Value of prometheus['home'] set in gitlab.rb. Defaults to /var/opt/gitlab/prometheus") do |d| - options[:home_dir] = d - end - - opts.on('-w', '--no-wait', 'Do not wait before starting the upgrade process') do - options[:wait] = false - end - end.parse!(args) - - options - end - end - end -end diff --git a/files/gitlab-ctl-commands/prometheus-upgrade.rb b/files/gitlab-ctl-commands/prometheus-upgrade.rb deleted file mode 100644 index 58fe89127c95f26fb960175b1596c37b3105e127_ZmlsZXMvZ2l0bGFiLWN0bC1jb21tYW5kcy9wcm9tZXRoZXVzLXVwZ3JhZGUucmI=..0000000000000000000000000000000000000000 --- a/files/gitlab-ctl-commands/prometheus-upgrade.rb +++ /dev/null @@ -1,62 +0,0 @@ -# -# Copyright:: Copyright (c) 2018 GitLab Inc -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require "#{base_path}/embedded/service/omnibus-ctl/lib/gitlab_ctl" - -add_command 'prometheus-upgrade', 'Upgrade the Prometheus data to the latest supported version', - 2 do |_cmd_name| - unless service_enabled?('prometheus') - log "Prometheus not enabled." - Kernel.exit 0 - end - - options = GitlabCtl::PrometheusUpgrade.parse_options(ARGV) - home_dir = File.expand_path(options[:home_dir]) - - prometheus_upgrade = GitlabCtl::PrometheusUpgrade.new(base_path, home_dir) - - # v1_path points to the current data directory - unless File.exist?(prometheus_upgrade.v1_path) - log "Specified home directory, #{home_dir} either does not exist or does not contain any data directory inside." - log "Use --home-dir flag to specify Prometheus home directory." - Kernel.exit 1 - end - - if prometheus_upgrade.is_version_2? - log "Already running Prometheus version 2." - Kernel.exit 0 - end - - prometheus_upgrade.prepare_directories - prometheus_upgrade.backup_data - - log "\nStopping prometheus for upgrade" - run_sv_command_for_service('stop', 'prometheus') - - prometheus_upgrade.rename_directory - - unless options[:skip_reconfigure] - log "Running reconfigure to apply changes" - run_chef("#{base_path}/embedded/cookbooks/dna.json").success? - end - - log "Starting prometheus" - run_sv_command_for_service('start', 'prometheus') - - log "Prometheus upgrade completed. You are now running Prometheus version 2" - log "Old data directory has been backed up to #{prometheus_upgrade.backup_path}." -end diff --git a/files/gitlab-ctl-commands/upgrade.rb b/files/gitlab-ctl-commands/upgrade.rb index 58fe89127c95f26fb960175b1596c37b3105e127_ZmlsZXMvZ2l0bGFiLWN0bC1jb21tYW5kcy91cGdyYWRlLnJi..e88ad72727e62892df7dff1da8e134ea939f90cc_ZmlsZXMvZ2l0bGFiLWN0bC1jb21tYW5kcy91cGdyYWRlLnJi 100644 --- a/files/gitlab-ctl-commands/upgrade.rb +++ b/files/gitlab-ctl-commands/upgrade.rb @@ -110,16 +110,6 @@ abort "Failed to start #{sv_name} for migrations" end - # Force upgrade to Prometheus 2.x - unless GitlabCtl::Util.progress_message('Ensuring Prometheus is updated') do - command = %W(#{base_path}/bin/gitlab-ctl prometheus-upgrade -w --skip-reconfigure) - status = run_command(command.join(' ')) - status.success? - end - log 'Error ensuring Prometheus is updated. Please check the logs' - Kernel.exit 1 - end - # Do not show "WARN: Cookbook 'local-mode-cache' is empty or entirely chefignored at /opt/gitlab/embedded/cookbooks/local-mode-cache" local_mode_cache_path = "#{base_path}/embedded/cookbooks/local-mode-cache" run_command("rm -rf #{local_mode_cache_path}")