Skip to content

Commit

Permalink
Add more logs into the product sync duration (#25799)
Browse files Browse the repository at this point in the history
* Add more logs into the product sync duration

* Fix channel_name log into the product sync duration

* Fix channel_name log into the product sync duration
  • Loading branch information
srbarrios committed Nov 14, 2024
1 parent 550637b commit 94789b0
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions testsuite/features/support/system_monitoring.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def last_onboarding_duration(host)
onboarding_events = events.select { |event| event['summary'].include? 'certs, channels, packages' }
last_event_id = onboarding_events.last['id']
event_details = $api_test.system.get_event_details(system_id, last_event_id)
Time.parse(event_details['completed']) - Time.parse(event_details['picked_up'])
# Convert XMLRPC::DateTime to Ruby's Time if necessary
completed_time = event_details['completed'].is_a?(XMLRPC::DateTime) ? event_details['completed'].to_time : Time.parse(event_details['completed'])
picked_up_time = event_details['picked_up'].is_a?(XMLRPC::DateTime) ? event_details['picked_up'].to_time : Time.parse(event_details['picked_up'])
Expand All @@ -46,33 +45,36 @@ def last_onboarding_duration(host)
# @param os_product_version [String] the product name
# @return [Integer] the duration in seconds
def product_synchronization_duration(os_product_version)
channels_to_wait = CHANNEL_TO_SYNC_BY_OS_PRODUCT_VERSION.dig(product, os_product_version)
channels_to_wait = filter_channels(channels_to_wait, ['beta']) unless $beta_enabled
raise ScriptError, "Synchronization error, channels for #{os_product_version} in #{product} not found" if channels_to_wait.nil?
channels_to_evaluate = CHANNEL_TO_SYNC_BY_OS_PRODUCT_VERSION.dig(product, os_product_version)
channels_to_evaluate = filter_channels(channels_to_evaluate, ['beta']) unless $beta_enabled
$stdout.puts("Channels to evaluate:\n#{channels_to_evaluate}")
raise ScriptError, "Synchronization error, channels for #{os_product_version} in #{product} not found" if channels_to_evaluate.nil?

get_target('server').extract('/var/log/rhn/reposync.log', '/tmp/reposync.log')
raise ScriptError, 'The file with repository synchronization logs doesn\'t exist or is empty' if !File.exist?('/tmp/reposync.log') || File.empty?('/tmp/reposync.log')

duration = 0
channel_to_evaluate = false
matches = 0
channel_name = ''
log_content = File.readlines('/tmp/reposync.log')
$stdout.puts("Content of reposync.log:\n#{log_content.join}")
log_content.each do |line|
if line.include?('Channel: ')
channel_name = line.split('Channel: ')[1].strip
channel_to_evaluate = channels_to_wait.include?(channel_name)
end
if line.include?('Total time: ') && channel_to_evaluate
match = line.match(/Total time: (\d+):(\d+):(\d+)/)
hours, minutes, seconds = match.captures.map(&:to_i)
total_seconds = (hours * 3600) + (minutes * 60) + seconds
duration += total_seconds
matches += 1
channel_to_evaluate = false
channel_to_evaluate = channels_to_evaluate.include?(channel_name)
end
next unless line.include?('Total time: ') && channel_to_evaluate

match = line.match(/Total time: (\d+):(\d+):(\d+)/)
hours, minutes, seconds = match.captures.map(&:to_i)
total_seconds = (hours * 3600) + (minutes * 60) + seconds
$stdout.puts("Channel #{channel_name} synchronization duration: #{total_seconds} seconds")
duration += total_seconds
matches += 1
channel_to_evaluate = false
end
$stdout.puts("Error extracting the synchronization duration of #{os_product_version}") if matches < channels_to_wait.size
$stdout.puts("Error extracting the synchronization duration of #{os_product_version}") if matches < channels_to_evaluate.size
duration
end

Expand Down Expand Up @@ -108,3 +110,4 @@ def channel_synchronization_duration(channel)

duration
end

0 comments on commit 94789b0

Please sign in to comment.