Skip to content

Commit

Permalink
Merge pull request #60 from MaxFedotov/configs_separation
Browse files Browse the repository at this point in the history
add ability to split config into 2 files
  • Loading branch information
mcrauwel authored Sep 10, 2018
2 parents 024713a + 0b75147 commit 5bdf86f
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 19 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ Matthias Crauwels (@mcrauwel)
Narcis Pillao (@narcisbcn)
Rudy Gevaert (@rgevaert)
Tim Meusel (@bastelfreak)
Maxim Fedotov (@MaxFedotov)
8 changes: 8 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,14 @@ Array of mysql_rules, that will be created in ProxySQL. Defaults to undef

##### `schedulers`
Array of schedulers, that will be created in ProxySQL. Defaults to undef
##### `split_config`
If set, ProxySQL config file will be split in 2: main config file with admin and mysql variables and proxy config file with servers\users\hostgroups\scheduler\rules params. Defaults to false

##### `proxy_config_file`
The file where servers\users\hostgroups\scheduler\rules params of ProxySQL configuration are saved. This will only be configured if `split_config` is set to `true`. Defaults to 'proxysql_proxy.cnf'

#####`manage_proxy_config_file`
Determines wheter this module will update the ProxySQL proxy configuration file. Defaults to 'true'

## Types
#### proxy_global_variable
Expand Down
15 changes: 15 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
class proxysql::config {

$config_settings = $proxysql::config_settings
$proxy_config_file = $proxysql::proxy_config_file
$split_config = $proxysql::split_config

if $proxysql::manage_config_file {
file { 'proxysql-config-file':
ensure => file,
Expand All @@ -17,4 +20,16 @@
}
}

if $proxysql::split_config {
file { 'proxysql-proxy-config-file':
ensure => file,
path => $proxysql::proxy_config_file,
content => epp('proxysql/proxysql_proxy.cnf.epp', { config_settings => $config_settings }),
mode => '0640',
owner => $proxysql::sys_owner,
group => $proxysql::sys_group,
selinux_ignore_defaults => true,
replace => $proxysql::manage_proxy_config_file,
}
}
}
21 changes: 19 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
# Which configuration variables should be overriden. Hash, defaults to {} (empty hash).
#
# * `cluster_name`
# If set, proxysql_servers with the same cluster_name will be automatically added to the same cluster and will
# If set, proxysql_servers with the same cluster_name will be automatically added to the same cluster and will
# synchronize their configuration parameters. Defaults to undef
#
# * `cluster_username`
Expand All @@ -116,7 +116,7 @@
# The name of the mysql client package in your package manager. Defaults to undef
#
# * `manage_hostgroup_for_servers`
# Determines wheter this module will manage hostgroup_id for mysql_servers.
# Determines wheter this module will manage hostgroup_id for mysql_servers.
# If false - it will skip difference in this value between manifest and defined in ProxySQL. Defaults to 'true'
#
# * `mysql_servers`
Expand All @@ -133,6 +133,16 @@
#
# * `schedulers`
# Array of schedulers, that will be created in ProxySQL. Defaults to undef
# * `split_config`
# If set, ProxySQL config file will be split in 2: main config file with admin and mysql variables
# and proxy config file with servers\users\hostgroups\scheduler params. Defaults to false
#
# * `proxy_config_file`
# The file where servers\users\hostgroups\scheduler\rules params of ProxySQL configuration are saved
# This will only be configured if `split_config` is set to `true`. Defaults to 'proxysql_proxy.cnf'
#
# * `manage_proxy_config_file`
# Determines wheter this module will update the ProxySQL proxy configuration file. Defaults to 'true'
#
class proxysql (
Optional[String] $cluster_name = $proxysql::params::cluster_name,
Expand All @@ -158,6 +168,11 @@
String $monitor_username = $proxysql::params::monitor_username,
Sensitive[String] $monitor_password = $proxysql::params::monitor_password,

Boolean $split_config = $proxysql::params::split_config,

String $proxy_config_file = $proxysql::params::proxy_config_file,
Boolean $manage_proxy_config_file = $proxysql::params::manage_proxy_config_file,

String $config_file = $proxysql::params::config_file,
Boolean $manage_config_file = $proxysql::params::manage_config_file,

Expand Down Expand Up @@ -227,11 +242,13 @@
# lint:endignore

anchor { 'proxysql::begin': }
-> class { 'proxysql::prerequisites':}
-> class { 'proxysql::repo':}
-> class { 'proxysql::install':}
-> class { 'proxysql::config':}
-> class { 'proxysql::service':}
-> class { 'proxysql::admin_credentials':}
-> class { 'proxysql::reload_config':}
-> class { 'proxysql::configure':}
-> anchor { 'proxysql::end': }

Expand Down
1 change: 1 addition & 0 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
}
}


