Class: Gitlab::QA::Component::GitalyCluster

Inherits:
Object
  • Object
show all
Includes:
Scenario::Actable
Defined in:
lib/gitlab/qa/component/gitaly_cluster.rb

Defined Under Namespace

Classes: GitalyClusterConfig

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Scenario::Actable

#act, included

Constructor Details

#initialize(config = GitalyClusterConfig.new) ⇒ GitalyCluster

Returns a new instance of GitalyCluster.



51
52
53
54
55
56
57
# File 'lib/gitlab/qa/component/gitaly_cluster.rb', line 51

def initialize(config = GitalyClusterConfig.new)
  @spec_suite = 'Test::Instance::All'
  @env = {}
  @tag = 'gitaly_cluster'
  @release = 'EE'
  @config = config
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



48
49
50
# File 'lib/gitlab/qa/component/gitaly_cluster.rb', line 48

def config
  @config
end

#database_nodeObject (readonly)

Returns the value of attribute database_node.



49
50
51
# File 'lib/gitlab/qa/component/gitaly_cluster.rb', line 49

def database_node
  @database_node
end

#exec_commandsObject

Returns the value of attribute exec_commands.



48
49
50
# File 'lib/gitlab/qa/component/gitaly_cluster.rb', line 48

def exec_commands
  @exec_commands
end

#gitaly_primary_nodeObject (readonly)

Returns the value of attribute gitaly_primary_node.



49
50
51
# File 'lib/gitlab/qa/component/gitaly_cluster.rb', line 49

def gitaly_primary_node
  @gitaly_primary_node
end

#gitaly_secondary_nodeObject (readonly)

Returns the value of attribute gitaly_secondary_node.



49
50
51
# File 'lib/gitlab/qa/component/gitaly_cluster.rb', line 49

def gitaly_secondary_node
  @gitaly_secondary_node
end

#gitaly_tertiary_nodeObject (readonly)

Returns the value of attribute gitaly_tertiary_node.



49
50
51
# File 'lib/gitlab/qa/component/gitaly_cluster.rb', line 49

def gitaly_tertiary_node
  @gitaly_tertiary_node
end

#gitlab_nameObject

Returns the value of attribute gitlab_name.



48
49
50
# File 'lib/gitlab/qa/component/gitaly_cluster.rb', line 48

def gitlab_name
  @gitlab_name
end

#praefect_nodeObject (readonly)

Returns the value of attribute praefect_node.



49
50
51
# File 'lib/gitlab/qa/component/gitaly_cluster.rb', line 49

def praefect_node
  @praefect_node
end

#releaseObject

Returns the value of attribute release.



48
49
50
# File 'lib/gitlab/qa/component/gitaly_cluster.rb', line 48

def release
  @release
end

Class Method Details

.disable_other_omnibus_servicesObject

Helper configuration for omnibus config to disable all non GitalyCluster related omnibus services



139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/gitlab/qa/component/gitaly_cluster.rb', line 139

def self.disable_other_omnibus_services
  <<~OMNIBUS
    postgresql['enable'] = false;
    redis['enable'] = false;
    nginx['enable'] = false;
    puma['enable'] = false;
    sidekiq['enable'] = false;
    gitlab_workhorse['enable'] = false;
    gitlab_rails['rake_cache_clear'] = false;
    gitlab_rails['auto_migrate'] = false;
    gitlab_exporter['enable'] = false;
    gitlab_kas['enable'] = false;
  OMNIBUS
end

Instance Method Details

#gitaly(gitaly_name, port, release) ⇒ Object

rubocop:disable Metrics/AbcSize



114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/gitlab/qa/component/gitaly_cluster.rb', line 114

