Giuseppe Lavagetto has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/220492

Change subject: varnish: allow picking which director is dynamic
......................................................................

varnish: allow picking which director is dynamic

Adding a "dyn_director" to varnish::instance allows us to:

* avoid including role::cache::base
* be generic enough to support the parsoid special-case
* be more clear and generic in building the template.

Change-Id: Iff2c3881ab1a83ad927f96834507855e7bba9876
---
M modules/role/manifests/cache/mobile.pp
M modules/role/manifests/cache/parsoid.pp
M modules/role/manifests/cache/text.pp
M modules/role/manifests/cache/upload.pp
M modules/varnish/manifests/instance.pp
M modules/varnish/templates/vcl/directors.vcl.tpl.erb
M modules/varnish/templates/vcl/wikimedia.vcl.erb
7 files changed, 31 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/92/220492/1

diff --git a/modules/role/manifests/cache/mobile.pp 
b/modules/role/manifests/cache/mobile.pp
index 39d482c..187f827 100644
--- a/modules/role/manifests/cache/mobile.pp
+++ b/modules/role/manifests/cache/mobile.pp
@@ -62,6 +62,11 @@
         default => 'chash',
     }
 
+    $be_dyn_director = $::role::cache::base::cluster_tier ? {
+        'two'   => 'eqiad',
+        default => undef,
+    }
+
     varnish::instance { 'mobile-backend':
         name               => '',
         vcl                => 'mobile-backend',
@@ -70,6 +75,7 @@
         storage            => $::role::cache::2layer::persistent_storage_args,
         runtime_parameters => $runtime_param,
         directors          => 
$varnish_be_directors[$::role::cache::base::cluster_tier],
+        dyn_directors      => $be_dyn_director,
         director_type      => $director_type_cluster,
         vcl_config         => {
             'default_backend'  => $::role::cache::base::default_backend,
@@ -110,6 +116,7 @@
         directors        => {
             'backend' => $site_mobile_nodes,
         },
+        dyn_director     => 'backend',
         director_type    => 'chash',
         vcl_config       => {
             'retry503'         => 1,
diff --git a/modules/role/manifests/cache/parsoid.pp 
b/modules/role/manifests/cache/parsoid.pp
index 26b38d8..030d06c 100644
--- a/modules/role/manifests/cache/parsoid.pp
+++ b/modules/role/manifests/cache/parsoid.pp
@@ -75,6 +75,7 @@
             'graphoid_backend' => 
$::role::cache::configuration::backends[$::realm]['graphoid'][$::mw_primary],
             'restbase_backend' => 
$::role::cache::configuration::backends[$::realm]['restbase'][$::mw_primary],
         },
+        dyn_director    => 'backend',
         director_type   => 'chash',
         vcl_config      => {
             'retry5xx'    => 0,
diff --git a/modules/role/manifests/cache/text.pp 
b/modules/role/manifests/cache/text.pp
index 234ee10..ec969fd 100644
--- a/modules/role/manifests/cache/text.pp
+++ b/modules/role/manifests/cache/text.pp
@@ -51,6 +51,11 @@
         default => 'chash',
     }
 
+    $be_dyn_director = $::role::cache::base::cluster_tier ? {
+        'two'   => 'eqiad',
+        default => undef,
+    }
+
     varnish::instance { 'text-backend':
         name               => '',
         vcl                => 'text-backend',
@@ -60,6 +65,7 @@
         runtime_parameters => $runtime_params,
         storage            => $::role::cache::2layer::persistent_storage_args,
         directors          => 
$varnish_be_directors[$::role::cache::base::cluster_tier],
+        dyn_directors      => $be_dyn_director,
         director_type      => $director_type_cluster,
         vcl_config         => {
             'cache4xx'         => '1m',
@@ -106,6 +112,7 @@
             'backend' => $site_text_nodes,
         },
         director_type   => 'chash',
+        dyn_director    => 'backend',
         vcl_config      => {
             'retry503'         => 1,
             'cache4xx'         => '1m',
diff --git a/modules/role/manifests/cache/upload.pp 
b/modules/role/manifests/cache/upload.pp
index c3e39a4..2a7a494 100644
--- a/modules/role/manifests/cache/upload.pp
+++ b/modules/role/manifests/cache/upload.pp
@@ -64,6 +64,11 @@
         default => 'chash',
     }
 
+    $be_dyn_director = $::role::cache::base::cluster_tier ? {
+        'two'   => 'eqiad',
+        default => undef,
+    }
+
     varnish::instance { 'upload-backend':
         name               => '',
         vcl                => 'upload-backend',
@@ -72,6 +77,7 @@
         runtime_parameters => $runtime_params,
         storage            => $upload_storage_args,
         directors          => 
$varnish_be_directors[$::role::cache::base::cluster_tier],
+        dyn_directors      => $be_dyn_director,
         director_type      => $director_type_cluster,
         vcl_config         => {
             'default_backend'  => $::role::cache::base::default_backend,
@@ -108,6 +114,7 @@
         directors       => {
             'backend' => $site_upload_nodes,
         },
+        dyn_directors   => 'backend',
         director_type   => 'chash',
         vcl_config      => {
             'retry503'         => 1,
diff --git a/modules/varnish/manifests/instance.pp 
b/modules/varnish/manifests/instance.pp
index ce01e4c..50e179d 100644
--- a/modules/varnish/manifests/instance.pp
+++ b/modules/varnish/manifests/instance.pp
@@ -14,7 +14,8 @@
     $extra_vcl = [],
     $cluster_options={},
     $wikimedia_networks=[],
-    $xff_sources=[]
+    $xff_sources=[],
+    $dyn_director=undef,
 ) {
 
     include varnish::common
@@ -50,14 +51,13 @@
 
     # Write the dynamic directors configuration, if we need it
     if $dynamic_directors {
-        require role::cache::base
         if $name == '' {
             $inst = 'backend'
         } else {
             $inst = $name
         }
         $use_dynamic_directors = ( !defined(Class['Role::Cache::1layer'])
-            and !($inst == 'backend' and $::role::cache::base::cluster_tier == 
'one'))
+            and $dyn_directors != undef)
         if $use_dynamic_directors {
             varnish::common::directors { $vcl:
                 instance      => $inst,
@@ -71,6 +71,8 @@
                                   ],
             }
         }
+    } else {
+        $use_dynamic_directors = false
     }
 
     file { "/etc/varnish/wikimedia_${vcl}.vcl":
diff --git a/modules/varnish/templates/vcl/directors.vcl.tpl.erb 
b/modules/varnish/templates/vcl/directors.vcl.tpl.erb
index 1fd647c..332fa01 100644
--- a/modules/varnish/templates/vcl/directors.vcl.tpl.erb
+++ b/modules/varnish/templates/vcl/directors.vcl.tpl.erb
@@ -11,8 +11,7 @@
        return ((Math.log10(100 - p) - 2) / (Math.log10(n - 1) - 
Math.log10(n))).ceil
 end
 
-# this is a one-element hash atm
-director = @directors.keys[0]
+director = @dyn_director
 -%>
 
 director <%= director %> <%= @director_type %> {
diff --git a/modules/varnish/templates/vcl/wikimedia.vcl.erb 
b/modules/varnish/templates/vcl/wikimedia.vcl.erb
index c2a8bfb..098e41f 100644
--- a/modules/varnish/templates/vcl/wikimedia.vcl.erb
+++ b/modules/varnish/templates/vcl/wikimedia.vcl.erb
@@ -144,10 +144,11 @@
 
 # Directors
 # Expected format: { "director name" => [ "backend1", "backend2" ] }
-<% if @use_dynamic_directors %>
+<% @varnish_directors.keys.sort.each do |director| -%>
+<% if @use_dynamic_directors and @dyn_director == director %>
+// We include director <%= director %> which is managed via confd
 include "directors.<%= @inst %>.vcl";
 <% else -%>
-<% @varnish_directors.keys.sort.each do |director| -%>
 director <%= director %> <%= @director_type %> {
 <% @director_options.each_pair do |option,value| -%>
        .<%= option %> = <%= value %>;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iff2c3881ab1a83ad927f96834507855e7bba9876
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Giuseppe Lavagetto <glavage...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to