file { 'proxysql-datadir':
ensure => directory,
path => $proxysql::datadir,
Expand Down
27 changes: 15 additions & 12 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
'Debian': {
case $facts['os']['release']['major'] {
'8': {
$package_source = 'https://github.com/sysown/proxysql/releases/download/v1.4.10/proxysql_1.4.10-debian8_amd64.deb'
$package_checksum_value = '98bab1b7cd719039b1483f7d51c30d7fc563def7'
$package_source = 'https://github.com/sysown/proxysql/releases/download/v1.4.11/proxysql_1.4.11-debian8_amd64.deb'
$package_checksum_value = '813a91ea030ef480c0210b047df5e88ff1c27810'
$package_checksum_type = 'sha1'
$package_dependencies = []
}
'9': {
$package_source = 'https://github.com/sysown/proxysql/releases/download/v1.4.10/proxysql_1.4.10-debian9_amd64.deb'
$package_checksum_value = 'd97a2f870e46d5f3218ab80d6c0db6bcc288127a'
$package_source = 'https://github.com/sysown/proxysql/releases/download/v1.4.11/proxysql_1.4.11-debian9_amd64.deb'
$package_checksum_value = '65a3c2b98eefa42946ee59eef18ba18534c2a39d'
$package_checksum_type = 'sha1'
$package_dependencies = []
}
Expand All @@ -54,14 +54,14 @@
'Ubuntu': {
case $facts['os']['release']['major'] {
'14.04': {
$package_source = 'https://github.com/sysown/proxysql/releases/download/v1.4.10/proxysql_1.4.10-ubuntu14_amd64.deb'
$package_checksum_value = '0b89f290bd9cd7e8bc2b7acd8a7799840a31af94'
$package_source = 'https://github.com/sysown/proxysql/releases/download/v1.4.11/proxysql_1.4.11-ubuntu14_amd64.deb'
$package_checksum_value = '42b99a12e8e43410aed88da4c5bbe902c43dbba1'
$package_checksum_type = 'sha1'
$package_dependencies = []
}
'16.04': {
$package_source = 'https://github.com/sysown/proxysql/releases/download/v1.4.10/proxysql_1.4.10-ubuntu16_amd64.deb'
$package_checksum_value = 'df8695c6296678a0eeda036cddff679cc1ff604e'
$package_source = 'https://github.com/sysown/proxysql/releases/download/v1.4.11/proxysql_1.4.11-ubuntu16_amd64.deb'
$package_checksum_value = '6e7db2fee78eee1a22cdfabefaa50953c3d24501'
$package_checksum_type = 'sha1'
$package_dependencies = []
}
Expand Down Expand Up @@ -95,8 +95,8 @@
}
'RedHat': {
$package_provider = 'rpm'
$package_source = 'https://github.com/sysown/proxysql/releases/download/v1.4.10/proxysql-1.4.10-1-centos67.x86_64.rpm'
$package_checksum_value = 'f5ca4efa9d69e9bd6ba9a96c724b031cd7326051'
$package_source = 'https://github.com/sysown/proxysql/releases/download/v1.4.11/proxysql-1.4.11-1-centos67.x86_64.rpm'
$package_checksum_value = '6f302beaea096b63851a136287818a1b6e049e28'
$package_checksum_type = 'sha1'
$package_dependencies = ['perl-DBI', 'perl-DBD-mysql']
$repo = {
Expand All @@ -117,8 +117,11 @@

$datadir = '/var/lib/proxysql'

$config_file = '/etc/proxysql.cnf'
$manage_config_file = true
$split_config = false
$config_file = '/etc/proxysql.cnf'
$manage_config_file = true
$proxy_config_file = '/etc/proxysql_proxy.cnf'
$manage_proxy_config_file = true

$mycnf_file_name = '/root/.my.cnf'
$manage_mycnf_file = true
Expand Down
18 changes: 18 additions & 0 deletions manifests/prerequisites.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Class: proxysql::prerequisites
# ===========================
#
# Manage the prerequisites where the ProxySQL package might be
#
class proxysql::prerequisites inherits proxysql {
if $proxysql::sys_owner != 'root' { # let's assume that 'root' will exist and not touch that...
group { $proxysql::sys_group:
ensure => 'present',
}

user { $proxysql::sys_owner:
ensure => 'present',
groups => $proxysql::sys_group,
}
}

}
26 changes: 26 additions & 0 deletions manifests/reload_config.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# == Class proxysql::reload_config
#
# This class is called from proxysql to update config if it changed.
#
class proxysql::reload_config {

$subscribe = $proxysql::split_config ? {
true => [ File['proxysql-config-file'], File['proxysql-proxy-config-file'] ],
false => File['proxysql-config-file'],
}

$mycnf_file_name = $proxysql::mycnf_file_name
exec {'reload-config':
command => "/usr/bin/mysql --defaults-extra-file=${mycnf_file_name} --execute=\"
LOAD ADMIN VARIABLES FROM CONFIG; \
LOAD ADMIN VARIABLES TO RUNTIME; \
SAVE ADMIN VARIABLES TO DISK; \
LOAD MYSQL VARIABLES FROM CONFIG; \
LOAD MYSQL VARIABLES TO RUNTIME; \
SAVE MYSQL VARIABLES TO DISK; \"
",
subscribe => $subscribe,
require => [ Service[$proxysql::service_name] , File['root-mycnf-file'] ],
refreshonly => true,
}
}
3 changes: 2 additions & 1 deletion spec/classes/proxysql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
it { is_expected.to contain_class('proxysql::install').that_comes_before('Class[proxysql::config]') }
it { is_expected.to contain_class('proxysql::config').that_comes_before('Class[proxysql::service]') }
it { is_expected.to contain_class('proxysql::service').that_comes_before('Class[proxysql::admin_credentials]') }
it { is_expected.to contain_class('proxysql::admin_credentials').that_comes_before('Class[proxysql::configure]') }
it { is_expected.to contain_class('proxysql::admin_credentials').that_comes_before('Class[proxysql::reload_config]') }
it { is_expected.to contain_class('proxysql::reload_config').that_comes_before('Class[proxysql::configure]') }
it { is_expected.to contain_class('proxysql::configure').that_comes_before('Anchor[proxysql::end]') }

it { is_expected.to contain_anchor('proxysql::end') }
Expand Down
10 changes: 6 additions & 4 deletions templates/proxysql.cnf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ default_handler = Proc.new do |k, v|
<%
end
end

hash_handler = Proc.new do |k, v|
if v.is_a?(Hash)
-%>
Expand All @@ -27,7 +26,6 @@ hash_handler = Proc.new do |k, v|
default_handler.call(k, v)
end
end

@config_settings.map do |k, v|
if v.is_a?(Hash)
if k == 'admin_variables' || k == 'mysql_variables'
Expand All @@ -42,6 +40,7 @@ end
<%
else
-%>
<% if @split_config == false -%>
<%= k %> = (
<%
v.each do |ki, vi|
Expand All @@ -50,7 +49,6 @@ end
else
default_handler.call(ki, vi)
end

if v.keys.index(ki) < v.size - 1
-%>
,
Expand All @@ -60,11 +58,15 @@ end
-%>

)

<% end -%>
<%
end
else
default_handler.call(k, v)
end
end
-%>
<% if @split_config == true -%>
@include "<%= @proxy_config_file %>"
<% end -%>
18 changes: 18 additions & 0 deletions templates/proxysql_proxy.cnf.epp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<%- | Hash $config_settings | -%>
<% $config_settings.each |$key, $value| { -%>
<% if $key == "mysql_servers" { -%>
<%= $key %> = (<% if $value != {} { -%><%= $value %><% } -%>)
<% } -%>
<% if $key == "mysql_users" { -%>
<%= $key %> = (<% if $value != {} { -%><%= $value %><% } -%>)
<% } -%>
<% if $key == "mysql_query_rules" { -%>
<%= $key %> = (<% if $value != {} { -%><%= $value %><% } -%>)
<% } -%>
<% if $key == "scheduler" { -%>
<%= $key %> = (<% if $value != {} { -%><%= $value %><% } -%>)
<% } -%>
<% if $key == "mysql_replication_hostgroups" { -%>
<%= $key %> = (<% if $value != {} { -%><%= $value %><% } -%>)
<% } -%>
<% } -%>

0 comments on commit 5bdf86f

Please sign in to comment.