Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to set separate interval for database resource #945

Merged
merged 4 commits into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions manifests/plugin/dbi/database.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
#
define collectd::plugin::dbi::database (
String $driver,
String $ensure = 'present',
Optional[String] $host = undef,
String $databasename = $name,
Hash $driveroption = {},
Optional[String] $selectdb = undef,
Array $query = [],
String $ensure = 'present',
Optional[String] $host = undef,
String $databasename = $name,
Hash $driveroption = {},
Optional[String] $selectdb = undef,
Array $query = [],
Optional[Integer[1]] $db_query_interval = undef,
) {

include collectd
Expand Down
48 changes: 48 additions & 0 deletions spec/classes/collectd_plugin_dbi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,54 @@
it "Will create #{options[:plugin_conf_dir]}/dbi-config.conf" do
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_db_mydatabase').with(content: %r{Driver \"mysql\"\n})
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_db_mydatabase').with(content: %r{Host \"localhost\"\n})
is_expected.not_to contain_concat__fragment('collectd_plugin_dbi_conf_db_mydatabase').with(content: %r{Interval})
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_db_mydatabase').with(content: %r{Query \"disk_io\"\n})
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_db_mydatabase').with(content: %r{DriverOption \"host\" \"db\.example\.com\"\n})
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_db_mydatabase').with(content: %r{DriverOption \"username\" \"dbuser\"\n})
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_db_mydatabase').with(content: %r{DriverOption \"password\" \"dbpasswd\"\n})

is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_query_log_delay').with(content: %r{Statement \"SELECT \* FROM log_delay_repli;\"\n})
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_query_log_delay').with(content: %r{<Result>\n})
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_query_log_delay').with(content: %r{InstancesFrom \"inet_server_port\" \"inet_server_host\"\n})
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_query_log_delay').with(content: %r{ValuesFrom \"log_delay\"\n})
end
end

context ':ensure => present and create a db with a query and certain interval' do
let(:params) do
{
databases: {
'mydatabase' => {
'host' => 'localhost',
'driver' => 'mysql',
'db_query_interval' => 60,
'driveroption' => {
'host' => 'db.example.com',
'username' => 'dbuser',
'password' => 'dbpasswd'
},
'selectdb' => 'db',
'query' => %w[disk_io log_delay]
}
},
queries: {
'log_delay' => {
'statement' => 'SELECT * FROM log_delay_repli;',
'results' => [{
'type' => 'gauge',
'instanceprefix' => 'log_delay',
'instancesfrom' => %w[inet_server_port inet_server_host],
'valuesfrom' => 'log_delay'
}]
}
}
}
end

it "Will create #{options[:plugin_conf_dir]}/dbi-config.conf with Interval" do
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_db_mydatabase').with(content: %r{Driver \"mysql\"\n})
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_db_mydatabase').with(content: %r{Host \"localhost\"\n})
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_db_mydatabase').with(content: %r{Interval 60\n})
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_db_mydatabase').with(content: %r{Query \"disk_io\"\n})
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_db_mydatabase').with(content: %r{DriverOption \"host\" \"db\.example\.com\"\n})
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_db_mydatabase').with(content: %r{DriverOption \"username\" \"dbuser\"\n})
Expand Down
3 changes: 3 additions & 0 deletions templates/plugin/dbi/database.conf.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<Database "<%= @databasename %>">
Driver "<%= @driver %>"
<% if @db_query_interval -%>
Interval <%= @db_query_interval %>
<% end -%>
<% @driveroption.each do |key, value| -%>
DriverOption "<%= key %>" "<%= value %>"
<% end -%>
Expand Down