From 5e184ee593b3c0d2ca28ec4c21c70b14442136f7 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 20 Jun 2012 13:20:47 -0700 Subject: [PATCH] Improve debug support for notifications Summary: Add a `notification.debug` setting that shows debug info in the browser. Also improve some logging/error handling stuff and fix a bug with host names. Test Plan: {F13098} Reviewers: jungejason, btrahan, vrana Reviewed By: btrahan CC: aran Maniphest Tasks: T944 Differential Revision: https://secure.phabricator.com/D2810 --- conf/default.conf.php | 3 + src/__celerity_resource_map__.php | 103 +----------------- src/docs/userguide/notifications.diviner | 5 +- src/view/page/PhabricatorStandardPageView.php | 6 +- support/aphlict/client/src/Aphlict.as | 1 - support/aphlict/server/aphlict_server.js | 41 ++++--- webroot/rsrc/css/aphront/notification.css | 5 + .../aphlict/behavior-aphlict-listen.js | 25 +++-- 8 files changed, 61 insertions(+), 128 deletions(-) diff --git a/conf/default.conf.php b/conf/default.conf.php index 83908ccb74..944e51791e 100644 --- a/conf/default.conf.php +++ b/conf/default.conf.php @@ -209,6 +209,9 @@ return array( // PID file to use. 'notification.pidfile' => '/var/run/aphlict.pid', + // Enable this option to get additional debug output in the browser. + 'notification.debug' => false, + // -- Email ----------------------------------------------------------------- // diff --git a/src/__celerity_resource_map__.php b/src/__celerity_resource_map__.php index 9179a15f7a..3f3c199352 100644 --- a/src/__celerity_resource_map__.php +++ b/src/__celerity_resource_map__.php @@ -49,20 +49,6 @@ celerity_register_resource_map(array( 'disk' => '/rsrc/image/custom/example_template.png', 'type' => 'png', ), - '/rsrc/image/facebook/icon/fatcow/speedometer.png' => - array( - 'hash' => '3345a7ba5b3c99dbfa3a922a16756815', - 'uri' => '/res/3345a7ba/rsrc/image/facebook/icon/fatcow/speedometer.png', - 'disk' => '/rsrc/image/facebook/icon/fatcow/speedometer.png', - 'type' => 'png', - ), - '/rsrc/image/facebook/icon/sandcastle.png' => - array( - 'hash' => '496a1c2e91ccb8332435491a7bbfa67d', - 'uri' => '/res/496a1c2e/rsrc/image/facebook/icon/sandcastle.png', - 'disk' => '/rsrc/image/facebook/icon/sandcastle.png', - 'type' => 'png', - ), '/rsrc/image/grippy_texture.png' => array( 'hash' => 'a8945e12ceeaddd5b491a8d81cfa19c1', @@ -701,69 +687,6 @@ celerity_register_resource_map(array( ), 'disk' => '/rsrc/css/application/diffusion/diffusion-source.css', ), - 'facebook-differential-core-view-css' => - array( - 'uri' => '/res/6053fa4a/rsrc/css/facebook/application/differential/core.css', - 'type' => 'css', - 'requires' => - array( - ), - 'disk' => '/rsrc/css/facebook/application/differential/core.css', - ), - 'facebook-example-css' => - array( - 'uri' => '/res/6ba49cd8/rsrc/css/facebook/application/example/example.css', - 'type' => 'css', - 'requires' => - array( - ), - 'disk' => '/rsrc/css/facebook/application/example/example.css', - ), - 'facebook-example-js' => - array( - 'uri' => '/res/31058d06/rsrc/js/facebook/application/example/example.js', - 'type' => 'js', - 'requires' => - array( - ), - 'disk' => '/rsrc/js/facebook/application/example/example.js', - ), - 'facebook-releeph-branch' => - array( - 'uri' => '/res/6b7eea98/rsrc/css/facebook/application/releeph/releeph-branch.css', - 'type' => 'css', - 'requires' => - array( - ), - 'disk' => '/rsrc/css/facebook/application/releeph/releeph-branch.css', - ), - 'facebook-releeph-core' => - array( - 'uri' => '/res/c3027f71/rsrc/css/facebook/application/releeph/releeph-core.css', - 'type' => 'css', - 'requires' => - array( - ), - 'disk' => '/rsrc/css/facebook/application/releeph/releeph-core.css', - ), - 'facebook-releeph-project' => - array( - 'uri' => '/res/497c0c11/rsrc/css/facebook/application/releeph/releeph-project.css', - 'type' => 'css', - 'requires' => - array( - ), - 'disk' => '/rsrc/css/facebook/application/releeph/releeph-project.css', - ), - 'facebook-releeph-request-typeahead-css' => - array( - 'uri' => '/res/2f4bab97/rsrc/css/facebook/application/releeph/request-typeahead.css', - 'type' => 'css', - 'requires' => - array( - ), - 'disk' => '/rsrc/css/facebook/application/releeph/request-typeahead.css', - ), 'files-css' => array( 'uri' => '/res/a265a77d/rsrc/css/application/files/files.css', @@ -856,7 +779,7 @@ celerity_register_resource_map(array( ), 'javelin-behavior-aphlict-listen' => array( - 'uri' => '/res/da96a861/rsrc/js/application/aphlict/behavior-aphlict-listen.js', + 'uri' => '/res/c716b386/rsrc/js/application/aphlict/behavior-aphlict-listen.js', 'type' => 'js', 'requires' => array( @@ -866,7 +789,8 @@ celerity_register_resource_map(array( 3 => 'javelin-request', 4 => 'javelin-uri', 5 => 'javelin-dom', - 6 => 'phabricator-notification', + 6 => 'javelin-json', + 7 => 'phabricator-notification', ), 'disk' => '/rsrc/js/application/aphlict/behavior-aphlict-listen.js', ), @@ -1239,25 +1163,6 @@ celerity_register_resource_map(array( ), 'disk' => '/rsrc/js/application/core/behavior-error-log.js', ), - 'javelin-behavior-facebook-releeph-request-typeahead' => - array( - 'uri' => '/res/585eff76/rsrc/js/facebook/application/releeph/request-typeahead.js', - 'type' => 'js', - 'requires' => - array( - 0 => 'javelin-behavior', - 1 => 'javelin-util', - 2 => 'javelin-dom', - 3 => 'javelin-typeahead', - 4 => 'javelin-tokenizer', - 5 => 'javelin-typeahead-preloaded-source', - 6 => 'javelin-typeahead-ondemand-source', - 7 => 'javelin-dom', - 8 => 'javelin-stratcom', - 9 => 'javelin-util', - ), - 'disk' => '/rsrc/js/facebook/application/releeph/request-typeahead.js', - ), 'javelin-behavior-fancy-datepicker' => array( 'uri' => '/res/b2d89e4c/rsrc/js/application/core/behavior-fancy-datepicker.js', @@ -2292,7 +2197,7 @@ celerity_register_resource_map(array( ), 'phabricator-notification-css' => array( - 'uri' => '/res/7452322a/rsrc/css/aphront/notification.css', + 'uri' => '/res/1ed48691/rsrc/css/aphront/notification.css', 'type' => 'css', 'requires' => array( diff --git a/src/docs/userguide/notifications.diviner b/src/docs/userguide/notifications.diviner index f0a9e71a79..f94828c541 100644 --- a/src/docs/userguide/notifications.diviner +++ b/src/docs/userguide/notifications.diviner @@ -76,8 +76,9 @@ You can run `aphlict` in the foreground to get output to your console: phabricator/ $ ./bin/aphlict --foreground -This may help identify and resolve problems. +You can set `notification.debug` in your configuration to get additional +output in your browser. The server also generates a log, by default in `/var/log/aphlict.log`. You can change this location by changing `notification.log` in your configuration. The -log may contain information useful in resolving issues. +log may contain information useful in resolving issues. \ No newline at end of file diff --git a/src/view/page/PhabricatorStandardPageView.php b/src/view/page/PhabricatorStandardPageView.php index 52b9e27bb8..cdc21e0dcb 100644 --- a/src/view/page/PhabricatorStandardPageView.php +++ b/src/view/page/PhabricatorStandardPageView.php @@ -394,16 +394,20 @@ final class PhabricatorStandardPageView extends AphrontPageView { $client_uri = PhabricatorEnv::getEnvConfig('notification.client-uri'); $client_uri = new PhutilURI($client_uri); if ($client_uri->getDomain() == 'localhost') { - $this_host = new PhutilURI($this->getRequest()->getHost()); + $this_host = $this->getRequest()->getHost(); + $this_host = new PhutilURI('http://'.$this_host.'/'); $client_uri->setDomain($this_host->getDomain()); } + $enable_debug = PhabricatorEnv::getEnvConfig('notification.debug'); + Javelin::initBehavior( 'aphlict-listen', array( 'id' => $aphlict_object_id, 'server' => $client_uri->getDomain(), 'port' => $client_uri->getPort(), + 'debug' => $enable_debug, 'pageObjects' => array_fill_keys($this->pageObjects, true), )); diff --git a/support/aphlict/client/src/Aphlict.as b/support/aphlict/client/src/Aphlict.as index 13172cced1..14eb9548db 100644 --- a/support/aphlict/client/src/Aphlict.as +++ b/support/aphlict/client/src/Aphlict.as @@ -37,7 +37,6 @@ package { this.remotePort = port; this.connectToServer(); - return; } diff --git a/support/aphlict/server/aphlict_server.js b/support/aphlict/server/aphlict_server.js index 3be6965ed7..26be15dc45 100755 --- a/support/aphlict/server/aphlict_server.js +++ b/support/aphlict/server/aphlict_server.js @@ -51,17 +51,25 @@ var querystring = require('querystring'); var fs = require('fs'); // set up log file -var logfile = fs.createWriteStream(config.log, - { flags: 'a', - encoding: null, - mode: 0666 }); -logfile.write('----- ' + (new Date()).toLocaleString() + ' -----\n'); +var logfile = fs.createWriteStream( + config.log, + { + flags: 'a', + encoding: null, + mode: 0666 + }); function log(str) { - console.log(str); - logfile.write(str + '\n'); + console.log(str); + logfile.write(str + '\n'); } +process.on('uncaughtException', function (err) { + log("\n<<< UNCAUGHT EXCEPTION! >>>\n\n" + err); + process.exit(1); +}); + +log('----- ' + (new Date()).toLocaleString() + ' -----\n'); function getFlashPolicy() { return [ @@ -75,9 +83,10 @@ function getFlashPolicy() { } net.createServer(function(socket) { - socket.on('data', function() { - socket.write(getFlashPolicy() + '\0'); - }); + socket.write(getFlashPolicy() + '\0'); + socket.end(); + + log('[' + socket.remoteAddress + '] Sent Flash Policy'); socket.on('error', function (e) { log('Error in policy server: ' + e); @@ -85,7 +94,6 @@ net.createServer(function(socket) { }).listen(843); - function write_json(socket, data) { var serial = JSON.stringify(data); var length = Buffer.byteLength(serial, 'utf8'); @@ -118,32 +126,33 @@ function generate_id() { var send_server = net.createServer(function(socket) { var client_id = generate_id(); + var client_name = '[' + socket.remoteAddress + '] [#' + client_id + '] '; socket.on('connect', function() { clients[client_id] = socket; current_connections++; - log(client_id + ': connected\t\t(' + log(client_name + 'connected\t\t(' + current_connections + ' current connections)'); }); socket.on('close', function() { delete clients[client_id]; current_connections--; - log(client_id + ': closed\t\t(' + log(client_name + 'closed\t\t(' + current_connections + ' current connections)'); }); socket.on('timeout', function() { - log(client_id + ': timed out!'); + log(client_name + 'timed out!'); }); socket.on('end', function() { - log(client_id + ': ended the connection'); + log(client_name + 'ended the connection'); // node automatically closes half-open connections }); socket.on('error', function (e) { - log('Uncaught error in send server: ' + e); + log(cliient_name + 'Uncaught error in send server: ' + e); }); }).listen(config.port); diff --git a/webroot/rsrc/css/aphront/notification.css b/webroot/rsrc/css/aphront/notification.css index 39551864c5..156aa85d32 100644 --- a/webroot/rsrc/css/aphront/notification.css +++ b/webroot/rsrc/css/aphront/notification.css @@ -31,3 +31,8 @@ background: #ffffa0; border: 1px solid #aaaa60; } + +.jx-notification-debug { + background: #ffa0ff; + border: 1px solid #aa60aa; +} diff --git a/webroot/rsrc/js/application/aphlict/behavior-aphlict-listen.js b/webroot/rsrc/js/application/aphlict/behavior-aphlict-listen.js index 309b28a6e8..dcfa4b8758 100644 --- a/webroot/rsrc/js/application/aphlict/behavior-aphlict-listen.js +++ b/webroot/rsrc/js/application/aphlict/behavior-aphlict-listen.js @@ -6,6 +6,7 @@ * javelin-request * javelin-uri * javelin-dom + * javelin-json * phabricator-notification */ @@ -23,17 +24,23 @@ JX.behavior('aphlict-listen', function(config) { // Respond to a notification from the Aphlict notification server. We send // a request to Phabricator to get notification details. function onaphlictmessage(type, message) { - if (!message) { - return; - } + if (type == 'receive') { + var request = new JX.Request('/notification/individual/', onnotification) + .addData({key: message.key}) + .send(); + } else if (__DEV__) { + if (config.debug) { + var details = message + ? JX.JSON.stringify(message) + : ''; - if (type != 'receive') { - return; + new JX.Notification() + .setContent('(Aphlict) [' + type + '] ' + details) + .setClassName('jx-notification-debug') + .setDuration(0) + .show(); + } } - - var request = new JX.Request('/notification/individual/', onnotification) - .addData({key: message.key}) - .send(); }