Skip to content

Commit

Permalink
Apple PR voxpupuli#158
Browse files Browse the repository at this point in the history
  • Loading branch information
ncstate-daniel committed Sep 19, 2023
1 parent 911142e commit f18cb32
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 18 deletions.
4 changes: 4 additions & 0 deletions lib/facter/proxysql_mycnf_file_name.rb
Original file line number Diff line number Diff line change
@@ -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')
14 changes: 10 additions & 4 deletions lib/puppet/provider/proxy_mysql_query_rule/proxysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/proxysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/proxy_cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

ensurable

autorequire(:file) { '/root/.my.cnf' }
autorequire(:class) { 'proxysql::admin_credentials' }
autorequire(:class) { 'mysql::client' }
autorequire(:service) { 'proxysql' }

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/proxy_global_variable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' }

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/proxy_mysql_galera_hostgroup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' }

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/proxy_mysql_group_replication_hostgroup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

ensurable

autorequire(:file) { '/root/.my.cnf' }
autorequire(:class) { 'proxysql::admin_credentials' }
autorequire(:class) { 'mysql::client' }
autorequire(:service) { 'proxysql' }

Expand Down
7 changes: 6 additions & 1 deletion lib/puppet/type/proxy_mysql_query_rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

ensurable

autorequire(:file) { '/root/.my.cnf' }
autorequire(:class) { 'proxysql::admin_credentials' }
autorequire(:class) { 'mysql::client' }
autorequire(:service) { 'proxysql' }

Expand Down Expand Up @@ -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+})
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/proxy_mysql_replication_hostgroup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

ensurable

autorequire(:file) { '/root/.my.cnf' }
autorequire(:class) { 'proxysql::admin_credentials' }
autorequire(:class) { 'mysql::client' }
autorequire(:service) { 'proxysql' }

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/proxy_mysql_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

ensurable

autorequire(:file) { '/root/.my.cnf' }
autorequire(:class) { 'proxysql::admin_credentials' }
autorequire(:class) { 'mysql::client' }
autorequire(:service) { 'proxysql' }

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/proxy_mysql_server_no_hostgroup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

ensurable

autorequire(:file) { '/root/.my.cnf' }
autorequire(:class) { 'proxysql::admin_credentials' }
autorequire(:class) { 'mysql::client' }
autorequire(:service) { 'proxysql' }

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/proxy_mysql_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

ensurable

autorequire(:file) { '/root/.my.cnf' }
autorequire(:class) { 'proxysql::admin_credentials' }
autorequire(:class) { 'mysql::client' }
autorequire(:service) { 'proxysql' }

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/proxy_scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

ensurable

autorequire(:file) { '/root/.my.cnf' }
autorequire(:class) { 'proxysql::admin_credentials' }
autorequire(:class) { 'mysql::client' }
autorequire(:service) { 'proxysql' }

Expand Down
12 changes: 11 additions & 1 deletion manifests/admin_credentials.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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,
}
}
}
2 changes: 1 addition & 1 deletion manifests/reload_config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
2 changes: 1 addition & 1 deletion manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions types/rule.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f18cb32

Please sign in to comment.