def gitaly(gitaly_name, port, release) # rubocop:disable Metrics/AbcSize
  Component::Gitaly.new.tap do |gitaly|
    gitaly.cluster_config = config
    gitaly.release = release
    gitaly.name = gitaly_name
    gitaly.gitaly_port = port
    gitaly.airgapped_network = config.airgapped_network
    gitaly.network = config.network
    gitaly.gitlab_name = config.gitlab_name
    gitaly.instance(skip_teardown: true)
  end
end

#instance(parallel_gitaly = false) ⇒ Object

Parameters:

  • parallel_gitaly (Boolean) (defaults to: false)

    controls whether we start gitaly nodes in parallel to improve startup time



60
61
62
# File 'lib/gitlab/qa/component/gitaly_cluster.rb', line 60

def instance(parallel_gitaly = false)
  run_gitaly_cluster(QA::Release.new(release), parallel_gitaly)
end

#postgresObject



103
104
105
106
107
108
109
110
111
112
# File 'lib/gitlab/qa/component/gitaly_cluster.rb', line 103

def postgres
  Component::PostgreSQL.new.tap do |sql|
    sql.name = config.database_node_name
    sql.airgapped_network = config.airgapped_network
    sql.network = config.network
    sql.instance(skip_teardown: true) do
      sql.run_psql '-d template1 -c "CREATE DATABASE praefect_production OWNER postgres"'
    end
  end
end

#praefect(release) ⇒ Object



127
128
129
130
131
132
133
134
135
136
# File 'lib/gitlab/qa/component/gitaly_cluster.rb', line 127

def praefect(release)
  Component::Praefect.new.tap do |praefect|
    praefect.cluster_config = config
    praefect.name = config.praefect_node_name
    praefect.airgapped_network = config.airgapped_network
    praefect.network = config.network
    praefect.release = release
    praefect.instance(skip_teardown: true)
  end
end

#run_gitaly_cluster(release, parallel_gitaly = false) ⇒ Object

Parameters:

  • parallel_gitaly (Boolean) (defaults to: false)

    controls whether we start gitaly nodes in parallel to improve startup time



65
66
67
68
69
70
71
72
73
74
# File 'lib/gitlab/qa/component/gitaly_cluster.rb', line 65

def run_gitaly_cluster(release, parallel_gitaly = false)
  # This also ensure that the docker network is created here, avoiding any potential race conditions later
  #  if the gitaly-cluster and GitLab containers attempt to create a network in parallel
  @database_node = postgres

  Thread.new do
    Thread.current.abort_on_exception = true
    start_gitaly_cluster(release, parallel_gitaly)
  end
end

#start_gitaly_cluster(release, parallel_gitaly = false) ⇒ Object

Parameters:

  • parallel_gitaly (Boolean) (defaults to: false)

    controls whether we start gitaly nodes in parallel to improve startup time



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
# File 'lib/gitlab/qa/component/gitaly_cluster.rb', line 77

def start_gitaly_cluster(release, parallel_gitaly = false) # rubocop:disable Metrics/AbcSize
  Runtime::Logger.info("Starting Gitaly Cluster")

  if parallel_gitaly
    threads = []
    threads << Thread.new do
      @gitaly_primary_node = gitaly(config.primary_node_name, config.primary_node_port, release)
    end
    threads << Thread.new do
      @gitaly_secondary_node = gitaly(config.secondary_node_name, config.secondary_node_port, release)
    end
    threads << Thread.new do
      @gitaly_tertiary_node = gitaly(config.tertiary_node_name, config.tertiary_node_port, release)
    end
    threads.each(&:join)
  else
    @gitaly_primary_node = gitaly(config.primary_node_name, config.primary_node_port, release)
    @gitaly_secondary_node = gitaly(config.secondary_node_name, config.secondary_node_port, release)
    @gitaly_tertiary_node = gitaly(config.tertiary_node_name, config.tertiary_node_port, release)
  end

  @praefect_node = praefect(release)
  config.praefect_ip = praefect_node.ip_address
  Runtime::Logger.info("Gitaly Cluster Ready")
end