-
Notifications
You must be signed in to change notification settings - Fork 22
Expand --nstimes option #421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,15 +1,14 @@ | ||||||||||||||||||||||||||||||||||||||||||
# Brief help module to define the exception we use for early exits. | ||||||||||||||||||||||||||||||||||||||||||
package Zonemaster::Engine::Exception::NormalExit; | ||||||||||||||||||||||||||||||||||||||||||
use 5.014002; | ||||||||||||||||||||||||||||||||||||||||||
use v5.26; | ||||||||||||||||||||||||||||||||||||||||||
use warnings; | ||||||||||||||||||||||||||||||||||||||||||
use parent 'Zonemaster::Engine::Exception'; | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
# The actual interesting module. | ||||||||||||||||||||||||||||||||||||||||||
package Zonemaster::CLI; | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
use 5.014002; | ||||||||||||||||||||||||||||||||||||||||||
use v5.26; | ||||||||||||||||||||||||||||||||||||||||||
marc-vanderwal marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
use strict; | ||||||||||||||||||||||||||||||||||||||||||
use warnings; | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
use version; our $VERSION = version->declare( "v7.2.0" ); | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -643,38 +642,98 @@ sub run { | |||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
if ( $opt_nstimes ) { | ||||||||||||||||||||||||||||||||||||||||||
my $zone = Zonemaster::Engine->zone( $domain ); | ||||||||||||||||||||||||||||||||||||||||||
my $max = max map { length( "$_" ) } ( @{ $zone->ns }, q{Server} ); | ||||||||||||||||||||||||||||||||||||||||||
my %all_nss = %{ Zonemaster::Engine::Nameserver::object_cache }; | ||||||||||||||||||||||||||||||||||||||||||
my @child_nss = @{ $zone->ns }; | ||||||||||||||||||||||||||||||||||||||||||
my @parent_nss = @{ $zone->parent->ns }; | ||||||||||||||||||||||||||||||||||||||||||
my @all_responded_nss; | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
foreach my $ns_name ( keys %all_nss ) { | ||||||||||||||||||||||||||||||||||||||||||
foreach my $ns ( values %{ $all_nss{$ns_name} } ) { | ||||||||||||||||||||||||||||||||||||||||||
push @all_responded_nss, $ns if scalar @{ $ns->times } > 0; | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
my %nss_filter = map { $_ => undef } ( @child_nss, @parent_nss ); | ||||||||||||||||||||||||||||||||||||||||||
my @other_nss = grep { ! exists $nss_filter{$_} } @all_responded_nss; | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
if ( $opt_json ) { | ||||||||||||||||||||||||||||||||||||||||||
my @times = (); | ||||||||||||||||||||||||||||||||||||||||||
foreach my $ns ( @{ $zone->ns } ) { | ||||||||||||||||||||||||||||||||||||||||||
push @times, | ||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||
'ns' => $ns->string, | ||||||||||||||||||||||||||||||||||||||||||
'max' => 1000 * $ns->max_time, | ||||||||||||||||||||||||||||||||||||||||||
'min' => 1000 * $ns->min_time, | ||||||||||||||||||||||||||||||||||||||||||
'avg' => 1000 * $ns->average_time, | ||||||||||||||||||||||||||||||||||||||||||
'stddev' => 1000 * $ns->stddev_time, | ||||||||||||||||||||||||||||||||||||||||||
'median' => 1000 * $ns->median_time, | ||||||||||||||||||||||||||||||||||||||||||
'total' => 1000 * $ns->sum_time | ||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||
my @times; | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
my sub json_nstimes { | ||||||||||||||||||||||||||||||||||||||||||
my ( $ns ) = @_; | ||||||||||||||||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||||||||||||||||
'ns' => $ns->string, | ||||||||||||||||||||||||||||||||||||||||||
'max' => 1000 * $ns->max_time, | ||||||||||||||||||||||||||||||||||||||||||
'min' => 1000 * $ns->min_time, | ||||||||||||||||||||||||||||||||||||||||||
'avg' => 1000 * $ns->average_time, | ||||||||||||||||||||||||||||||||||||||||||
'stddev' => 1000 * $ns->stddev_time, | ||||||||||||||||||||||||||||||||||||||||||
'median' => 1000 * $ns->median_time, | ||||||||||||||||||||||||||||||||||||||||||
'total' => 1000 * $ns->sum_time, | ||||||||||||||||||||||||||||||||||||||||||
'count' => scalar @{ $ns->times } | ||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
my %section_mapping = ( | ||||||||||||||||||||||||||||||||||||||||||
'child' => \@child_nss, | ||||||||||||||||||||||||||||||||||||||||||
'parent' => \@parent_nss, | ||||||||||||||||||||||||||||||||||||||||||
'other' => \@other_nss | ||||||||||||||||||||||||||||||||||||||||||
mattias-p marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
foreach my $section_name ( sort keys %section_mapping ) { | ||||||||||||||||||||||||||||||||||||||||||
my @entries = map { json_nstimes( $_ ) } sort @{ $section_mapping{$section_name} }; | ||||||||||||||||||||||||||||||||||||||||||
push @times, { $section_name => \@entries }; | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
$json_output->{nstimes} = \@times; | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
else { | ||||||||||||||||||||||||||||||||||||||||||
print "\n"; | ||||||||||||||||||||||||||||||||||||||||||
printf "%${max}s %s\n", 'Server', ' Max Min Avg Stddev Median Total'; | ||||||||||||||||||||||||||||||||||||||||||
printf "%${max}s %s\n", '=' x $max, ' ======== ======== ======== ======== ======== ========='; | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
foreach my $ns ( @{ $zone->ns } ) { | ||||||||||||||||||||||||||||||||||||||||||
printf "%${max}s ", $ns->string; | ||||||||||||||||||||||||||||||||||||||||||
printf "%9.2f ", 1000 * $ns->max_time; | ||||||||||||||||||||||||||||||||||||||||||
printf "%8.2f ", 1000 * $ns->min_time; | ||||||||||||||||||||||||||||||||||||||||||
printf "%8.2f ", 1000 * $ns->average_time; | ||||||||||||||||||||||||||||||||||||||||||
printf "%8.2f ", 1000 * $ns->stddev_time; | ||||||||||||||||||||||||||||||||||||||||||
printf "%8.2f ", 1000 * $ns->median_time; | ||||||||||||||||||||||||||||||||||||||||||
printf "%9.2f\n", 1000 * $ns->sum_time; | ||||||||||||||||||||||||||||||||||||||||||
my $header = __( 'Name servers' ); | ||||||||||||||||||||||||||||||||||||||||||
my $max = max map { length( "$_" ) } ( ( @child_nss, @parent_nss, @all_responded_nss ), $header ); | ||||||||||||||||||||||||||||||||||||||||||
printf "\n%${max}s %s\n", $header, ' Max Min Avg Stddev Median Total Count'; | ||||||||||||||||||||||||||||||||||||||||||
printf "%${max}s %s\n", '=' x $max, ' ========== ========== ========== ========== ========== =========== ==========='; | ||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+690
to
+693
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This table’s columns aren’t fully localized and that’s a problem. Also, it's better to write
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The width of each the column is wide enough for the English header name, but in translation the header name might get wider. I guess the solution is to have adaptive column width for all comlumns. Or does the second suggestion take care of that? |
||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
my $total_queries_count = 0; | ||||||||||||||||||||||||||||||||||||||||||
my $total_queries_times = 0; | ||||||||||||||||||||||||||||||||||||||||||
my %nss_already_processed; | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
my sub print_nstimes { | ||||||||||||||||||||||||||||||||||||||||||
my ( $ns, $max, $total_queries_count, $total_queries_times, $nss_already_processed_ref ) = @_; | ||||||||||||||||||||||||||||||||||||||||||
my %nss_already_processed = %{ $nss_already_processed_ref }; | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
printf "%${max}s ", $ns->string; | ||||||||||||||||||||||||||||||||||||||||||
printf "%11.2f ", 1000 * $ns->max_time; | ||||||||||||||||||||||||||||||||||||||||||
printf "%10.2f ", 1000 * $ns->min_time; | ||||||||||||||||||||||||||||||||||||||||||
printf "%10.2f ", 1000 * $ns->average_time; | ||||||||||||||||||||||||||||||||||||||||||
printf "%10.2f ", 1000 * $ns->stddev_time; | ||||||||||||||||||||||||||||||||||||||||||
printf "%10.2f ", 1000 * $ns->median_time; | ||||||||||||||||||||||||||||||||||||||||||
printf "%11.2f ", 1000 * $ns->sum_time; | ||||||||||||||||||||||||||||||||||||||||||
printf "%11d\n", scalar @{ $ns->times }; | ||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+703
to
+710
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks to introducing the And there’s another trick: by using
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
$total_queries_count += scalar @{ $ns->times } unless $nss_already_processed{$ns}; | ||||||||||||||||||||||||||||||||||||||||||
$total_queries_times += ( 1000 * $ns->sum_time ) unless $nss_already_processed{$ns}; | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
return $total_queries_count, $total_queries_times; | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
my %section_mapping = ( | ||||||||||||||||||||||||||||||||||||||||||
1 => { __( 'Child zone' ) => \@child_nss }, | ||||||||||||||||||||||||||||||||||||||||||
2 => { __( 'Parent zone' ) => \@parent_nss }, | ||||||||||||||||||||||||||||||||||||||||||
3 => { __( 'Other' ) => \@other_nss } | ||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
foreach my $section_order ( sort keys %section_mapping ) { | ||||||||||||||||||||||||||||||||||||||||||
foreach my $section_header ( keys % { $section_mapping{$section_order} } ) { | ||||||||||||||||||||||||||||||||||||||||||
printf "%s %s\n", $section_header, '-' x ( ( $max - length $section_header ) - 1 ); | ||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
foreach my $section_nss ( sort @{ $section_mapping{$section_order}{$section_header} } ) { | ||||||||||||||||||||||||||||||||||||||||||
( $total_queries_count, $total_queries_times ) = | ||||||||||||||||||||||||||||||||||||||||||
print_nstimes( $section_nss, $max, $total_queries_count, $total_queries_times, \%nss_already_processed ); | ||||||||||||||||||||||||||||||||||||||||||
$nss_already_processed{$section_nss} = 1; | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
printf "%${max}s %s\n", '=' x $max, ' ========== ========== ========== ========== ========== =========== ==========='; | ||||||||||||||||||||||||||||||||||||||||||
printf "%${max}s %67.2f %11s\n", __( 'Grand total' ), $total_queries_times, $total_queries_count; | ||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't the grand total be included in the JSON output also? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wondered about that too, but decided against it for now. It could be done more easily once I do the refactoring you suggested.
Comment on lines
+735
to
+736
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, using a single source of truth for the column widths:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
} ## end if ( $opt_nstimes ) | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
|
@@ -685,7 +744,7 @@ sub run { | |||||||||||||||||||||||||||||||||||||||||
$json_output->{elapsed} = $last->timestamp; | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
else { | ||||||||||||||||||||||||||||||||||||||||||
printf "Total test run time: %0.1f seconds.\n", $last->timestamp; | ||||||||||||||||||||||||||||||||||||||||||
printf "\nTotal test run time: %0.1f seconds.\n", $last->timestamp; | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that mean that we increase the lowest Perl version of Zonemaster from v5.16 to v5.26?