<commit_before>require 'optparse'
require 'fileutils'
require 'mixlib/shellout'

module GitlabCtl
  class PrometheusUpgrade
    attr_reader :v1_path, :v2_path, :backup_path

    # Sample output of prometheus --version is
    # prometheus, version 1.8.2 (branch: master, revision: 6aa68e74cdc25a7d95f3f120ccc8eddd46e3c07b)
    VERSION_REGEX = %r{.*?version (?<version>.*?) .*?}

    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")
    end

    def is_version_2?
      version_string_check && file_existence_check
    end

    def file_existence_check
      File.exist?(File.join(@home_dir, "data", "wal"))
    end

    def version_string_check
      version_output = `#{@base_path}/embedded/bin/prometheus --version 2>&1`.strip
      version_output.match(VERSION_REGEX)[:version].start_with?("2")
    end

    def prepare_directories
      # Directory to store data in v2 format
      FileUtils.mkdir_p(@v2_path)
      system("chown --reference=#{@v1_path} #{@v2_path}")<commit_msg>Add saftey check<commit_after>require 'optparse'
require 'fileutils'
require 'mixlib/shellout'

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>.*?) .*?}

    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?
      binary_existence_check && version_string_check && file_existence_check
    end

    def binary_existence_check
      File.exist?(@binary_path)
    end

    def file_existence_check
      File.exist?(File.join(@home_dir, "data", "wal"))
    end

    def version_string_check
      version_output = `#{@binary_path} --version 2>&1`.strip
      version_output.match(VERSION_REGEX)[:version].start_with?("2")
    end

    def prepare_directories
      # Directory to store data in v2 format
      FileUtils.mkdir_p(@v2_path)
      system("chown --reference=#{@v1_path} #{@v2_path}")
{'fraction_non_alphanumeric': 0.11971268954509177, 'fraction_numerical': 0.028731045490822026, 'mean_word_length': 3.730188679245283, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2013542', 'n_tokens_mistral': 936, 'n_tokens_neox': 882, 'n_words': 170}