diff --git a/lib/facter/proxysql_mycnf_file_name.rb b/lib/facter/proxysql_mycnf_file_name.rb new file mode 100644 index 00000000..b7a82e2e --- /dev/null +++ b/lib/facter/proxysql_mycnf_file_name.rb @@ -0,0 +1,4 @@ +Facter.add(:proxysql_mycnf_file_name) do + setcode do + if File.exist? '/root/.proxysql_mycnf_file_name' + Facter::Core::Execution.execute('cat /root/.proxysql_mycnf_file_name') diff --git a/lib/puppet/provider/proxy_mysql_query_rule/proxysql.rb b/lib/puppet/provider/proxy_mysql_query_rule/proxysql.rb index 93d67b38..9e90d5f2 100644 --- a/lib/puppet/provider/proxy_mysql_query_rule/proxysql.rb +++ b/lib/puppet/provider/proxy_mysql_query_rule/proxysql.rb @@ -25,14 +25,14 @@ def self.instances query = 'SELECT `active`, `username`, `schemaname`, `flagIN`, `flagOUT`, `apply`, ' \ ' `client_addr`, `proxy_addr`, `proxy_port`, `destination_hostgroup`, ' \ ' `digest`, `match_digest`, `match_pattern`, `negate_match_pattern`, `replace_pattern`, ' \ - ' `cache_ttl`, `reconnect`, `timeout`, `retries`, `delay`, `error_msg`, `log`, `comment`, ' \ + ' `cache_ttl`, `reconnect`, `multiplex`, `timeout`, `retries`, `delay`, `error_msg`, `log`, `comment`, ' \ ' `mirror_flagOUT`, `mirror_hostgroup`' \ " FROM `mysql_query_rules` WHERE rule_id = '#{rule_id}'" @active, @username, @schemaname, @flag_in, @flag_out, @apply, @client_addr, @proxy_addr, @proxy_port, @destination_hostgroup, @digest, @match_digest, @match_pattern, @negate_match_pattern, @replace_pattern, - @cache_ttl, @reconnect, @timeout, @retries, @delay, @error_msg, @log, @comment, + @cache_ttl, @reconnect, @multiplex, @timeout, @retries, @delay, @error_msg, @log, @comment, @mirror_flag_out, @mirror_hostgroup = mysql([defaults_file, '-NBe', query].compact).to_s.chomp.split(%r{\t}) name = "mysql_query_rule-#{rule_id}" @@ -61,6 +61,7 @@ def self.instances replace_pattern: @replace_pattern, cache_ttl: @cache_ttl, reconnect: @reconnect, + multiplex: @multiplex, timeout: @timeout, retries: @retries, delay: @delay, @@ -104,6 +105,7 @@ def create replace_pattern = make_sql_value(@resource.value(:replace_pattern) || nil) cache_ttl = make_sql_value(@resource.value(:cache_ttl) || nil) reconnect = make_sql_value(@resource.value(:reconnect) || nil) + multiplex = make_sql_value(@resource.value(:multiplex) || nil) timeout = make_sql_value(@resource.value(:timeout) || nil) retries = make_sql_value(@resource.value(:retries) || nil) delay = make_sql_value(@resource.value(:delay) || nil) @@ -117,12 +119,12 @@ def create '`rule_id`, `active`, `username`, `schemaname`, `flagIN`, `flagOUT`, `apply`, ' \ '`client_addr`, `proxy_addr`, `proxy_port`, `destination_hostgroup`, ' \ '`digest`, `match_digest`, `match_pattern`, `negate_match_pattern`, `replace_pattern`, ' \ - '`cache_ttl`, `reconnect`, `timeout`, `retries`, `delay`, `error_msg`, `log`, `comment`, ' \ + '`cache_ttl`, `reconnect`, `multiplex`, `timeout`, `retries`, `delay`, `error_msg`, `log`, `comment`, ' \ '`mirror_flagOUT`, `mirror_hostgroup`) VALUES (' \ "#{rule_id}, #{active}, #{username}, #{schemaname}, #{flag_in}, #{flag_out}, #{apply}, " \ "#{client_addr}, #{proxy_addr}, #{proxy_port}, #{destination_hostgroup}, " \ "#{digest}, #{match_digest}, #{match_pattern}, #{negate_match_pattern}, #{replace_pattern}, " \ - "#{cache_ttl}, #{reconnect}, #{timeout}, #{retries}, #{delay}, #{error_msg}, #{log}, #{comment}, " \ + "#{cache_ttl}, #{reconnect}, #{multiplex}, #{timeout}, #{retries}, #{delay}, #{error_msg}, #{log}, #{comment}, " \ "#{mirror_flag_out}, #{mirror_hostgroup})" mysql([defaults_file, '-e', query].compact) @property_hash[:ensure] = :present @@ -245,6 +247,10 @@ def reconnect=(value) @property_flush[:reconnect] = value end + def multiplex=(value) + @property_flush[:multiplex] = value + end + def timeout=(value) @property_flush[:timeout] = value end diff --git a/lib/puppet/provider/proxysql.rb b/lib/puppet/provider/proxysql.rb index d2d8d1a5..d20a3499 100644 --- a/lib/puppet/provider/proxysql.rb +++ b/lib/puppet/provider/proxysql.rb @@ -11,7 +11,7 @@ class Puppet::Provider::Proxysql < Puppet::Provider # Optional defaults file def self.defaults_file - "--defaults-extra-file=#{Facter.value(:root_home)}/.my.cnf" if File.file?("#{Facter.value(:root_home)}/.my.cnf") + "--defaults-extra-file=#{Facter.value(:proxysql_mycnf_file_name)}" if File.file?(Facter.value(:proxysql_mycnf_file_name).to_s) end def defaults_file diff --git a/lib/puppet/type/proxy_cluster.rb b/lib/puppet/type/proxy_cluster.rb index e56b625f..d1bf3443 100644 --- a/lib/puppet/type/proxy_cluster.rb +++ b/lib/puppet/type/proxy_cluster.rb @@ -6,7 +6,7 @@ ensurable - autorequire(:file) { '/root/.my.cnf' } + autorequire(:class) { 'proxysql::admin_credentials' } autorequire(:class) { 'mysql::client' } autorequire(:service) { 'proxysql' } diff --git a/lib/puppet/type/proxy_global_variable.rb b/lib/puppet/type/proxy_global_variable.rb index db277d49..5f259ac3 100644 --- a/lib/puppet/type/proxy_global_variable.rb +++ b/lib/puppet/type/proxy_global_variable.rb @@ -4,7 +4,7 @@ Puppet::Type.newtype(:proxy_global_variable) do @doc = 'Manage a ProxySQL global variable.' - autorequire(:file) { '/root/.my.cnf' } + autorequire(:class) { 'proxysql::admin_credentials' } autorequire(:class) { 'mysql::client' } autorequire(:service) { 'proxysql' } diff --git a/lib/puppet/type/proxy_mysql_galera_hostgroup.rb b/lib/puppet/type/proxy_mysql_galera_hostgroup.rb index 1ceb66e5..b0127b71 100644 --- a/lib/puppet/type/proxy_mysql_galera_hostgroup.rb +++ b/lib/puppet/type/proxy_mysql_galera_hostgroup.rb @@ -5,7 +5,7 @@ Puppet::Type.newtype(:proxy_mysql_galera_hostgroup) do @doc = 'Manage a ProxySQL mysql_galera_hostgroup.' - autorequire(:file) { '/root/.my.cnf' } + autorequire(:class) { 'proxysql::admin_credentials' } autorequire(:class) { 'mysql::client' } autorequire(:service) { 'proxysql' } diff --git a/lib/puppet/type/proxy_mysql_group_replication_hostgroup.rb b/lib/puppet/type/proxy_mysql_group_replication_hostgroup.rb index 1a56fdff..4065bce0 100644 --- a/lib/puppet/type/proxy_mysql_group_replication_hostgroup.rb +++ b/lib/puppet/type/proxy_mysql_group_replication_hostgroup.rb @@ -6,7 +6,7 @@ ensurable - autorequire(:file) { '/root/.my.cnf' } + autorequire(:class) { 'proxysql::admin_credentials' } autorequire(:class) { 'mysql::client' } autorequire(:service) { 'proxysql' } diff --git a/lib/puppet/type/proxy_mysql_query_rule.rb b/lib/puppet/type/proxy_mysql_query_rule.rb index f73ab785..087566a9 100644 --- a/lib/puppet/type/proxy_mysql_query_rule.rb +++ b/lib/puppet/type/proxy_mysql_query_rule.rb @@ -5,7 +5,7 @@ ensurable - autorequire(:file) { '/root/.my.cnf' } + autorequire(:class) { 'proxysql::admin_credentials' } autorequire(:class) { 'mysql::client' } autorequire(:service) { 'proxysql' } @@ -120,6 +120,11 @@ newvalue(%r{[01]}) end + newproperty(:multiplex) do + desc 'Enable / Disable multiplexing on rule' + newvalue(%r{[01]}) + end + newproperty(:timeout) do desc 'The maximum amount of miliseconds in which the matched or rewritten query should be executed.' newvalue(%r{\d+}) diff --git a/lib/puppet/type/proxy_mysql_replication_hostgroup.rb b/lib/puppet/type/proxy_mysql_replication_hostgroup.rb index 50b3a512..9d581184 100644 --- a/lib/puppet/type/proxy_mysql_replication_hostgroup.rb +++ b/lib/puppet/type/proxy_mysql_replication_hostgroup.rb @@ -6,7 +6,7 @@ ensurable - autorequire(:file) { '/root/.my.cnf' } + autorequire(:class) { 'proxysql::admin_credentials' } autorequire(:class) { 'mysql::client' } autorequire(:service) { 'proxysql' } diff --git a/lib/puppet/type/proxy_mysql_server.rb b/lib/puppet/type/proxy_mysql_server.rb index f4cd332c..d7f0e45b 100644 --- a/lib/puppet/type/proxy_mysql_server.rb +++ b/lib/puppet/type/proxy_mysql_server.rb @@ -6,7 +6,7 @@ ensurable - autorequire(:file) { '/root/.my.cnf' } + autorequire(:class) { 'proxysql::admin_credentials' } autorequire(:class) { 'mysql::client' } autorequire(:service) { 'proxysql' } diff --git a/lib/puppet/type/proxy_mysql_server_no_hostgroup.rb b/lib/puppet/type/proxy_mysql_server_no_hostgroup.rb index bbe925f2..4267597c 100644 --- a/lib/puppet/type/proxy_mysql_server_no_hostgroup.rb +++ b/lib/puppet/type/proxy_mysql_server_no_hostgroup.rb @@ -6,7 +6,7 @@ ensurable - autorequire(:file) { '/root/.my.cnf' } + autorequire(:class) { 'proxysql::admin_credentials' } autorequire(:class) { 'mysql::client' } autorequire(:service) { 'proxysql' } diff --git a/lib/puppet/type/proxy_mysql_user.rb b/lib/puppet/type/proxy_mysql_user.rb index 4fb10d23..fa603888 100644 --- a/lib/puppet/type/proxy_mysql_user.rb +++ b/lib/puppet/type/proxy_mysql_user.rb @@ -8,7 +8,7 @@ ensurable - autorequire(:file) { '/root/.my.cnf' } + autorequire(:class) { 'proxysql::admin_credentials' } autorequire(:class) { 'mysql::client' } autorequire(:service) { 'proxysql' } diff --git a/lib/puppet/type/proxy_scheduler.rb b/lib/puppet/type/proxy_scheduler.rb index 3ddda4de..53785f76 100644 --- a/lib/puppet/type/proxy_scheduler.rb +++ b/lib/puppet/type/proxy_scheduler.rb @@ -5,7 +5,7 @@ ensurable - autorequire(:file) { '/root/.my.cnf' } + autorequire(:class) { 'proxysql::admin_credentials' } autorequire(:class) { 'mysql::client' } autorequire(:service) { 'proxysql' } diff --git a/manifests/admin_credentials.pp b/manifests/admin_credentials.pp index 3cb3bfc9..1d648a09 100644 --- a/manifests/admin_credentials.pp +++ b/manifests/admin_credentials.pp @@ -19,7 +19,10 @@ -o `/usr/bin/mysql --defaults-extra-file=${mycnf_file_name} -BN \ --execute=\"SELECT variable_value FROM global_variables WHERE variable_name='admin-mysql_ifaces'\"` != '${admin_interfaces}' ", - before => File['root-mycnf-file'], + before => [ + File['root-mycnf-file'], + File['/root/.proxysql_mycnf_file_name'] + ], } file { 'root-mycnf-file': @@ -30,5 +33,12 @@ group => $proxysql::sys_group, mode => '0400', } + + # This is to keep track of my cnf file. + # This is used by custom proxy_* resources + file { '/root/.proxysql_mycnf_file_name': + ensure => file, + content => $proxysql::mycnf_file_name, + } } } diff --git a/manifests/reload_config.pp b/manifests/reload_config.pp index 9154da48..7362cebf 100644 --- a/manifests/reload_config.pp +++ b/manifests/reload_config.pp @@ -18,7 +18,7 @@ SAVE MYSQL VARIABLES TO DISK; \" ", subscribe => $subscribe, - require => [Service[$proxysql::service_name], File['root-mycnf-file']], + require => [Service[$proxysql::service_name], File['root-mycnf-file'], File['/root/.proxysql_mycnf_file_name']], refreshonly => true, } } diff --git a/manifests/service.pp b/manifests/service.pp index 81c870c6..c97cdc3c 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -15,7 +15,7 @@ ensure => $drop_in_ensure, filename => 'puppet.conf', unit => "${proxysql::service_name}.service", - content => "[Service]\nExecStart=\nExecStart=/usr/bin/proxysql --reload -c /etc/proxysql.cnf\n", + content => "[Service]\nExecStart=\nExecStart=/usr/bin/proxysql --reload --idle-threads -c /etc/proxysql.cnf \$PROXYSQL_OPTS\n", notify => Service[$proxysql::service_name], } service { $proxysql::service_name: diff --git a/types/rule.pp b/types/rule.pp index 95686bc3..2a72706c 100644 --- a/types/rule.pp +++ b/types/rule.pp @@ -17,6 +17,7 @@ Optional[destination_hostgroup] => Integer, Optional[cache_ttl] => Integer, Optional[reconnect] => Integer[0,1], + Optional[multiplex] => Integer[0,1], Optional[timeout] => Integer, Optional[retries] => Integer, Optional[delay] => Integer,