# HG changeset patch
# User Sami Hiltunen <shiltunen@gitlab.com>
# Date 1612359872 -3600
#      Wed Feb 03 14:44:32 2021 +0100
# Node ID 2261ed8a6f244761c1877cfc5b6e9287a2764f1b
# Parent  6a1ce1f2e82e895c0c902e6326ef602c1b570959
Add Praefect's default replication factor configuration option

This commit adds Praefect's recently added default replication factor
configuration option in to the config template.

diff --git a/changelogs/unreleased/smh-default-replication-factor.yml b/changelogs/unreleased/smh-default-replication-factor.yml
new file mode 100644
--- /dev/null
+++ b/changelogs/unreleased/smh-default-replication-factor.yml
@@ -0,0 +1,5 @@
+---
+title: Add default replication factor configuration option to Praefect
+merge_request: 4988
+author:
+type: added
diff --git a/files/gitlab-config-template/gitlab.rb.template b/files/gitlab-config-template/gitlab.rb.template
--- a/files/gitlab-config-template/gitlab.rb.template
+++ b/files/gitlab-config-template/gitlab.rb.template
@@ -2099,6 +2099,7 @@
 # praefect['logging_format'] = "json"
 # praefect['virtual_storages'] = {
 #   'default' => {
+#     'default_replication_factor' => 3,
 #     'nodes' => {
 #       'praefect-internal-0' => {
 #         'address' => 'tcp://10.23.56.78:8075',
diff --git a/files/gitlab-cookbooks/praefect/templates/default/praefect-config.toml.erb b/files/gitlab-cookbooks/praefect/templates/default/praefect-config.toml.erb
--- a/files/gitlab-cookbooks/praefect/templates/default/praefect-config.toml.erb
+++ b/files/gitlab-cookbooks/praefect/templates/default/praefect-config.toml.erb
@@ -63,6 +63,9 @@
 <% @virtual_storages.each do |name, config| %>
 [[virtual_storage]]
 name = '<%= name %>'
+<% if config['default_replication_factor'] %>
+default_replication_factor = <%= config['default_replication_factor'] %>
+<% end %>
 <% config['nodes'].each do |storage, node|  %>
 [[virtual_storage.node]]
 storage = '<%= storage %>'
diff --git a/spec/chef/recipes/praefect_spec.rb b/spec/chef/recipes/praefect_spec.rb
--- a/spec/chef/recipes/praefect_spec.rb
+++ b/spec/chef/recipes/praefect_spec.rb
@@ -92,6 +92,7 @@
       let(:virtual_storages) do
         {
           'default' => {
+            'default_replication_factor' => 2,
             'nodes' => {
               'praefect1' => { address: 'tcp://node1.internal', token: "praefect1-token" },
               'praefect2' => { address: 'tcp://node2.internal', token: "praefect2-token" },
@@ -205,6 +206,7 @@
               'virtual_storage' => [
                 {
                   'name' => 'default',
+                  'default_replication_factor' => 2,
                   'node' => [
                     {
                       'address' => 'tcp://node1.internal',