From 34788ed25426a2a9d461613772a9e7f16447c5c0 Mon Sep 17 00:00:00 2001 From: Robert Helmer Date: Thu, 6 Oct 2011 02:42:16 -0700 Subject: [PATCH] bug 637661 - add pagination and duration selector, disable duplicates until we have a better way to show them --- socorro/cron/hangReport.py | 2 +- socorro/services/hangReport.py | 41 ++++++++++--- sql/upgrade/2.3/hang_report.sql | 2 +- .../application/controllers/hangreport.php | 20 ++++--- webapp-php/application/models/hangreport.php | 5 +- .../views/hangreport/byversion.php | 53 ++++++++-------- .../application/views/hangreport/index.php | 60 ------------------- 7 files changed, 75 insertions(+), 108 deletions(-) delete mode 100644 webapp-php/application/views/hangreport/index.php diff --git a/socorro/cron/hangReport.py b/socorro/cron/hangReport.py index fe011dfb47..8cfd20afe1 100644 --- a/socorro/cron/hangReport.py +++ b/socorro/cron/hangReport.py @@ -16,7 +16,7 @@ def run(config): connection, cursor = databaseConnectionPool.connectionCursorPair() startTime = datetime.now() - timedelta(day=1) - cursor.callproc('hang_report', (startTime)) + cursor.callproc('update_hang_report', (startTime)) connection.commit() finally: databaseConnectionPool.cleanup() diff --git a/socorro/services/hangReport.py b/socorro/services/hangReport.py index 706cb8a400..1ef6324202 100644 --- a/socorro/services/hangReport.py +++ b/socorro/services/hangReport.py @@ -11,17 +11,38 @@ def __init__(self, configContext): super(HangReport, self).__init__(configContext) logger.debug('HangReport __init__') - # http://socorro-api/bpapi/201109/reports/hang/p/Firefox/v/9.0a1/end/2011-09-20T15%3A00%3A00T%2B0000/days/1/listsize/300 - uri = '/201109/reports/hang/p/(.*)/v/(.*)/end/(.*)/duration/(.*)/listsize/(.*)' + # http://socorro-api/bpapi/201109/reports/hang/p/Firefox/v/9.0a1/end/2011-09-20T15%3A00%3A00T%2B0000/days/1/listsize/300/page/1 + uri = '/201109/reports/hang/p/(.*)/v/(.*)/end/(.*)/duration/(.*)/listsize/(.*)/page/(.*)' def get(self, *args): - convertedArgs = webapi.typeConversion([str, str, dtutil.datetimeFromISOdateString, int, int], args) - parameters = util.DotDict(zip(['product', 'version', 'end', 'duration', 'listsize'], convertedArgs)) + convertedArgs = webapi.typeConversion([str, str, dtutil.datetimeFromISOdateString, int, int, int], args) + parameters = util.DotDict(zip(['product', 'version', 'end', 'duration', 'listsize', 'page'], convertedArgs)) connection = self.database.connection() cursor = connection.cursor() - hangReport = """ + hangReportCountSql = """ + /* socorro.services.HangReportCount */ + SELECT count(*) + FROM hang_report + WHERE product = %(product)s + AND version = %(version)s + AND report_day > utc_day_begins_pacific(((%(end)s)::timestamp - interval '%(duration)s days')::date) + """ + + logger.debug(cursor.mogrify(hangReportCountSql, parameters)) + cursor.execute(hangReportCountSql, parameters) + + hangReportCount = cursor.fetchone()[0] + + listsize = parameters['listsize'] + page = parameters['page'] + totalPages = hangReportCount / listsize + logger.debug('total pages: %s' % totalPages) + + parameters['offset'] = listsize * (page - 1) + + hangReportSql = """ /* socorro.services.HangReport */ SELECT browser_signature, plugin_signature, browser_hangid, flash_version, url, @@ -30,10 +51,11 @@ def get(self, *args): WHERE product = %(product)s AND version = %(version)s AND report_day > utc_day_begins_pacific(((%(end)s)::timestamp - interval '%(duration)s days')::date) - LIMIT %(listsize)s""" + LIMIT %(listsize)s + OFFSET %(offset)s""" - logger.debug(cursor.mogrify(hangReport, parameters)) - cursor.execute(hangReport, parameters) + logger.debug(cursor.mogrify(hangReportSql, parameters)) + cursor.execute(hangReportSql, parameters) result = [] for row in cursor.fetchall(): @@ -47,4 +69,5 @@ def get(self, *args): 'uuid': uuid, 'duplicates': duplicates, 'report_day': str(report_day)}) - return {'hangReport': result, 'end_date': str(parameters['end'])} + return {'hangReport': result, 'endDate': str(parameters['end']), 'totalPages': totalPages, 'currentPage': page, + 'totalCount': hangReportCount} diff --git a/sql/upgrade/2.3/hang_report.sql b/sql/upgrade/2.3/hang_report.sql index 3735c849b8..6ae3c04c2e 100644 --- a/sql/upgrade/2.3/hang_report.sql +++ b/sql/upgrade/2.3/hang_report.sql @@ -22,7 +22,7 @@ CREATE OR REPLACE FUNCTION update_hang_report(updateday DATE) RETURNS BOOLEAN -- created for bug 637661 INSERT INTO hang_report ( - SELECT + SELECT DISTINCT product_name AS product, version_string AS version, browser.signature AS browser_signature, diff --git a/webapp-php/application/controllers/hangreport.php b/webapp-php/application/controllers/hangreport.php index 11873a0ec2..aab051837a 100644 --- a/webapp-php/application/controllers/hangreport.php +++ b/webapp-php/application/controllers/hangreport.php @@ -95,7 +95,7 @@ public function index() { * @param string The crash type to query by * @return void */ - public function byversion($product=null, $version=null, $duration=null, $crash_type=null) + public function byversion($product=null, $version=null) { if(is_null($product)) { Kohana::show_404(); @@ -107,12 +107,13 @@ public function byversion($product=null, $version=null, $duration=null, $crash_t $this->_versionExists($version); } + $duration = (int)Input::instance()->get('duration'); if (empty($duration)) { $duration = Kohana::config('products.duration'); } - $duration_url_path = array(Router::$controller, Router::$method, $product, $version); - $durations = Kohana::config('hang_report.durations'); + $page = (int)Input::instance()->get('page'); + $page = (!empty($page) && $page > 0) ? $page : 1; $config = array(); $credentials = Kohana::config('webserviceclient.basic_auth'); @@ -131,19 +132,24 @@ public function byversion($product=null, $version=null, $duration=null, $crash_t $p = urlencode($product); $v = urlencode($version); - $resp = $this->hangreport_model->getHangReportViaWebService($p, $v, $duration); + $pg = urlencode($page); + $resp = $this->hangreport_model->getHangReportViaWebService($p, $v, $duration, $pg); if ($resp) { + $pager = new MozPager(Kohana::config('hang_report.byversion_limit'), $resp->totalCount, $resp->currentPage); + $this->setViewData(array( 'resp' => $resp, - 'duration_url' => url::site(implode($duration_url_path, '/') . '/'), 'duration' => $duration, - 'durations' => $durations, 'product' => $product, 'version' => $version, 'nav_selection' => 'hang_report', - 'end_date' => $resp->end_date, + 'end_date' => $resp->endDate, + 'url_base' => url::site('hangreport/byversion/'.$product.'/'.$version), 'url_nav' => url::site('products/'.$product), + 'pager' => $pager, + 'totalItemText' => " Results", + 'navPathPrefix' => url::site('hangreport/byversion/'.$product.'/'.$version) . '?duration=' . $duration . '&page=', )); } else { header("Data access error", TRUE, 500); diff --git a/webapp-php/application/models/hangreport.php b/webapp-php/application/models/hangreport.php index 4c8fdf3407..b432cbf3b3 100644 --- a/webapp-php/application/models/hangreport.php +++ b/webapp-php/application/models/hangreport.php @@ -12,7 +12,7 @@ class HangReport_Model extends Model { * @param int The number of days * @return array Returns */ - public function getHangReportViaWebService($product, $version, $duration) + public function getHangReportViaWebService($product, $version, $duration, $page) { $config = array(); $credentials = Kohana::config('webserviceclient.basic_auth'); @@ -27,8 +27,9 @@ public function getHangReportViaWebService($product, $version, $duration) $lifetime = Kohana::config('products.cache_expires'); $p = urlencode($product); $v = urlencode($version); + $pg = urlencode($page); - $resp = $service->get("${host}/201109/reports/hang/p/${p}/v/${v}/end/${end_date}/duration/${duration}/listsize/${limit}"); + $resp = $service->get("${host}/201109/reports/hang/p/${p}/v/${v}/end/${end_date}/duration/${duration}/listsize/${limit}/page/${pg}"); if($resp) { return $resp; } diff --git a/webapp-php/application/views/hangreport/byversion.php b/webapp-php/application/views/hangreport/byversion.php index 39ab499678..b4ef667f7f 100644 --- a/webapp-php/application/views/hangreport/byversion.php +++ b/webapp-php/application/views/hangreport/byversion.php @@ -16,6 +16,11 @@ + @@ -36,30 +41,28 @@ } ?> OOID - Duplicates Report Day render(TRUE); foreach ($resp->hangReport as $entry) { - $sigParams = array( - #'range_value' => $range_value, - #'range_unit' => $range_unit, - 'date' => $end_date, - 'signature' => $entry->browser_signature - ); - if (property_exists($entry, 'branch')) { - $sigParams['branch'] = $entry->branch; - } else { - $sigParams['version'] = $product . ':' . $version; - } - - $browser_link_url = url::base() . 'report/list?' . html::query_string($sigParams); - $sigParams['signature'] = $entry->plugin_signature; - $plugin_link_url = url::base() . 'report/list?' . html::query_string($sigParams); - $uuid_link_url = url::base() . 'report/index/' . $entry->uuid; + $sigParams = array( + 'date' => $end_date, + 'signature' => $entry->browser_signature + ); + if (property_exists($entry, 'branch')) { + $sigParams['branch'] = $entry->branch; + } else { + $sigParams['version'] = $product . ':' . $version; + } + + $browser_link_url = url::base() . 'report/list?' . html::query_string($sigParams); + $sigParams['signature'] = $entry->plugin_signature; + $plugin_link_url = url::base() . 'report/list?' . html::query_string($sigParams); + $uuid_link_url = url::base() . 'report/index/' . $entry->uuid; ?> @@ -85,25 +88,19 @@ uuid) ?> -duplicates as $dup) { -?> - - - - report_day) ?> + + +render(TRUE); } else { View::factory('common/data_access_error')->render(TRUE); } ?> - - diff --git a/webapp-php/application/views/hangreport/index.php b/webapp-php/application/views/hangreport/index.php deleted file mode 100644 index d4db044381..0000000000 --- a/webapp-php/application/views/hangreport/index.php +++ /dev/null @@ -1,60 +0,0 @@ - - Top Crashers - - -
-

Top Crashers

-
- - -
-
-

-
-
- - - - - - - - - - - '2', - 'range_unit' => 'weeks', - 'signature' => $crasher->signature - ); - if (property_exists($crasher, 'version')) { - $sigParams['version'] = $crasher->product . ':' . $crasher->version; - } else { - $sigParams['branch'] = $crasher->branch; - } - $link_url = url::base() . 'report/list?' . html::query_string($sigParams); - - if (empty($crasher->signature)) { - $sig = '(no signature)'; - } else { - $sig = $crasher->signature; - } - ?> - - - - - -
SignatureCrash Count
total)?>
- - -

View all current crashers

-
-
-