From 7711a4a694139e938ac59db8b42a77b4b0cec28b Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Tue, 21 Jan 2020 18:29:03 +0100 Subject: [PATCH 1/2] Use Puppet 6.6 evaltrace for progress 9fc5fd3c41acfdd01ffbc6c929d00987691da5d4 disabled the progress bar monkey patch on Puppet 6. Puppet 6.6.0 started to mention the progress when evaluating resources which can be used to update the progress bar. --- lib/kafo/progress_bar.rb | 15 ++++++++- test/kafo/progress_bar_test.rb | 57 ++++++++++++++++++++++------------ 2 files changed, 51 insertions(+), 21 deletions(-) diff --git a/lib/kafo/progress_bar.rb b/lib/kafo/progress_bar.rb index cfe5eacb..48b3dfef 100644 --- a/lib/kafo/progress_bar.rb +++ b/lib/kafo/progress_bar.rb @@ -11,7 +11,7 @@ module Kafo # change more methods like #done_message or #print_error class ProgressBar MONITOR_RESOURCE = %r{\w*MONITOR_RESOURCE ([^\]]+\])} - EVALTRACE_START = %r{/(.+\]): Starting to evaluate the resource} + EVALTRACE_START = %r{/(.+\]): Starting to evaluate the resource( \((\d+) of (\d+)\))?} EVALTRACE_END = %r{/(.+\]): Evaluated in [\d\.]+ seconds} PREFETCH = %r{Prefetching .* resources for} @@ -42,6 +42,19 @@ def update(line) end if (line_start = EVALTRACE_START.match(line)) + if line_start[4] + # Puppet 6.6 introduced progress in evaltrace + # Puppet counts 1-based where we count 0-based here + new_lines = line_start[3].to_i - 1 + new_total = line_start[4].to_i + if new_lines != @lines || @total != new_total + @lines = new_lines + @total = new_total + update_bar = true + force_update = true + end + end + if (known_resource = find_known_resource(line_start[1])) line = known_resource update_bar = true diff --git a/test/kafo/progress_bar_test.rb b/test/kafo/progress_bar_test.rb index 2239a42c..cb2fae99 100644 --- a/test/kafo/progress_bar_test.rb +++ b/test/kafo/progress_bar_test.rb @@ -5,30 +5,47 @@ module Kafo let(:bar) { ProgressBar.new.tap { |pb| pb.instance_variable_set(:@bar, powerbar) } } let(:powerbar) { MiniTest::Mock.new } - it "calls powerbar.show" do - powerbar.expect(:show, nil, [{:msg => 'Notify[test] ', :done => 0, :total => 2}, true]) - powerbar.expect(:show, nil, [{:msg => 'Prefetching example resources for example_type ', :done => 1, :total => 2}, true]) - powerbar.expect(:show, nil, [{:msg => 'File[/foo/bar] ', :done => 1, :total => 2}, true]) + describe 'Puppet 5' do + it "calls powerbar.show" do + powerbar.expect(:show, nil, [{:msg => 'Notify[test] ', :done => 0, :total => 2}, true]) + powerbar.expect(:show, nil, [{:msg => 'Prefetching example resources for example_type ', :done => 1, :total => 2}, true]) + powerbar.expect(:show, nil, [{:msg => 'File[/foo/bar] ', :done => 1, :total => 2}, true]) - bar.update('MONITOR_RESOURCE File[/foo/bar]') - bar.update('MONITOR_RESOURCE Notify[test]') - bar.update('/Stage[main]/Example/Notify[test]: Starting to evaluate the resource') - bar.update('/Stage[main]/Example/Notify[test]: Evaluated in 0.5 seconds') - bar.update('Prefetching example resources for example_type') - bar.update('/Stage[main]/Example/File[/foo/bar]: Starting to evaluate the resource') - bar.update('/Stage[main]/Example/File[/foo/bar]: Evaluated in 0.5 seconds') - powerbar.verify + bar.update('MONITOR_RESOURCE File[/foo/bar]') + bar.update('MONITOR_RESOURCE Notify[test]') + bar.update('/Stage[main]/Example/Notify[test]: Starting to evaluate the resource') + bar.update('/Stage[main]/Example/Notify[test]: Evaluated in 0.5 seconds') + bar.update('Prefetching example resources for example_type') + bar.update('/Stage[main]/Example/File[/foo/bar]: Starting to evaluate the resource') + bar.update('/Stage[main]/Example/File[/foo/bar]: Evaluated in 0.5 seconds') + powerbar.verify + end + + it 'handles an unknown total' do + powerbar.expect(:show, nil, [{:msg => 'Prefetching example resources for example_type ', :done => 0, :total => :unknown}, true]) + + bar.update('/Stage[main]/Example/Notify[test]: Starting to evaluate the resource') + bar.update('/Stage[main]/Example/Notify[test]: Evaluated in 0.5 seconds') + bar.update('Prefetching example resources for example_type') + bar.update('/Stage[main]/Example/File[/foo/bar]: Starting to evaluate the resource') + bar.update('/Stage[main]/Example/File[/foo/bar]: Evaluated in 0.5 seconds') + powerbar.verify + end end - it 'handles an unknown total' do - powerbar.expect(:show, nil, [{:msg => 'Prefetching example resources for example_type ', :done => 0, :total => :unknown}, true]) + describe 'Puppet 6' do + it "calls powerbar.show" do + powerbar.expect(:show, nil, [{:msg => 'Notify[test] ', :done => 0, :total => 2}, true]) + powerbar.expect(:show, nil, [{:msg => 'Prefetching example resources for example_type ', :done => 1, :total => 2}, true]) + powerbar.expect(:show, nil, [{:msg => 'File[/foo/bar] ', :done => 1, :total => 2}, true]) - bar.update('/Stage[main]/Example/Notify[test]: Starting to evaluate the resource') - bar.update('/Stage[main]/Example/Notify[test]: Evaluated in 0.5 seconds') - bar.update('Prefetching example resources for example_type') - bar.update('/Stage[main]/Example/File[/foo/bar]: Starting to evaluate the resource') - bar.update('/Stage[main]/Example/File[/foo/bar]: Evaluated in 0.5 seconds') - powerbar.verify + bar.update('/Stage[main]/Example/Notify[test]: Starting to evaluate the resource (1 of 2)') + bar.update('/Stage[main]/Example/Notify[test]: Evaluated in 0.5 seconds') + bar.update('Prefetching example resources for example_type') + bar.update('/Stage[main]/Example/File[/foo/bar]: Starting to evaluate the resource (2 of 2)') + bar.update('/Stage[main]/Example/File[/foo/bar]: Evaluated in 0.5 seconds') + powerbar.verify + end end end end From f88b0f602847796f529b844af45005a29d3c1c8e Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Fri, 28 Aug 2020 17:57:51 +0200 Subject: [PATCH 2/2] WIP --- lib/kafo/progress_bar.rb | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/lib/kafo/progress_bar.rb b/lib/kafo/progress_bar.rb index 48b3dfef..2e7fff09 100644 --- a/lib/kafo/progress_bar.rb +++ b/lib/kafo/progress_bar.rb @@ -11,7 +11,7 @@ module Kafo # change more methods like #done_message or #print_error class ProgressBar MONITOR_RESOURCE = %r{\w*MONITOR_RESOURCE ([^\]]+\])} - EVALTRACE_START = %r{/(.+\]): Starting to evaluate the resource( \((\d+) of (\d+)\))?} + EVALTRACE_START = %r{/(?.+\]): Starting to evaluate the resource( \((?\d+) of (?\d+)\))?} EVALTRACE_END = %r{/(.+\]): Evaluated in [\d\.]+ seconds} PREFETCH = %r{Prefetching .* resources for} @@ -37,39 +37,40 @@ def update(line) force_update = false if (line_monitor = MONITOR_RESOURCE.match(line)) + # In Puppet < 6 Kafo's custom progress bar hooks into internals and + # prints a MONITOR_RESOURCE line. This gives a total. @resources << line_monitor[1] @total = (@total == :unknown ? 1 : @total + 1) - end + elsif (line_start = EVALTRACE_START.match(line)) + if line_start[:total] + # Puppet 6.6 introduced progress in evaltrace. There is no complete + # set prior to evaluation, so the set it built as evaluation is + # progressing. + line = line_start[:resource] + @resources << line + update_bar = true + force_update = true - if (line_start = EVALTRACE_START.match(line)) - if line_start[4] - # Puppet 6.6 introduced progress in evaltrace - # Puppet counts 1-based where we count 0-based here - new_lines = line_start[3].to_i - 1 - new_total = line_start[4].to_i + # Puppet counts 1-based where Kafo counts 0-based here + new_lines = line_start[:number].to_i - 1 + new_total = line_start[:total].to_i if new_lines != @lines || @total != new_total @lines = new_lines @total = new_total - update_bar = true - force_update = true end - end - - if (known_resource = find_known_resource(line_start[1])) + elsif (known_resource = find_known_resource(line_start[1])) + # In Puppet < 6 we have a complete set of all resources prior to + # evaluation line = known_resource update_bar = true force_update = true end - end - - if (line_end = EVALTRACE_END.match(line)) && @total != :unknown && @lines < @total + elsif (line_end = EVALTRACE_END.match(line)) && @total != :unknown && @lines < @total if (known_resource = find_known_resource(line_end[1])) @resources.delete(known_resource) # ensure it's only counted once @lines += 1 end - end - - if PREFETCH =~ line + elsif PREFETCH =~ line update_bar = true force_update = true end