Class: Gitlab::QA::Component::Praefect

Inherits:
Base
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/gitlab/qa/component/praefect.rb

Constant Summary

Constants inherited from Base

Base::CERTIFICATES_PATH

Instance Attribute Summary collapse

Attributes inherited from Base

#additional_hosts, #airgapped_network, #docker, #environment, #logger, #network, #network_aliases, #ports, #runner_network, #volumes

Instance Method Summary collapse

Methods inherited from Base

#add_network_alias, #hostname, #image, #instance, #ip_address, #prepare, #prepare_airgapped_network, #prepare_docker_container, #prepare_docker_image, #prepare_network, #prepare_runner_network, #process_exec_commands, #restart, #start, #start_instance, #tag, #teardown, #teardown!

Methods included from Scenario::Actable

#act, included

Constructor Details

#initializePraefect

Returns a new instance of Praefect.



15
16
17
18
19
20
# File 'lib/gitlab/qa/component/praefect.rb', line 15

def initialize
  super
  self.release = 'CE'
  @cluster_config = Component::GitalyCluster::GitalyClusterConfig.new
  @ports = [cluster_config.praefect_port]
end

Instance Attribute Details

#cluster_configObject

Returns the value of attribute cluster_config.



10
11
12
# File 'lib/gitlab/qa/component/praefect.rb', line 10

def cluster_config
  @cluster_config
end

#nameObject



22
23
24
# File 'lib/gitlab/qa/component/praefect.rb', line 22

def name
  @name || "praefect-#{SecureRandom.hex(4)}"
end

#releaseObject

Returns the value of attribute release.



9
10
11
# File 'lib/gitlab/qa/component/praefect.rb', line 9

def release
  @release
end

Instance Method Details

#praefect_omnibus_configurationObject

rubocop:disable Metrics/AbcSize



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/gitlab/qa/component/praefect.rb', line 57

def praefect_omnibus_configuration # rubocop:disable Metrics/AbcSize
  <<~OMNIBUS
      #{GitalyCluster.disable_other_omnibus_services}
      gitaly['enable'] = false;
      prometheus['enable'] = true;
      praefect['enable'] = true;
      praefect['configuration'] = {
        listen_addr: '0.0.0.0:#{cluster_config.praefect_port}',
        prometheus_listen_addr: '0.0.0.0:9652',
        auth: {
          token: 'PRAEFECT_EXTERNAL_TOKEN'
        },
        reconciliation: {
          scheduling_interval: '10s'
        },
        database: {
          host: '#{cluster_config.database_node_addr}',
          port: #{cluster_config.database_port},
          user: 'postgres',
          password: 'SQL_PASSWORD',
          dbname: 'praefect_production',
          sslmode: 'disable'
        },
        virtual_storage: [
          {
            name: 'default',
            node: [
              {
                'storage': '#{cluster_config.primary_node_name}',
                'address': 'tcp://#{cluster_config.primary_node_addr}:#{cluster_config.primary_node_port}',
                'token': 'PRAEFECT_INTERNAL_TOKEN'
              },
              {
                'storage': '#{cluster_config.secondary_node_name}',
                'address': 'tcp://#{cluster_config.secondary_node_addr}:#{cluster_config.secondary_node_port}',
                'token': 'PRAEFECT_INTERNAL_TOKEN'
              },
              {
                'storage': '#{cluster_config.tertiary_node_name}',
                'address': 'tcp://#{cluster_config.tertiary_node_addr}:#{cluster_config.tertiary_node_port}',
                'token': 'PRAEFECT_INTERNAL_TOKEN'
              }
            ],
          }
        ]
      }
  OMNIBUS
end

#pullObject



30
31
32
33
34
# File 'lib/gitlab/qa/component/praefect.rb', line 30

def pull
  docker.(**release.) if release.

  super
end

#reconfigureObject



36
37
38
39
40
41
42
# File 'lib/gitlab/qa/component/praefect.rb', line 36

def reconfigure
  setup_omnibus
  @docker.attach(name) do |line|
    # TODO, workaround which allows to detach from the container
    break if line.include?('gitlab Reconfigured!')
  end
end

#setup_omnibusObject



44
45
46
47
48
# File 'lib/gitlab/qa/component/praefect.rb', line 44

def setup_omnibus
  @docker.write_files(name) do |f|
    f.write('/etc/gitlab/gitlab.rb', praefect_omnibus_configuration)
  end
end

#wait_until_readyObject



50
51
52
53
54
55
# File 'lib/gitlab/qa/component/praefect.rb', line 50

def wait_until_ready
  @docker.exec(name, 'praefect -config /var/opt/gitlab/praefect/cluster_config.toml check || true') do |resp|
    Runtime::Logger.info(resp)
    break if line.include?('All checks passed')
  end
end