diff options
author | Dylan William Hardison <dylan@hardison.net> | 2018-06-29 05:26:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-29 05:26:52 +0200 |
commit | d5f2d8158b90a55cefe126e38132e390e9fa75f5 (patch) | |
tree | 8d31e608d7bf81d919fc4b8240508a4cb1982c41 | |
parent | 4a15e8b3b36dcde234ef2e068d931a59e0ce1d4e (diff) | |
download | bugzilla-d5f2d8158b90a55cefe126e38132e390e9fa75f5.tar.gz bugzilla-d5f2d8158b90a55cefe126e38132e390e9fa75f5.tar.xz |
Bug 1472048 - Remove Metrics Code
-rw-r--r-- | Bugzilla.pm | 69 | ||||
-rw-r--r-- | Bugzilla/Config/Advanced.pm | 31 | ||||
-rw-r--r-- | Bugzilla/Install/Filesystem.pm | 1 | ||||
-rw-r--r-- | Bugzilla/Metrics/Collector.pm | 171 | ||||
-rw-r--r-- | Bugzilla/Metrics/Memcached.pm | 24 | ||||
-rw-r--r-- | Bugzilla/Metrics/Mysql.pm | 148 | ||||
-rw-r--r-- | Bugzilla/Metrics/Reporter.pm | 103 | ||||
-rw-r--r-- | Bugzilla/Metrics/Reporter/ElasticSearch.pm | 105 | ||||
-rw-r--r-- | Bugzilla/Metrics/Reporter/STDERR.pm | 152 | ||||
-rw-r--r-- | Bugzilla/Metrics/Template.pm | 24 | ||||
-rw-r--r-- | Bugzilla/Metrics/Template/Context.pm | 30 | ||||
-rw-r--r-- | Bugzilla/Template.pm | 5 | ||||
-rw-r--r-- | Bugzilla/WebService/Server.pm | 5 | ||||
-rwxr-xr-x | metrics.pl | 42 | ||||
-rwxr-xr-x | page.cgi | 5 | ||||
-rw-r--r-- | template/en/default/admin/params/advanced.html.tmpl | 16 |
16 files changed, 4 insertions, 927 deletions
diff --git a/Bugzilla.pm b/Bugzilla.pm index 74fa257f2..cf22ecc32 100644 --- a/Bugzilla.pm +++ b/Bugzilla.pm @@ -48,10 +48,6 @@ use Bugzilla::Util; use Bugzilla::CPAN; use Bugzilla::Bloomfilter; -use Bugzilla::Metrics::Collector; -use Bugzilla::Metrics::Template; -use Bugzilla::Metrics::Memcached; - use Date::Parse; use DateTime::TimeZone; use Encode; @@ -139,30 +135,6 @@ sub init_page { my $script = basename($0); - # BMO - init metrics collection if required - if (i_am_cgi() && $script eq 'show_bug.cgi') { - # we need to measure loading the params, so default to on - Bugzilla->metrics_enabled(1); - Bugzilla->metrics($script); - # we can now hit params to check if we really should be enabled. - # note - we can't use anything which uses templates or the database, as - # that would initialise those modules with metrics enabled. - if (!Bugzilla->params->{metrics_enabled}) { - Bugzilla->metrics_enabled(0); - } - else { - # to avoid generating massive amounts of data, we're only interested in - # a small subset of users - my $user_id = Bugzilla->cgi->cookie('Bugzilla_login'); - if (!$user_id - || !grep { $user_id == $_ } - split(/\s*,\s*/, Bugzilla->params->{metrics_user_ids})) - { - Bugzilla->metrics_enabled(0); - } - } - } - # Because of attachment_base, attachment.cgi handles this itself. if ($script ne 'attachment.cgi') { do_ssl_redirect_if_required(); @@ -231,12 +203,7 @@ sub init_page { ##################################################################### sub template { - # BMO - use metrics subclass if required - if (Bugzilla->metrics_enabled) { - request_cache->{template} ||= Bugzilla::Metrics::Template->create(); - } else { - request_cache->{template} ||= Bugzilla::Template->create(); - } + request_cache->{template} ||= Bugzilla::Template->create(); request_cache->{template}->{_is_main} = 1; return request_cache->{template}; @@ -806,37 +773,10 @@ sub process_cache { return $_process_cache; } -# BMO - Instrumentation - -sub metrics_enabled { - if (defined $_[1]) { - if (!$_[1] - && request_cache->{metrics_enabled} - && request_cache->{metrics}) - { - request_cache->{metrics}->cancel(); - delete request_cache->{metrics}; - } - request_cache->{metrics_enabled} = $_[1]; - } - else { - return request_cache->{metrics_enabled}; - } -} - -sub metrics { - return request_cache->{metrics} ||= Bugzilla::Metrics::Collector->new($_[1]); -} - # This is a memcached wrapper, which provides cross-process and cross-system # caching. sub memcached { - # BMO - use metrics subclass if required - if (Bugzilla->metrics_enabled) { - return request_cache->{memcached} ||= Bugzilla::Metrics::Memcached->_new(); - } else { - return request_cache->{memcached} ||= Bugzilla::Memcached->_new(); - } + return request_cache->{memcached} ||= Bugzilla::Memcached->_new(); } sub elastic { @@ -882,11 +822,6 @@ sub markdown_parser { sub _cleanup { return if $^C; - # BMO - finalise and report on metrics - if (Bugzilla->metrics_enabled) { - Bugzilla->metrics->finish(); - } - # BMO - allow "end of request" processing Bugzilla::Hook::process('request_cleanup'); Bugzilla::Bug->CLEANUP; diff --git a/Bugzilla/Config/Advanced.pm b/Bugzilla/Config/Advanced.pm index 9316d8e48..398f02701 100644 --- a/Bugzilla/Config/Advanced.pm +++ b/Bugzilla/Config/Advanced.pm @@ -36,37 +36,6 @@ use constant get_param_list => ( type => 'b', default => 0 }, - - { - name => 'metrics_enabled', - type => 'b', - default => 0 - }, - { - name => 'metrics_user_ids', - type => 't', - default => '3881,5038,5898,13647,20209,251051,373476,409787' - }, - { - name => 'metrics_elasticsearch_server', - type => 't', - default => '127.0.0.1:9200' - }, - { - name => 'metrics_elasticsearch_index', - type => 't', - default => 'bmo-metrics' - }, - { - name => 'metrics_elasticsearch_type', - type => 't', - default => 'timings' - }, - { - name => 'metrics_elasticsearch_ttl', - type => 't', - default => '1210000000' # 14 days - }, ); 1; diff --git a/Bugzilla/Install/Filesystem.pm b/Bugzilla/Install/Filesystem.pm index 094226891..003be22e4 100644 --- a/Bugzilla/Install/Filesystem.pm +++ b/Bugzilla/Install/Filesystem.pm @@ -225,7 +225,6 @@ sub FILESYSTEM { 'runtests.pl' => { perms => OWNER_EXECUTE }, 'jobqueue.pl' => { perms => OWNER_EXECUTE }, 'migrate.pl' => { perms => OWNER_EXECUTE }, - 'metrics.pl' => { perms => WS_EXECUTE }, 'Makefile.PL' => { perms => OWNER_EXECUTE }, 'gen-cpanfile.pl' => { perms => OWNER_EXECUTE }, 'jobqueue-worker.pl' => { perms => OWNER_EXECUTE }, diff --git a/Bugzilla/Metrics/Collector.pm b/Bugzilla/Metrics/Collector.pm deleted file mode 100644 index 53cbac819..000000000 --- a/Bugzilla/Metrics/Collector.pm +++ /dev/null @@ -1,171 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# -# This Source Code Form is "Incompatible With Secondary Licenses", as -# defined by the Mozilla Public License, v. 2.0. - -package Bugzilla::Metrics::Collector; - -use strict; -use warnings; -use 5.10.1; - -# the reporter needs to be a constant and use'd here to ensure it's loaded at -# compile time. -use constant REPORTER => 'Bugzilla::Metrics::Reporter::ElasticSearch'; -use Bugzilla::Metrics::Reporter::ElasticSearch; - -# Debugging reporter -#use constant REPORTER => 'Bugzilla::Metrics::Reporter::STDERR'; -#use Bugzilla::Metrics::Reporter::STDERR; - -use Bugzilla::Constants; -use Cwd qw(abs_path); -use File::Basename; -use Time::HiRes qw(gettimeofday clock_gettime CLOCK_MONOTONIC); - -sub new { - my ($class, $name) = @_; - my $self = { - root => undef, - head => undef, - time => scalar(gettimeofday()), - }; - bless($self, $class); - $self->_start_timer({ type => 'main', name => $name }); - return $self; -} - -sub end { - my ($self, $timer) = @_; - my $is_head = $timer ? 0 : 1; - $timer ||= $self->{head}; - $timer->{duration} += clock_gettime(CLOCK_MONOTONIC) - $timer->{start_time}; - $self->{head} = $self->{head}->{parent} if $is_head; -} - -sub cancel { - my ($self) = @_; - delete $self->{head}; -} - -sub DESTROY { - my ($self) = @_; - $self->finish() if $self->{head}; -} - -sub finish { - my ($self) = @_; - $self->end($self->{root}); - delete $self->{head}; - - my $user = Bugzilla->user; - if ($ENV{MOD_PERL}) { - require Apache2::RequestUtil; - my $request = eval { Apache2::RequestUtil->request }; - my $headers = $request ? $request->headers_in() : {}; - $self->{env} = { - referer => $headers->{Referer}, - request_method => $request->method, - request_uri => basename($request->unparsed_uri), - script_name => $request->uri, - user_agent => $headers->{'User-Agent'}, - }; - } - else { - $self->{env} = { - referer => $ENV{HTTP_REFERER}, - request_method => $ENV{REQUEST_METHOD}, - request_uri => $ENV{REQUEST_URI}, - script_name => basename($ENV{SCRIPT_NAME}), - user_agent => $ENV{HTTP_USER_AGENT}, - }; - } - $self->{env}->{name} = $self->{root}->{name}; - $self->{env}->{time} = $self->{time}; - $self->{env}->{user_id} = $user->id; - $self->{env}->{login} = $user->login if $user->id; - - # remove passwords from request_uri - $self->{env}->{request_uri} =~ s/\b((?:bugzilla_)?password=)(?:[^&]+|.+$)/$1x/gi; - - $self->report(); -} - -sub name { - my ($self, $value) = @_; - $self->{root}->{name} = $value if defined $value; - return $self->{root}->{name}; -} - -sub db_start { - my ($self) = @_; - my $timer = $self->_start_timer({ type => 'db' }); - - my @stack; - my $i = 0; - state $path = quotemeta(abs_path(bz_locations()->{cgi_path}) . '/'); - while (1) { - my @caller = caller($i); - last unless @caller; - my $file = $caller[1]; - $file =~ s/^$path//o; - push @stack, "$file:$caller[2]" - unless substr($file, 0, 16) eq 'Bugzilla/Metrics'; - last if $file =~ /\.(?:tmpl|cgi)$/; - $i++; - } - $timer->{stack} = \@stack; - - return $timer; -} - -sub template_start { - my ($self, $file) = @_; - $self->_start_timer({ type => 'tmpl', file => $file }); -} - -sub memcached_start { - my ($self, $key) = @_; - $self->_start_timer({ type => 'memcached', key => $key }); -} - -sub memcached_end { - my ($self, $hit) = @_; - $self->{head}->{result} = $hit ? 'hit' : 'miss'; - $self->end(); -} - -sub resume { - my ($self, $timer) = @_; - $timer->{start_time} = clock_gettime(CLOCK_MONOTONIC); - return $timer; -} - -sub _start_timer { - my ($self, $timer) = @_; - $timer->{start_time} = $timer->{first_time} = clock_gettime(CLOCK_MONOTONIC); - $timer->{duration} = 0; - $timer->{children} = []; - - if ($self->{head}) { - $timer->{parent} = $self->{head}; - push @{ $self->{head}->{children} }, $timer; - } - else { - $timer->{parent} = undef; - $self->{root} = $timer; - } - $self->{head} = $timer; - - return $timer; -} - -sub report { - my ($self) = @_; - my $class = REPORTER; - $class->DETACH ? $class->background($self) : $class->foreground($self); -} - -1; diff --git a/Bugzilla/Metrics/Memcached.pm b/Bugzilla/Metrics/Memcached.pm deleted file mode 100644 index b640f9280..000000000 --- a/Bugzilla/Metrics/Memcached.pm +++ /dev/null @@ -1,24 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# -# This Source Code Form is "Incompatible With Secondary Licenses", as -# defined by the Mozilla Public License, v. 2.0. - -package Bugzilla::Metrics::Memcached; - -use 5.10.1; -use strict; -use warnings; - -use base 'Bugzilla::Memcached'; - -sub _get { - my $self = shift; - Bugzilla->metrics->memcached_start($_[0]); - my $result = $self->SUPER::_get(@_); - Bugzilla->metrics->memcached_end($result); - return $result; -} - -1; diff --git a/Bugzilla/Metrics/Mysql.pm b/Bugzilla/Metrics/Mysql.pm deleted file mode 100644 index 60dff78c8..000000000 --- a/Bugzilla/Metrics/Mysql.pm +++ /dev/null @@ -1,148 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# -# This Source Code Form is "Incompatible With Secondary Licenses", as -# defined by the Mozilla Public License, v. 2.0. - -package Bugzilla::Metrics::Mysql; - -use 5.10.1; -use strict; -use warnings; - -use base 'Bugzilla::DB::Mysql'; - -sub do { - my ($self, @args) = @_; - Bugzilla->metrics->db_start($args[0]); - my $result = $self->SUPER::do(@args); - Bugzilla->metrics->end(); - return $result; -} - -sub selectall_arrayref { - my ($self, @args) = @_; - Bugzilla->metrics->db_start($args[0]); - my $result = $self->SUPER::selectall_arrayref(@args); - Bugzilla->metrics->end(); - return $result; -} - -sub selectall_hashref { - my ($self, @args) = @_; - Bugzilla->metrics->db_start($args[0]); - my $result = $self->SUPER::selectall_hashref(@args); - Bugzilla->metrics->end(); - return $result; -} - -sub selectcol_arrayref { - my ($self, @args) = @_; - Bugzilla->metrics->db_start($args[0]); - my $result = $self->SUPER::selectcol_arrayref(@args); - Bugzilla->metrics->end(); - return $result; -} - -sub selectrow_array { - my ($self, @args) = @_; - Bugzilla->metrics->db_start($args[0]); - my @result = $self->SUPER::selectrow_array(@args); - Bugzilla->metrics->end(); - return wantarray ? @result : $result[0]; -} - -sub selectrow_arrayref { - my ($self, @args) = @_; - Bugzilla->metrics->db_start($args[0]); - my $result = $self->SUPER::selectrow_arrayref(@args); - Bugzilla->metrics->end(); - return $result; -} - -sub selectrow_hashref { - my ($self, @args) = @_; - Bugzilla->metrics->db_start($args[0]); - my $result = $self->SUPER::selectrow_hashref(@args); - Bugzilla->metrics->end(); - return $result; -} - -sub commit { - my ($self, @args) = @_; - Bugzilla->metrics->db_start('COMMIT'); - my $result = $self->SUPER::commit(@args); - Bugzilla->metrics->end(); - return $result; -} - -sub prepare { - my ($self, @args) = @_; - my $sth = $self->SUPER::prepare(@args); - bless($sth, 'Bugzilla::Metrics::st'); - return $sth; -} - -package Bugzilla::Metrics::st; - -use 5.10.1; -use strict; -use warnings; - -use base 'DBI::st'; - -sub execute { - my ($self, @args) = @_; - $self->{private_timer} = Bugzilla->metrics->db_start(); - my $result = $self->SUPER::execute(@args); - Bugzilla->metrics->end(); - return $result; -} - -sub fetchrow_array { - my ($self, @args) = @_; - my $timer = $self->{private_timer}; - Bugzilla->metrics->resume($timer); - my @result = $self->SUPER::fetchrow_array(@args); - Bugzilla->metrics->end($timer); - return wantarray ? @result : $result[0]; -} - -sub fetchrow_arrayref { - my ($self, @args) = @_; - my $timer = $self->{private_timer}; - Bugzilla->metrics->resume($timer); - my $result = $self->SUPER::fetchrow_arrayref(@args); - Bugzilla->metrics->end($timer); - return $result; -} - -sub fetchrow_hashref { - my ($self, @args) = @_; - my $timer = $self->{private_timer}; - Bugzilla->metrics->resume($timer); - my $result = $self->SUPER::fetchrow_hashref(@args); - Bugzilla->metrics->end($timer); - return $result; -} - -sub fetchall_arrayref { - my ($self, @args) = @_; - my $timer = $self->{private_timer}; - Bugzilla->metrics->resume($timer); - my $result = $self->SUPER::fetchall_arrayref(@args); - Bugzilla->metrics->end($timer); - return $result; -} - -sub fetchall_hashref { - my ($self, @args) = @_; - my $timer = $self->{private_timer}; - Bugzilla->metrics->resume($timer); - my $result = $self->SUPER::fetchall_hashref(@args); - Bugzilla->metrics->end($timer); - return $result; -} - -1; diff --git a/Bugzilla/Metrics/Reporter.pm b/Bugzilla/Metrics/Reporter.pm deleted file mode 100644 index 8216ea923..000000000 --- a/Bugzilla/Metrics/Reporter.pm +++ /dev/null @@ -1,103 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# -# This Source Code Form is "Incompatible With Secondary Licenses", as -# defined by the Mozilla Public License, v. 2.0. - -package Bugzilla::Metrics::Reporter; - -use 5.10.1; -use strict; -use warnings; - -use Bugzilla::Constants; -use File::Slurp; -use File::Temp; -use JSON; - -# most reporters should detach from the httpd process. -# reporters which do not detach will block completion of the http response. -use constant DETACH => 1; - -# class method to start the delivery script in the background -sub background { - my ($class, $collector) = @_; - - # we need to remove parent links to avoid looped structures, which - # encode_json chokes on - _walk_timers($collector->{root}, sub { delete $_[0]->{parent} }); - - # serialisation - my $json = encode_json({ env => $collector->{env}, times => $collector->{root} }); - - # write to temp filename - my $fh = File::Temp->new( UNLINK => 0 ); - if (!$fh) { - warn "Failed to create temp file: $!\n"; - return; - } - binmode($fh, ':utf8'); - print $fh $json; - close($fh) or die "$fh : $!"; - my $filename = $fh->filename; - - # spawn delivery worker - my $command = bz_locations()->{'cgi_path'} . "/metrics.pl '$class' '$filename' &"; - $ENV{PATH} = ''; - system($command); -} - -# run the reporter immediately -sub foreground { - my ($class, $collector) = @_; - my $reporter = $class->new({ hashref => { env => $collector->{env}, times => $collector->{root} } }); - $reporter->report(); -} - -sub new { - my ($invocant, $args) = @_; - my $class = ref($invocant) || $invocant; - - # load from either a json_filename or hashref - my $self; - if ($args->{json_filename}) { - $self = decode_json(read_file($args->{json_filename}, binmode => ':utf8')); - unlink($args->{json_filename}); - } - else { - $self = $args->{hashref}; - } - bless($self, $class); - - # remove redundant data - $self->walk_timers(sub { - my ($timer) = @_; - $timer->{start_time} = delete $timer->{first_time}; - delete $timer->{children} - if exists $timer->{children} && !scalar(@{ $timer->{children} }); - }); - - return $self; -} - -sub walk_timers { - my ($self, $callback) = @_; - _walk_timers($self->{times}, $callback, undef); -} - -sub _walk_timers { - my ($timer, $callback, $parent) = @_; - $callback->($timer, $parent); - if (exists $timer->{children}) { - foreach my $child (@{ $timer->{children} }) { - _walk_timers($child, $callback, $timer); - } - } -} - -sub report { - die "abstract method call"; -} - -1; diff --git a/Bugzilla/Metrics/Reporter/ElasticSearch.pm b/Bugzilla/Metrics/Reporter/ElasticSearch.pm deleted file mode 100644 index c61a1d750..000000000 --- a/Bugzilla/Metrics/Reporter/ElasticSearch.pm +++ /dev/null @@ -1,105 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# -# This Source Code Form is "Incompatible With Secondary Licenses", as -# defined by the Mozilla Public License, v. 2.0. - -package Bugzilla::Metrics::Reporter::ElasticSearch; - -use 5.10.1; -use strict; -use warnings; - -use base 'Bugzilla::Metrics::Reporter'; - -use constant DETACH => 1; - -sub report { - my ($self) = @_; - - # build path array and flatten - my @timers; - $self->walk_timers(sub { - my ($timer, $parent) = @_; - $timer->{id} = scalar(@timers); - if ($parent) { - if (exists $timer->{children}) { - if ($timer->{type} eq 'tmpl') { - $timer->{node} = 'tmpl: ' . $timer->{file}; - } - elsif ($timer->{type} eq 'db') { - $timer->{node} = 'db'; - } - else { - $timer->{node} = '?'; - } - } - $timer->{path} = [ @{ $parent->{path} }, $parent->{node} ]; - $timer->{parent} = $parent->{id}; - } - else { - $timer->{path} = [ ]; - $timer->{node} = $timer->{name}; - } - push @timers, $timer; - }); - - # calculate timer-only durations - $self->walk_timers(sub { - my ($timer) = @_; - my $child_duration = 0; - if (exists $timer->{children}) { - foreach my $child (@{ $timer->{children} }) { - $child_duration += $child->{duration}; - } - } - $timer->{this_duration} = $timer->{duration} - $child_duration; - }); - - # massage each timer - my $start_time = $self->{times}->{start_time}; - foreach my $timer (@timers) { - # remove node name and children - delete $timer->{node}; - delete $timer->{children}; - - # show relative times - $timer->{start_time} = $timer->{start_time} - $start_time; - delete $timer->{end_time}; - - # show times in ms instead of fractional seconds - foreach my $field (qw( start_time duration this_duration )) { - $timer->{$field} = sprintf('%.4f', $timer->{$field} * 1000) * 1; - } - } - - # remove private data from env - delete $self->{env}->{user_agent}; - delete $self->{env}->{referer}; - - # throw at ES - require ElasticSearch; - my $es = ElasticSearch->new( - servers => Bugzilla->params->{metrics_elasticsearch_server}, - transport => 'http', - ); - # the ElasticSearch module queries the server for a list of nodes and - # connects directly to a random node. that bypasses our load balancer so we - # disable that by setting the server list directly. - $es->transport->servers(Bugzilla->params->{metrics_elasticsearch_server}); - # as the discovered node list is lazy-loaded, increase _refresh_in so it - # won't call ->refresh_servers() - $es->transport->{_refresh_in} = 1; - $es->index( - index => Bugzilla->params->{metrics_elasticsearch_index}, - type => Bugzilla->params->{metrics_elasticsearch_type}, - ttl => Bugzilla->params->{metrics_elasticsearch_ttl}, - data => { - env => $self->{env}, - times => \@timers, - }, - ); -} - -1; diff --git a/Bugzilla/Metrics/Reporter/STDERR.pm b/Bugzilla/Metrics/Reporter/STDERR.pm deleted file mode 100644 index a61cdb25f..000000000 --- a/Bugzilla/Metrics/Reporter/STDERR.pm +++ /dev/null @@ -1,152 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# -# This Source Code Form is "Incompatible With Secondary Licenses", as -# defined by the Mozilla Public License, v. 2.0. - -package Bugzilla::Metrics::Reporter::STDERR; - -use 5.10.1; -use strict; -use warnings; - -use base 'Bugzilla::Metrics::Reporter'; - -use Data::Dumper; - -use constant DETACH => 0; - -sub report { - my ($self) = @_; - - # count totals - $self->{total} = $self->{times}->{duration}; - $self->{tmpl_count} = $self->{db_count} = $self->{mem_count} = 0; - $self->{total_tmpl} = $self->{total_db} = $self->{mem_hits} = 0; - $self->{mem_keys} = {}; - $self->_tally($self->{times}); - - # calculate percentages - $self->{other} = $self->{total} - $self->{total_tmpl} - $self->{total_db}; - if ($self->{total} * 1) { - $self->{perc_tmpl} = $self->{total_tmpl} / $self->{total} * 100; - $self->{perc_db} = $self->{total_db} / $self->{total} * 100; - $self->{perc_other} = $self->{other} / $self->{total} * 100; - } else { - $self->{perc_tmpl} = 0; - $self->{perc_db} = 0; - $self->{perc_other} = 0; - } - if ($self->{mem_count}) { - $self->{perc_mem} = $self->{mem_hits} / $self->{mem_count} * 100; - } else { - $self->{perm_mem} = 0; - } - - # convert to ms and format - foreach my $key (qw( total total_tmpl total_db other )) { - $self->{$key} = sprintf("%.4f", $self->{$key} * 1000); - } - foreach my $key (qw( perc_tmpl perc_db perc_other perc_mem )) { - $self->{$key} = sprintf("%.1f", $self->{$key}); - } - - # massage each timer - my $start_time = $self->{times}->{start_time}; - $self->walk_timers(sub { - my ($timer) = @_; - delete $timer->{parent}; - - # show relative times - $timer->{start_time} = $timer->{start_time} - $start_time; - delete $timer->{end_time}; - - # show times in ms instead of fractional seconds - foreach my $field (qw( start_time duration duration_this )) { - $timer->{$field} = sprintf('%.4f', $timer->{$field} * 1000) * 1 - if exists $timer->{$field}; - } - }); - - if (0) { - # dump timers to stderr - local $Data::Dumper::Indent = 1; - local $Data::Dumper::Terse = 1; - local $Data::Dumper::Sortkeys = sub { - my ($rh) = @_; - return [ sort { $b cmp $a } keys %$rh ]; - }; - print STDERR Dumper($self->{env}); - print STDERR Dumper($self->{times}); - } - - # summary summary table too - print STDERR <<EOF; -total time: $self->{total} - tmpl time: $self->{total_tmpl} ($self->{perc_tmpl}%) $self->{tmpl_count} hits - db time: $self->{total_db} ($self->{perc_db}%) $self->{db_count} hits -other time: $self->{other} ($self->{perc_other}%) - memcached: $self->{perc_mem}% ($self->{mem_count} requests) -EOF - my $tmpls = $self->{tmpl}; - my $len = 0; - foreach my $file (keys %$tmpls) { - $len = length($file) if length($file) > $len; - } - foreach my $file (sort { $tmpls->{$b}->{count} <=> $tmpls->{$a}->{count} } keys %$tmpls) { - my $tmpl = $tmpls->{$file}; - printf STDERR - "%${len}s: %2s hits %8.4f total %8.4f avg\n", - $file, - $tmpl->{count}, - $tmpl->{duration} * 1000, - $tmpl->{duration} * 1000 / $tmpl->{count} - ; - } - my $keys = $self->{mem_keys}; - $len = 0; - foreach my $key (keys %$keys) { - $len = length($key) if length($key) > $len; - } - foreach my $key (sort { $keys->{$a} <=> $keys->{$b} or $a cmp $b } keys %$keys) { - printf STDERR "%${len}s: %s\n", $key, $keys->{$key}; - } -} - -sub _tally { - my ($self, $timer) = @_; - if (exists $timer->{children}) { - foreach my $child (@{ $timer->{children} }) { - $self->_tally($child); - } - } - - if ($timer->{type} eq 'db') { - $timer->{duration_this} = $timer->{duration}; - $self->{total_db} += $timer->{duration}; - $self->{db_count}++; - - } elsif ($timer->{type} eq 'tmpl') { - my $child_duration = 0; - if (exists $timer->{children}) { - foreach my $child (@{ $timer->{children} }) { - $child_duration += $child->{duration}; - } - } - $timer->{duration_this} = $timer->{duration} - $child_duration; - - $self->{total_tmpl} += $timer->{duration} - $child_duration; - $self->{tmpl_count}++; - $self->{tmpl}->{$timer->{file}}->{count}++; - $self->{tmpl}->{$timer->{file}}->{duration} += $timer->{duration}; - - } elsif ($timer->{type} eq 'memcached') { - $timer->{duration_this} = $timer->{duration}; - $self->{mem_count}++; - $self->{mem_keys}->{$timer->{key}}++; - $self->{mem_hits}++ if $timer->{result} eq 'hit'; - } -} - -1; diff --git a/Bugzilla/Metrics/Template.pm b/Bugzilla/Metrics/Template.pm deleted file mode 100644 index 5d9af240e..000000000 --- a/Bugzilla/Metrics/Template.pm +++ /dev/null @@ -1,24 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# -# This Source Code Form is "Incompatible With Secondary Licenses", as -# defined by the Mozilla Public License, v. 2.0. - -package Bugzilla::Metrics::Template; - -use 5.10.1; -use strict; -use warnings; - -use base 'Bugzilla::Template'; - -sub process { - my $self = shift; - Bugzilla->metrics->template_start($_[0]); - my $result = $self->SUPER::process(@_); - Bugzilla->metrics->end(); - return $result; -} - -1; diff --git a/Bugzilla/Metrics/Template/Context.pm b/Bugzilla/Metrics/Template/Context.pm deleted file mode 100644 index 278cfce1e..000000000 --- a/Bugzilla/Metrics/Template/Context.pm +++ /dev/null @@ -1,30 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# -# This Source Code Form is "Incompatible With Secondary Licenses", as -# defined by the Mozilla Public License, v. 2.0. - -package Bugzilla::Metrics::Template::Context; - -use 5.10.1; -use strict; -use warnings; - -use base 'Bugzilla::Template::Context'; - -sub process { - my $self = shift; - - # we only want to measure files not template blocks - if (ref($_[0]) || substr($_[0], -5) ne '.tmpl') { - return $self->SUPER::process(@_); - } - - Bugzilla->metrics->template_start($_[0]); - my $result = $self->SUPER::process(@_); - Bugzilla->metrics->end(); - return $result; -} - -1; diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm index ae4f9bbad..9eea0d3dd 100644 --- a/Bugzilla/Template.pm +++ b/Bugzilla/Template.pm @@ -1050,10 +1050,7 @@ sub create { $SHARED_PROVIDERS{$provider_key} ||= $provider_class->new($config); $config->{LOAD_TEMPLATES} = [ $SHARED_PROVIDERS{$provider_key} ]; - # BMO - use metrics subclass - local $Template::Config::CONTEXT = Bugzilla->metrics_enabled() - ? 'Bugzilla::Metrics::Template::Context' - : 'Bugzilla::Template::Context'; + local $Template::Config::CONTEXT = 'Bugzilla::Template::Context'; Bugzilla::Hook::process('template_before_create', { config => $config }); my $template = $class->new($config) diff --git a/Bugzilla/WebService/Server.pm b/Bugzilla/WebService/Server.pm index ba9847abc..a76c4c48c 100644 --- a/Bugzilla/WebService/Server.pm +++ b/Bugzilla/WebService/Server.pm @@ -23,11 +23,6 @@ sub handle_login { # Throw error if the supplied class does not exist or the method is private ThrowCodeError('unknown_method', {method => $full_method}) if (!$class or $method =~ /^_/); - # BMO - use the class and method as the name, instead of the cgi filename - if (Bugzilla->metrics_enabled) { - Bugzilla->metrics->name("$class $method"); - } - # We never want to create a new session unless the user is calling the # login method. Setting dont_persist_session makes # Bugzilla::Auth::_handle_login_result() skip calling persist_login(). diff --git a/metrics.pl b/metrics.pl deleted file mode 100755 index b181ebf32..000000000 --- a/metrics.pl +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/perl - -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# -# This Source Code Form is "Incompatible With Secondary Licenses", as -# defined by the Mozilla Public License, v. 2.0. - -use 5.10.1; -use strict; -use warnings; -use lib qw(. lib local/lib/perl5); - -BEGIN { delete $ENV{SERVER_SOFTWARE}; } - -use Bugzilla; -use Bugzilla::Constants; -use POSIX qw(setsid nice); - -Bugzilla->metrics_enabled(0); -Bugzilla->usage_mode(USAGE_MODE_CMDLINE); -nice(19); - -# grab reporter class and filename -exit(1) unless my $reporter_class = shift; -exit(1) unless my $filename = shift; - -# create reporter object and report -eval "use $reporter_class"; - -# detach -if ($reporter_class->DETACH) { - open(STDIN, '<', '/dev/null'); - open(STDOUT, '>', '/dev/null'); - open(STDERR, '>', '/dev/null'); - setsid(); -} - -# report -exit(1) unless my $reporter = $reporter_class->new({ json_filename => $filename }); -$reporter->report(); @@ -65,11 +65,6 @@ if ($id) { ThrowCodeError("bad_page_cgi_id", { "page_id" => $id }); } - # BMO - append template filename to metrics data - if (Bugzilla->metrics_enabled) { - Bugzilla->metrics->name("page.cgi $id"); - } - my %vars = ( quicksearch_field_names => \&quicksearch_field_names, ); diff --git a/template/en/default/admin/params/advanced.html.tmpl b/template/en/default/admin/params/advanced.html.tmpl index 7c85881d7..2fe59c533 100644 --- a/template/en/default/admin/params/advanced.html.tmpl +++ b/template/en/default/admin/params/advanced.html.tmpl @@ -25,7 +25,7 @@ %] [% sts_desc = BLOCK %] - Enables the sending of the + Enables the sending of the <a href="https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security">Strict-Transport-Security</a> header along with HTTP responses on SSL connections. This adds greater security to your SSL connections by forcing the browser to always @@ -67,18 +67,4 @@ disable_bug_updates => "When enabled, all updates to $terms.bugs will be blocked.", - - metrics_enabled => - "Collect metrics for reporting to ElasticSearch", - metrics_user_ids => - "Comma separated list of user_id's which trigger data collection and reporting." - _ " eg <kbd>3881,5038,5898,13647,20209,251051,373476,409787</kbd>.", - metrics_elasticsearch_server => - "Metrics ElasticSearch server and port. eg <kbd>127.0.0.1:9200</kbd>", - metrics_elasticsearch_index => - "Metrics ElasticSearch index. eg <kbd>bmo-metrics</kbd>", - metrics_elasticsearch_type => - "Metrics ElasticSearch type. eg <kbd>timings</kbd>", - metrics_elasticsearch_ttl => - "The time to live for data in the ElasticSearch cluster, in milliseconds. eg <kbd>1210000000</kbd>", } %] |