From 80c784ce1b8805b4d1797bcc1c49bc40a7ea1946 Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Wed, 19 Mar 2014 16:03:37 +0800 Subject: Bug 985305: update the metrics elasticsearch reporter to bypass es node discovery --- Bugzilla/Metrics/Collector.pm | 12 +++++++++--- Bugzilla/Metrics/Reporter/ElasticSearch.pm | 12 ++++++++++-- metrics.pl | 1 - 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Bugzilla/Metrics/Collector.pm b/Bugzilla/Metrics/Collector.pm index 2f9b6130d..53cbac819 100644 --- a/Bugzilla/Metrics/Collector.pm +++ b/Bugzilla/Metrics/Collector.pm @@ -9,6 +9,7 @@ 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. @@ -19,6 +20,8 @@ use Bugzilla::Metrics::Reporter::ElasticSearch; #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); @@ -102,12 +105,15 @@ sub db_start { my @stack; my $i = 0; + state $path = quotemeta(abs_path(bz_locations()->{cgi_path}) . '/'); while (1) { my @caller = caller($i); last unless @caller; - last if substr($caller[1], -5, 5) eq '.tmpl'; - push @stack, "$caller[1]:$caller[2]" - unless substr($caller[1], 0, 16) eq 'Bugzilla/Metrics'; + 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; diff --git a/Bugzilla/Metrics/Reporter/ElasticSearch.pm b/Bugzilla/Metrics/Reporter/ElasticSearch.pm index 4b424b5da..1bab2502c 100644 --- a/Bugzilla/Metrics/Reporter/ElasticSearch.pm +++ b/Bugzilla/Metrics/Reporter/ElasticSearch.pm @@ -79,10 +79,18 @@ sub report { # throw at ES require ElasticSearch; - ElasticSearch->new( + my $es = ElasticSearch->new( servers => Bugzilla->params->{metrics_elasticsearch_server}, transport => 'http', - )->index( + ); + # 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}, diff --git a/metrics.pl b/metrics.pl index 5d955fd88..f10499057 100644 --- a/metrics.pl +++ b/metrics.pl @@ -20,7 +20,6 @@ use lib "$Bin/lib"; use Bugzilla; use Bugzilla::Constants; -use File::Slurp; use POSIX qw(setsid nice); Bugzilla->metrics_enabled(0); -- cgit v1.2.3-24-g4f1b