#!/usr/bin/env ruby # Verify recovery relative to the actual kubectl action, using only non-secret workload events. require 'json' directory, run = ARGV result = File.readlines("#{directory}/load-#{run}.txt").map do |line| match = line.match(/\bmsg=("(?:\\.|[^"])*")/) next unless match message = JSON.parse(match[1]) next unless message.start_with?('{') JSON.parse(message) end.compact.find { |item| item['pass'] } abort 'Missing successful failover report' unless result stopped = Float(File.read("#{directory}/#{run}-stop-epoch.txt")) relative_stop = stopped - result.fetch('started_epoch_ms') / 1000.0 event = result.fetch('events').find { |item| item['seconds'] >= relative_stop && item['instance'] != result['target'] } abort 'No recovered write' unless event recovery = event['seconds'] - relative_stop abort "Recovery exceeded 10 seconds: #{recovery}" unless recovery <= 10 summary = result.reject { |key, _| key == 'events' }.merge('recovery_seconds' => recovery.round(3), 'confirmed_rps' => (result['confirmed'] - 1) / 25.0) File.write("#{directory}/#{run}-summary.json", JSON.pretty_generate(summary)+"\n") puts JSON.generate(summary)