From 772c3b9c168de752200ebfd86b96179fe3bcdd3f Mon Sep 17 00:00:00 2001 From: Mike Tillberg Date: Sun, 2 Jul 2023 15:32:14 -0400 Subject: [PATCH 1/3] uw: for case where field in fetch but not config Better handling when a plugin has a field in fetch that wasn't in config. This specifically prevents inserting id=null rows into the state table. Note: Munin 2.0 would display these fields with a "No .label provided" label and default drawing rules. These are now dropped. --- lib/Munin/Master/UpdateWorker.pm | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/Munin/Master/UpdateWorker.pm b/lib/Munin/Master/UpdateWorker.pm index d9d7d70fd..5fd4de98e 100644 --- a/lib/Munin/Master/UpdateWorker.pm +++ b/lib/Munin/Master/UpdateWorker.pm @@ -512,6 +512,13 @@ sub _db_state_update { WHERE ds.name = '$field'" unless $ds_id; $sth_ds->finish(); + # Don't insert missing ds values + # Note, this means unconfigured ds values are lost, rather than + # kept with some default ds_attr values + if (!defined($ds_id)) { + return $ds_id; + } + # Update the state with the new values my $sth_state_u = $dbh->prepare_cached("UPDATE state SET prev_epoch = last_epoch, prev_value = last_value, last_epoch = ?, last_value = ? WHERE id = ? AND type = ?"); my $rows_u = $sth_state_u->execute($when, $value, $ds_id, "ds"); @@ -758,6 +765,11 @@ sub uw_handle_fetch { my $ds_id = $self->_db_state_update($plugin, $field, $when, $value); DEBUG "[DEBUG] ds_id($plugin, $field, $when, $value) = $ds_id"; + # Missing ds config means undef ds_id, already warned + if (!$ds_id) { + next; + } + my ($rrd_file, $rrd_field); { # XXX - Quite inefficient, but works From 33c1fda086a3ab6d59f97bd20440ed1e5f455588 Mon Sep 17 00:00:00 2001 From: Mike Tillberg Date: Sun, 2 Jul 2023 15:32:14 -0400 Subject: [PATCH 2/3] uw: avoid undef warning in DEBUG --- lib/Munin/Master/UpdateWorker.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Munin/Master/UpdateWorker.pm b/lib/Munin/Master/UpdateWorker.pm index 5fd4de98e..f4e21c3d1 100644 --- a/lib/Munin/Master/UpdateWorker.pm +++ b/lib/Munin/Master/UpdateWorker.pm @@ -506,7 +506,7 @@ sub _db_state_update { WHERE ds.name = ?"); $sth_ds->execute($node_id, $plugin, $field); my ($ds_id) = $sth_ds->fetchrow_array(); - DEBUG "_db_state_update.ds_id:$ds_id"; + DEBUG "_db_state_update.ds_id:" . ($ds_id || 'undef'); WARN "ds_id($plugin, $field, $when, $value) is NULL, SELECT ds.id FROM ds JOIN service s ON ds.service_id = s.id AND s.node_id = '$node_id' AND s.name = '$plugin' WHERE ds.name = '$field'" unless $ds_id; @@ -763,7 +763,7 @@ sub uw_handle_fetch { # Update all data-driven components: State, RRD, Graphite my $ds_id = $self->_db_state_update($plugin, $field, $when, $value); - DEBUG "[DEBUG] ds_id($plugin, $field, $when, $value) = $ds_id"; + DEBUG "[DEBUG] ds_id($plugin, $field, $when, $value) = " . ($ds_id || 'undef'); # Missing ds config means undef ds_id, already warned if (!$ds_id) { From 5f4d8ee3083aa39636569bfe9585613f254a00f0 Mon Sep 17 00:00:00 2001 From: Mike Tillberg Date: Mon, 3 Jul 2023 19:31:20 -0400 Subject: [PATCH 3/3] Create rrd file during fetch for unconfigured fields --- lib/Munin/Master/UpdateWorker.pm | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/Munin/Master/UpdateWorker.pm b/lib/Munin/Master/UpdateWorker.pm index f4e21c3d1..6efb46c1f 100644 --- a/lib/Munin/Master/UpdateWorker.pm +++ b/lib/Munin/Master/UpdateWorker.pm @@ -765,13 +765,8 @@ sub uw_handle_fetch { my $ds_id = $self->_db_state_update($plugin, $field, $when, $value); DEBUG "[DEBUG] ds_id($plugin, $field, $when, $value) = " . ($ds_id || 'undef'); - # Missing ds config means undef ds_id, already warned - if (!$ds_id) { - next; - } - my ($rrd_file, $rrd_field); - { + if ($ds_id) { # XXX - Quite inefficient, but works my $dbh = $self->{dbh}; my $sth_rrdinfos = $dbh->prepare_cached( @@ -786,6 +781,23 @@ sub uw_handle_fetch { $rrd_field = $row[1] if $row[0] eq "rrd:field"; } $sth_rrdinfos->finish(); + } else { + # We have an unconfigured fetch value, make sure + # to store the data + + # Need to have the service attrs, currently just for + # a potential update_rate value. + my $dbh = $self->{dbh}; + my $sth_service_attrs = $dbh->prepare_cached("SELECT service_attr.name, service_attr.value FROM service_attr, service WHERE service.name=? and service.node_id=? and service.id = service_attr.id"); + $sth_service_attrs->execute($plugin, $self->{node_id}); + my %temp_ds_config = ( ); + while (my ($_name, $_value) = $sth_service_attrs->fetchrow_array()) { + $temp_ds_config{$_name} = $_value; + } + + my $first_epoch = time - (12 * 3600); + $rrd_file = $self->_create_rrd_file_if_needed($plugin, $field, \%temp_ds_config, $first_epoch); + $rrd_field = '42'; } # This is a little convoluted but is needed as the API permits