github.com/redhat-appstudio/e2e-tests@v0.0.0-20240520140907-9709f6f59323/tests/load-tests/ci-scripts/utility_scripts/measure-time-skew.sh (about) 1 #!/bin/bash 2 3 # Initialize sums 4 sum_rtt=0 5 sum_skew=0 6 7 for i in {1..3}; do 8 # Step 1: Measure RTT in nanoseconds and calculate in seconds with fractional part 9 start=$(date +%s%N) # Start time in nanoseconds 10 oc exec prometheus-k8s-0 -n openshift-monitoring -- date -u +"%Y-%m-%dT%H:%M:%S%z" > /dev/null 11 end=$(date +%s%N) # End time in nanoseconds 12 13 # Calculate round-trip time in seconds with fractions 14 rtt=$(echo "scale=3; ($end - $start) / 1000000000" | bc) # Round to three decimal places 15 sum_rtt=$(echo "$sum_rtt + $rtt" | bc) 16 17 # Step 2: Get remote time and local time, one after the other 18 remote_time=$(oc exec prometheus-k8s-0 -n openshift-monitoring -- date -u +"%Y-%m-%dT%H:%M:%S.%N%z") 19 local_time=$(date -u +"%Y-%m-%dT%H:%M:%S.%N%z") 20 21 remote_time_epoch=$(date -ud "$remote_time" +"%s.%3N") # Truncate to milliseconds 22 local_time_epoch=$(date -ud "$local_time" +"%s.%3N") # Truncate to milliseconds 23 24 # Adjust for half of the round-trip time 25 latency_correction=$(echo "scale=3; $rtt / 2" | bc) # Round to three decimal places 26 remote_time_corrected_epoch=$(echo "scale=3; $remote_time_epoch - $latency_correction" | bc) # Round to three decimal places 27 28 29 # Step 3: Calculate skew with fractional part 30 time_skew=$(echo "scale=3; $local_time_epoch - $remote_time_corrected_epoch" | bc) # Round to three decimal places 31 sum_skew=$(echo "$sum_skew + $time_skew" | bc) 32 33 # Optional: Output each measurement 34 # echo "Measurement $i: RTT = $rtt seconds, Time Skew = $time_skew seconds" 35 done 36 37 # Calculate averages 38 avg_rtt=$(echo "scale=3; $sum_rtt / 3" | bc) 39 avg_skew=$(echo "scale=3; $sum_skew / 3" | bc) 40 41 # Output the averages 42 echo "Average RTT: $avg_rtt seconds" 43 echo "Average Time Skew: $avg_skew seconds"