From 7f70a230486c6666a36e76947ab8e0e70228188a Mon Sep 17 00:00:00 2001 From: Steve Schnepp Date: Thu, 6 Jun 2019 20:38:40 +0200 Subject: [PATCH 1/6] t: Add Test::Differences --- contrib/munin-node-debug | 4 ++-- lib/Munin/Common/Config.pm | 22 ------------------ lib/Munin/Common/Logger.pm | 2 +- lib/Munin/Master/Host.pm | 37 ------------------------------ t/munin_master_update.t | 1 + t/munin_master_update_spoolfetch.t | 1 + t/munin_master_update_worker.t | 2 ++ 7 files changed, 7 insertions(+), 62 deletions(-) diff --git a/contrib/munin-node-debug b/contrib/munin-node-debug index ccfbd84fd4..0d751e09bd 100755 --- a/contrib/munin-node-debug +++ b/contrib/munin-node-debug @@ -194,8 +194,7 @@ sub service $graph_data_size = "normal" if $plugin_number % 5 == 1; $graph_data_size = "huge" if $plugin_number % 5 == 2; $graph_data_size = "custom 10,5 10,10 10" if $plugin_number % 5 == 3; - $graph_data_size = "custom 10,5 for 10, 100s for 10d" if $plugin_number % 5 == 4; - print $client "graph_data_size $graph_data_size\n" if $graph_data_size; + $graph_data_size = "custom 10,5 for 10, 5m for 10d" if $plugin_number % 5 == 4; for (my $i = 0; $i < $fields_per_plugin; $i ++) { my $ds = get_ds($plugin_number, $i); my $ds_info = get_ds_info($plugin_number, $i); @@ -207,6 +206,7 @@ sub service /; my $plugin_type = $PLUGIN_TYPES[($i + $plugin_number) % 3]; + print $client "$ds.graph_data_size $graph_data_size\n" if $graph_data_size; print $client "$ds.type $plugin_type\n"; } print $client ".\n"; diff --git a/lib/Munin/Common/Config.pm b/lib/Munin/Common/Config.pm index 65e0118072..33ecbc8e6b 100644 --- a/lib/Munin/Common/Config.pm +++ b/lib/Munin/Common/Config.pm @@ -150,14 +150,6 @@ my %legal = map { $_ => 1 } qw( my %bools = map { $_ => 1} qw(yes no true false on off 1 0); -sub cl_is_keyword { - # Class-less version of is_keyword for legacy code. - my ($word) = @_; - - return defined $legal{$word}; -} - - sub is_keyword { my ($self, $word) = @_; @@ -259,17 +251,3 @@ Returns true if $keyword is a valid configuration keyword. Returns false if $keyword is not a valid configuration keyword. =back - -=head1 FUNCTIONS - -=over - -=item cl_is_keyword ($keyword) - -A "classless" version of B. - -Returns true if $keyword is a valid configuration keyword. - -Returns false if $keyword is not a valid configuration keyword. - -=back diff --git a/lib/Munin/Common/Logger.pm b/lib/Munin/Common/Logger.pm index 2ff0ce5e0f..352f8bd922 100644 --- a/lib/Munin/Common/Logger.pm +++ b/lib/Munin/Common/Logger.pm @@ -43,7 +43,7 @@ my $screen_format = sub { my $level = $args{level}; my $message = $args{message}; - $message = _remove_label($message); + $message = _remove_label($message) if $message =~ /^\[(DEBUG|INFO|NOTICE|WARNING|ERROR)\][\s:]*/; chomp $message; diff --git a/lib/Munin/Master/Host.pm b/lib/Munin/Master/Host.pm index 00ecd746f4..1c6c20480b 100644 --- a/lib/Munin/Master/Host.pm +++ b/lib/Munin/Master/Host.pm @@ -50,32 +50,6 @@ sub get_full_path { return join(";",@groups); } - -sub add_attributes_if_not_exists { - my ($self, $attributes) = @_; - - %$self = (%$attributes, %$self); -} - - -sub get_canned_ds_config { - my ($self, $service, $data_source) = @_; - - # XXX: Could this be done in some sane way? - - my %ds_config; - my $svc_ds_prefix = "$service.$data_source."; - - for my $svc_ds_prop (keys %$self) { - if (index($svc_ds_prop, $svc_ds_prefix) == 0) { - my $prop = substr($svc_ds_prop, length($svc_ds_prefix)); - $ds_config{$prop} = $self->{$svc_ds_prop}; - } - } - - return \%ds_config; -} - 1; @@ -108,16 +82,5 @@ c. Returns the full nested named path of the host object (eg. "group1;group2;hostname"). -=item B - - $host->add_attributes_if_not_exists(\%attrs); - -Merges the new attributes from %attrs into the host object, without -overwriting any existing attributes. - -=item B - -FIX - =back diff --git a/t/munin_master_update.t b/t/munin_master_update.t index 89f1e8f40c..b620baa374 100644 --- a/t/munin_master_update.t +++ b/t/munin_master_update.t @@ -5,6 +5,7 @@ use lib qw(t/lib); use Test::More; +use Test::Differences; require_ok( 'Munin::Master::Update' ); require_ok( 'Munin::Master::Config' ); diff --git a/t/munin_master_update_spoolfetch.t b/t/munin_master_update_spoolfetch.t index 9f73d74838..6bd5ffc693 100644 --- a/t/munin_master_update_spoolfetch.t +++ b/t/munin_master_update_spoolfetch.t @@ -5,6 +5,7 @@ use lib qw(t/lib); use Test::More; +use Test::Differences; require_ok( 'Munin::Master::Update' ); require_ok( 'Munin::Master::Config' ); diff --git a/t/munin_master_update_worker.t b/t/munin_master_update_worker.t index a50f52562a..a37e73cd26 100644 --- a/t/munin_master_update_worker.t +++ b/t/munin_master_update_worker.t @@ -5,6 +5,8 @@ use lib qw(t/lib); use Test::More; +use Test::Differences; + use Munin::Master::UpdateWorker; # parse_update_rate From 09f5524dff1b915108e0f51aef908983413e3ca8 Mon Sep 17 00:00:00 2001 From: Steve Schnepp Date: Thu, 6 Jun 2019 23:51:55 +0200 Subject: [PATCH 2/6] u: fixed whitspace --- lib/Munin/Master/Update.pm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Munin/Master/Update.pm b/lib/Munin/Master/Update.pm index dc67bf67bb..b265020811 100644 --- a/lib/Munin/Master/Update.pm +++ b/lib/Munin/Master/Update.pm @@ -78,8 +78,7 @@ sub get_dbh { $dbh->{RaiseError} = 1; use Carp; $dbh->{HandleError} = sub { confess(shift) }; - } - + } # Plainly returns it, but do *not* put it in $self, as it will let Perl # do its GC properly and closing it when out of scope. From a720a05bb6667ddaca26e9652d71b19b72d71834 Mon Sep 17 00:00:00 2001 From: Steve Schnepp Date: Thu, 6 Jun 2019 23:52:30 +0200 Subject: [PATCH 3/6] u: add some db specific session vars --- lib/Munin/Master/Update.pm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Munin/Master/Update.pm b/lib/Munin/Master/Update.pm index b265020811..77bc9944f6 100644 --- a/lib/Munin/Master/Update.pm +++ b/lib/Munin/Master/Update.pm @@ -234,9 +234,12 @@ sub _db_init { my $db_driver = $ENV{MUNIN_DBDRIVER} || "$config->{dbdriver}"; $db_serial_type = "SERIAL" if $db_driver eq "Pg"; - # Create DB - $dbh->begin_work(); + # Sets some session vars + $dbh->do("PRAGMA journal_mode=WAL;") if $db_driver eq "SQLite"; $dbh->do("SET LOCAL client_min_messages = error") if $db_driver eq "Pg"; + + # Initialize DB Schema + $dbh->begin_work(); $dbh->do("CREATE TABLE IF NOT EXISTS param (name VARCHAR PRIMARY KEY, value VARCHAR)"); $dbh->do("CREATE TABLE IF NOT EXISTS grp (id $db_serial_type PRIMARY KEY, p_id INTEGER REFERENCES grp(id), name VARCHAR, path VARCHAR)"); $dbh->do("CREATE UNIQUE INDEX IF NOT EXISTS r_g_grp ON grp (p_id, name)"); From 826d81b4ac4fba0141313437d68cf57eda9bb664 Mon Sep 17 00:00:00 2001 From: Steve Schnepp Date: Fri, 7 Jun 2019 00:52:30 +0200 Subject: [PATCH 4/6] u: ignore when mutiplier is "0" --- lib/Munin/Master/UpdateWorker.pm | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/Munin/Master/UpdateWorker.pm b/lib/Munin/Master/UpdateWorker.pm index c2ea0ccaf2..001da6af2b 100644 --- a/lib/Munin/Master/UpdateWorker.pm +++ b/lib/Munin/Master/UpdateWorker.pm @@ -932,6 +932,14 @@ sub parse_custom_resolution { my $multiplier = int ($nb_sec / $update_rate); my $multiplier_nb = int ($for_sec / $nb_sec); + # Log & ignore if having a 0 + unless ($multiplier && $multiplier_nb) { + ERROR "$elem" + . " -> nb_sec:$nb_sec, for_sec:$for_sec" + . " -> multiplier:$multiplier, multiplier_nb:$multiplier_nb"; + next; + } + DEBUG "[DEBUG] $elem" . " -> nb_sec:$nb_sec, for_sec:$for_sec" . " -> multiplier:$multiplier, multiplier_nb:$multiplier_nb" From 855648e947f44e3ebafc7dd2ce4f4c20452e6925 Mon Sep 17 00:00:00 2001 From: Steve Schnepp Date: Fri, 7 Jun 2019 01:13:53 +0200 Subject: [PATCH 5/6] u: Fixed mixed return args in is_fresh_enough() --- lib/Munin/Master/UpdateWorker.pm | 2 +- t/munin_master_update.t | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Munin/Master/UpdateWorker.pm b/lib/Munin/Master/UpdateWorker.pm index 001da6af2b..7254abc07d 100644 --- a/lib/Munin/Master/UpdateWorker.pm +++ b/lib/Munin/Master/UpdateWorker.pm @@ -513,7 +513,7 @@ sub is_fresh_enough { DEBUG "is_fresh_enough($update_rate, $last_timestamp, $now)"; - my ($is_update_aligned, $update_rate_in_sec) = parse_update_rate($update_rate); + my ($update_rate_in_sec, $is_update_aligned) = parse_update_rate($update_rate); DEBUG "update_rate_in_sec:$update_rate_in_sec"; diff --git a/t/munin_master_update.t b/t/munin_master_update.t index b620baa374..edefc3c7f5 100644 --- a/t/munin_master_update.t +++ b/t/munin_master_update.t @@ -41,6 +41,10 @@ ok($update->run() == 5); kill('TERM', $pid_debug_node); wait(); +# cleanup the update dir +system("rm", "-Rvf", $config->{dbdir}); + + done_testing(); 1; From 457bb6b89d9095b4741f72ddb4399a9e9f6f9ecd Mon Sep 17 00:00:00 2001 From: Steve Schnepp Date: Fri, 7 Jun 2019 22:11:14 +0200 Subject: [PATCH 6/6] u: Adding progress log for spoolfetching & arg0 --- lib/Munin/Master/UpdateWorker.pm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/Munin/Master/UpdateWorker.pm b/lib/Munin/Master/UpdateWorker.pm index 7254abc07d..9b05b744e8 100644 --- a/lib/Munin/Master/UpdateWorker.pm +++ b/lib/Munin/Master/UpdateWorker.pm @@ -116,7 +116,12 @@ sub do_work { # updates, as we don't want to slurp the whole spoolfetched output # and process it later. It will surely timeout, and use a truckload # of RSS. - my $timestamp = $node->spoolfetch($spoolfetch_last_timestamp, sub { $self->uw_handle_config( @_ ); } ); + my $timestamp = $node->spoolfetch($spoolfetch_last_timestamp, sub { + my ($plugin, $now, $data, $last_timestamp, $update_rate_ptr) = @_; + INFO "spoolfetch config ($plugin, $now)"; + local $0 = "$0 t($now) c($plugin)"; + $self->uw_handle_config( @_ ); + } ); # update the timestamp if we spoolfetched something $self->set_spoolfetch_timestamp($timestamp) if $timestamp;