Giuseppe Lavagetto has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/345158 )
Change subject: service::node: refactor configuration, allow use of confd for
scap3
......................................................................
service::node: refactor configuration, allow use of confd for scap3
Change-Id: I119339458b599ee254695c7f3c95815d4f1eca02
---
M modules/service/manifests/node.pp
A modules/service/manifests/node/config.pp
A modules/service/manifests/node/config/scap3.pp
M modules/service/templates/node/apply-config.sh.erb
M modules/service/templates/node/config-vars.yaml.erb
5 files changed, 203 insertions(+), 67 deletions(-)
Approvals:
Giuseppe Lavagetto: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/service/manifests/node.pp
b/modules/service/manifests/node.pp
index c91fa7a..5a9c819 100644
--- a/modules/service/manifests/node.pp
+++ b/modules/service/manifests/node.pp
@@ -26,7 +26,8 @@
# [*full_config*]
# Whether the full config has been provided by the caller. If set to true,
# no config merging will take place and the caller is required to supply the
-# 'config' parameter. Default: false
+# 'config' parameter. If set to 'external', it will prevent service::node
from
+# performing any configuration. Default: false
#
# [*no_workers*]
# Number of workers to start. Default: 'ncpu' (i.e. start as many workers as
@@ -216,28 +217,9 @@
fail('Service port must be specified and must be a number!')
}
- # the local log file name
+ # the local log directory
$local_logdir = "${service::configuration::log_dir}/${title}"
$local_logfile = "${local_logdir}/main.log"
-
- # configuration management
- if $full_config {
- unless $config and size($config) > 0 {
- fail('A config needs to be specified when full_config == true!')
- }
- $complete_config = $config
- } else {
- # load configuration
- $local_config = $config ? {
- undef => '{}',
- default => $config
- }
- $complete_config = merge_config(
- template('service/node/config.yaml.erb'),
- $local_config
- )
- }
-
# Software and the deployed code, firejail for containment
require_package('nodejs', 'nodejs-legacy', 'firejail')
@@ -269,7 +251,9 @@
mode => '0775',
}
- if $deployment == 'scap3' and $deployment_config {
+ if $full_config == 'external' {
+ notice("Not configuring ${title} as configuration is handled
independently")
+ } elsif $deployment == 'scap3' and $deployment_config {
# NOTE: this is a work-around need to switch config file deployments
# to Scap3. The previous praxis was to make the config owned by root,
# but that is not possible with Scap3, as it installs a symlink under
@@ -283,52 +267,35 @@
onlyif => "/usr/bin/test -O ${chown_target}",
require => [User[$deployment_user], Group[$deployment_user]]
}
- file { "/etc/${title}/config-vars.yaml":
- ensure => present,
- content => template('service/node/config-vars.yaml.erb'),
- owner => $deployment_user,
- group => $deployment_user,
- mode => '0444',
- tag => "${title}::config",
+ service::node::config::scap3 { $title:
+ port => $port,
+ no_workers => $no_workers,
+ heap_limit => $heap_limit,
+ heartbeat_to => $heartbeat_to,
+ repo => $repo,
+ starter_module => $starter_module,
+ entrypoint => $entrypoint,
+ logging_name => $logging_name,
+ statsd_prefix => $statsd_prefix,
+ auto_refresh => $auto_refresh,
+ deployment_vars => $deployment_vars,
+ deployment_user => $deployment_user,
}
-
- # We need to ensure that the full config gets deployed when we change
the
- # puppet controlled part. If auto_refresh is true, this will also
restart
- # the service.
- file { "/usr/local/bin/apply-config-${title}":
- ensure => present,
- content => template('service/node/apply-config.sh.erb'),
- owner => 'root',
- group => 'root',
- mode => '0755',
- before => Exec["${title} config deploy"],
- }
-
- exec { "${title} config deploy":
- command => "/usr/local/bin/apply-config-${title}",
- user => $deployment_user,
- group => $deployment_user,
- refreshonly => true,
- subscribe => File["/etc/${title}/config-vars.yaml"],
- }
-
} else {
- file { "/etc/${title}/config.yaml":
- ensure => present,
- content => $complete_config,
- owner => 'root',
- group => 'root',
- mode => '0444',
- tag => "${title}::config",
- }
- if $auto_refresh {
- # if the service should be restarted after a
- # config change, specify the notify/before requirement
- File["/etc/${title}/config.yaml"] ~> Service[$title]
- } else {
- # no restart should happen, just ensure the file is
- # created before the service
- File["/etc/${title}/config.yaml"] -> Service[$title]
+ service::node::config { $title:
+ port => $port,
+ config => $config,
+ full_config => $full_config,
+ no_workers => $no_workers,
+ heap_limit => $heap_limit,
+ heartbeat_to => $heartbeat_to,
+ local_logging => $local_logging,
+ starter_module => $starter_module,
+ entrypoint => $entrypoint,
+ logging_name => $logging_name,
+ statsd_prefix => $statsd_prefix,
+ auto_refresh => $auto_refresh,
+ use_proxy => $use_proxy
}
}
diff --git a/modules/service/manifests/node/config.pp
b/modules/service/manifests/node/config.pp
new file mode 100644
index 0000000..4e14b91
--- /dev/null
+++ b/modules/service/manifests/node/config.pp
@@ -0,0 +1,66 @@
+# === define service::node::config::scap3
+#
+# Used to deploy a configuration for a service that uses service::node.
+#
+# == Parameters
+#
+# All parameters have the same meaning as in service::node, to the
documentation of which you
+# should refer for those.
+#
+define service::node::config(
+ $port,
+ $config = undef,
+ $full_config = false,
+ $no_workers = 'ncpu',
+ $heap_limit = 300,
+ $heartbeat_to = 7500,
+ $logging_name = $title,
+ $local_logging = true,
+ $statsd_prefix = $title,
+ $starter_module = './src/app.js',
+ $entrypoint = '',
+ $use_proxy = false,
+ $auto_refresh = true,
+) {
+ require ::service::configuration
+ # the local log file name
+ $local_logdir = "${service::configuration::log_dir}/${title}"
+ $local_logfile = "${local_logdir}/main.log"
+
+ # configuration management
+ if $full_config {
+ unless $config and size($config) > 0 {
+ fail('A config needs to be specified when full_config == true!')
+ }
+ $complete_config = $config
+ }
+ else {
+ # load configuration
+ $local_config = $config ? {
+ undef => '{}',
+ default => $config
+ }
+ $complete_config = merge_config(
+ template('service/node/config.yaml.erb'),
+ $local_config
+ )
+ }
+ file { "/etc/${title}/config.yaml":
+ ensure => present,
+ content => $complete_config,
+ owner => 'root',
+ group => 'root',
+ mode => '0444',
+ tag => "${title}::config",
+ }
+ if $auto_refresh {
+ # if the service should be restarted after a
+ # config change, specify the notify/before requirement
+ File["/etc/${title}/config.yaml"] ~> Service[$title]
+ } else {
+ # no restart should happen, just ensure the file is
+ # created before the service
+ File["/etc/${title}/config.yaml"] -> Service[$title]
+ }
+
+}
diff --git a/modules/service/manifests/node/config/scap3.pp
b/modules/service/manifests/node/config/scap3.pp
new file mode 100644
index 0000000..519b8f1
--- /dev/null
+++ b/modules/service/manifests/node/config/scap3.pp
@@ -0,0 +1,94 @@
+# === define service::node::config::scap3
+#
+# Used to deploy a configuration for a service that uses service::node.
+#
+# == Parameters
+#
+# Most parameters have the same meaning as in service::node, to the
documentation of which you
+# should refer for those.
+#
+# [*discovery*] If set, it will make the config-vars file managed by confd and
use discovery
+# based records to change the data in config-vars.yaml and then
reload the config.
+#
+# [*confd_template*] Confd template fragment to include at the end of the
config file so that it
+# can be delegated to confd.
+#
+# [*max_splay*] For services controlled via confd, enable a splay to delay
execution of the service restarts.
+#
+define service::node::config::scap3 (
+ $port,
+ $no_workers = 'ncpu',
+ $heap_limit = 300,
+ $heartbeat_to = 7500,
+ $repo = "${title}/deploy",
+ $starter_module = './src/app.js',
+ $entrypoint = '',
+ $logging_name = $title,
+ $statsd_prefix = $title,
+ $auto_refresh = true,
+ $deployment_user = 'deploy-service',
+ $deployment_vars = {},
+ $discovery = undef,
+ $confd_template = undef,
+ $max_splay = 120,
+){
+ require ::service::configuration
+ # the local log file name
+ $local_logdir = "${service::configuration::log_dir}/${title}"
+ $local_logfile = "${local_logdir}/main.log"
+ # We need to ensure that the full config gets deployed when we change the
+ # puppet controlled part. If auto_refresh is true, this will also restart
+ # the service.
+ file { "/usr/local/bin/apply-config-${title}":
+ ensure => present,
+ content => template('service/node/apply-config.sh.erb'),
+ owner => 'root',
+ group => 'root',
+ mode => '0755',
+ before => Exec["${title} config deploy"],
+ }
+
+ if $discovery {
+ # This will make any change (either puppet or confd-drive) trigger
+ # the apply script, with a random sleep (0-120 seconds) in front to
help
+ # spread restarts in two minutes.
+ # Race conditions will be handled as follows:
+ # - If you make two etcd changes in a row, and you make them in the
+ # interval between two subsequent polls from confd to etcd, just the
+ # latter will be acted upon by confd
+ # - If you make one before and one after confd has queried etcd, you
+ # will have two splay-ed restarts firing up, as follows:
+ # 1. confd queries etcd for the first time the reload script is
+ # launched, and confd will wait for it to complete
+ # 2. once it's completed, the second value will be written to the
+ # config file and a new splayed restart will happen.
+ # No race condition is possible here too.
+ # - confd treats reload failures by just keep running, but we will be
+ # notified by alerting if that happens, as it would happen with puppet
before
+ # - reloads have a sort-of global lock in the fact after depooling, we
+ # actually query pybal to be sure the service is depooled before
+ # restarting. Since pybal has its depool-threshold, that will prevent
+ # more than X servers in a pool from restarting at the same time.
+ confd::file { "/etc/${title}/config-vars.yaml":
+ ensure => present,
+ watch_keys => "/discovery/${discovery}",
+ reload => "/usr/local/apply-config-${title}"
+ }
+ } else {
+ file { "/etc/${title}/config-vars.yaml":
+ ensure => present,
+ content => template('service/node/config-vars.yaml.erb'),
+ owner => $deployment_user,
+ group => $deployment_user,
+ mode => '0444',
+ tag => "${title}::config",
+ }
+ exec { "${title} config deploy":
+ command => "/usr/local/bin/apply-config-${title}",
+ user => $deployment_user,
+ group => $deployment_user,
+ refreshonly => true,
+ subscribe => File["/etc/${title}/config-vars.yaml"],
+ }
+ }
+}
diff --git a/modules/service/templates/node/apply-config.sh.erb
b/modules/service/templates/node/apply-config.sh.erb
index 5ae72d9..a0c98d5 100755
--- a/modules/service/templates/node/apply-config.sh.erb
+++ b/modules/service/templates/node/apply-config.sh.erb
@@ -4,4 +4,10 @@
set -e
/usr/bin/scap deploy-local -D 'log_json:False' --repo <%= @repo %> --force
config_deploy;
-<%- if @auto_refresh %>/usr/bin/scap deploy-local -D 'log_json:False' --repo
<%= @repo %> --force restart_service;<%- end -%>
+<%- if @auto_refresh -%>
+<%- if @discovery -%>
+# Sleep a random time between 0 and <%= @max_splay %> seconds to avoid herd
effects
+sleep $[ $RANDOM % <%= @max_splay %> ]
+<%- end -%>
+/usr/bin/scap deploy-local -D 'log_json:False' --repo <%= @repo %> --force
restart_service;
+<%- end -%>
diff --git a/modules/service/templates/node/config-vars.yaml.erb
b/modules/service/templates/node/config-vars.yaml.erb
index c10b6bf..d35ab21 100644
--- a/modules/service/templates/node/config-vars.yaml.erb
+++ b/modules/service/templates/node/config-vars.yaml.erb
@@ -40,3 +40,6 @@
# deployment variables
<%= scope.function_ordered_yaml([@deployment_vars]) %>
<% end -%>
+<%- if @discovery && @confd_template -%>
+<%= @confd_template %>
+<%- end -%>
--
To view, visit https://gerrit.wikimedia.org/r/345158
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I119339458b599ee254695c7f3c95815d4f1eca02
Gerrit-PatchSet: 8
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Giuseppe Lavagetto <[email protected]>
Gerrit-Reviewer: Giuseppe Lavagetto <[email protected]>
Gerrit-Reviewer: Mobrovac <[email protected]>
Gerrit-Reviewer: Volans <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits