Giuseppe Lavagetto has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/350404 )

Change subject: profile::redis::multidc_instance: separate concerns with confd
......................................................................

profile::redis::multidc_instance: separate concerns with confd

In an attempt to make things more readable and manageable, we clearly
separate what redis config comes from puppet (specifically: the
information about the redis shards and what is the twin instance in the
other datacenter) from what is controlled by confd (that is, if that
information is included or not in the configuration.

This creates a second level of indirection on the systems, but I think
that's manageable.

Change-Id: I369da7e52e8556c98788d40e7f35be55b2084a12
---
M modules/profile/manifests/redis/multidc_instance.pp
D modules/profile/templates/jobqueue_redis/statefile.tpl.erb
A modules/profile/templates/redis/multidc_statefile.inc.erb
A modules/profile/templates/redis/multidc_statefile.tpl.erb
4 files changed, 38 insertions(+), 25 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/04/350404/1

diff --git a/modules/profile/manifests/redis/multidc_instance.pp 
b/modules/profile/manifests/redis/multidc_instance.pp
index 49a632f..13213cb 100644
--- a/modules/profile/manifests/redis/multidc_instance.pp
+++ b/modules/profile/manifests/redis/multidc_instance.pp
@@ -25,11 +25,18 @@
     }
 
     if $discovery {
+        file { "${replica_state_file}.inc":
+            ensure   => present,
+            owner    => 'root',
+            group    => 'root',
+            template => template('profile/redis/multidc_statefile.inc.erb'),
+            before   => Confd::File[$replica_state_file]
+        }
         confd::file { $replica_state_file:
             ensure     => present,
             prefix     => "/discovery/${discovery}",
             watch_keys => ['/'],
-            content    => template('profile/jobqueue_redis/statefile.tpl.erb'),
+            content    => template('profile/redis/multidc_statefile.tpl.erb'),
         }
         Base::Service_unit['confd'] -> 
Base::Service_unit["redis-instance-tcp_${title}"]
 
diff --git a/modules/profile/templates/jobqueue_redis/statefile.tpl.erb 
b/modules/profile/templates/jobqueue_redis/statefile.tpl.erb
deleted file mode 100644
index 2b85f37..0000000
--- a/modules/profile/templates/jobqueue_redis/statefile.tpl.erb
+++ /dev/null
@@ -1,24 +0,0 @@
-# This file is managed by confd
-# DO NOT edit by hand.
-<%-
-site = scope.lookupvar('::site')
-datacenters = @shards.keys
-datacenters.delete(site)
-
-# Find the shard we're referring to
-shard = nil
-@shards[site].each do |name, instance|
-  if instance['host'] == @ip && instance['port'] == @title.to_i
-    shard = name
-  end
-end -%>
-{{ $site := json ( getv "/<%= site %>" ) }}{{ if $site.pooled }}
-# This redis server is a global master as it's in an active datacenter
-{{ else }}<%-
-datacenters.each do |dc|
-  master = @shards[dc][shard]
-  slaveof = "slaveof #{master['host']} #{master['port']}"
- -%>
-{{ $site := json ( getv "/<%= dc %>" ) }}{{ if $site.pooled }}<%= slaveof %>{{ 
end }}
-<%- end -%>
-{{ end }}
diff --git a/modules/profile/templates/redis/multidc_statefile.inc.erb 
b/modules/profile/templates/redis/multidc_statefile.inc.erb
new file mode 100644
index 0000000..c9e41ea
--- /dev/null
+++ b/modules/profile/templates/redis/multidc_statefile.inc.erb
@@ -0,0 +1,22 @@
+# This file is managed by puppet
+# DO NOT edit by hand.
+<%-
+site = scope.lookupvar('::site')
+datacenters = @shards.keys
+datacenters.delete(site)
+
+# Find the shard we're referring to
+shard = nil
+@shards[site].each do |name, instance|
+  if instance['host'] == @ip && instance['port'] == @title.to_i
+    shard = name
+  end
+end
+
+# WARNING: just 2 datacenters are supported here.
+dc = datacenters[0]
+master = @shards[dc][shard]
+-%>
+# This file is not included directly in the redis configuration, but
+# conditionally via <%= @replica_state_file %>
+slaveof <%= master['host'] %> <%= master['port'] %>
diff --git a/modules/profile/templates/redis/multidc_statefile.tpl.erb 
b/modules/profile/templates/redis/multidc_statefile.tpl.erb
new file mode 100644
index 0000000..62ae943
--- /dev/null
+++ b/modules/profile/templates/redis/multidc_statefile.tpl.erb
@@ -0,0 +1,8 @@
+# This file is managed by confd
+# DO NOT edit by hand.
+{{ $site := json ( getv "/<%= scope.lookupvar('::site') %>" ) }}{{ if 
$site.pooled }}
+# This redis server is a global master as it's in an active datacenter
+{{ else }}
+# This redis server is a slave
+include <%= @replica_state_file %>.inc
+{{ end }}

-- 
To view, visit https://gerrit.wikimedia.org/r/350404
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I369da7e52e8556c98788d40e7f35be55b2084a12
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Giuseppe Lavagetto <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to