mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-03 03:11:01 +01:00
Use events rather than Conduit to report daemon status in Phabricator
Summary: Ref T1670. Use events and direct database writes instead of Conduit. Deprecate the Conduit methods. Test Plan: Ran daemons, used the console to review daemon event logs. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T1670 Differential Revision: https://secure.phabricator.com/D6536
This commit is contained in:
parent
9e0a299b06
commit
794dc0151a
8 changed files with 125 additions and 5 deletions
|
@ -1023,6 +1023,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorDaemonConsoleController' => 'applications/daemon/controller/PhabricatorDaemonConsoleController.php',
|
'PhabricatorDaemonConsoleController' => 'applications/daemon/controller/PhabricatorDaemonConsoleController.php',
|
||||||
'PhabricatorDaemonController' => 'applications/daemon/controller/PhabricatorDaemonController.php',
|
'PhabricatorDaemonController' => 'applications/daemon/controller/PhabricatorDaemonController.php',
|
||||||
'PhabricatorDaemonDAO' => 'infrastructure/daemon/storage/PhabricatorDaemonDAO.php',
|
'PhabricatorDaemonDAO' => 'infrastructure/daemon/storage/PhabricatorDaemonDAO.php',
|
||||||
|
'PhabricatorDaemonEventListener' => 'applications/daemon/event/PhabricatorDaemonEventListener.php',
|
||||||
'PhabricatorDaemonLog' => 'infrastructure/daemon/storage/PhabricatorDaemonLog.php',
|
'PhabricatorDaemonLog' => 'infrastructure/daemon/storage/PhabricatorDaemonLog.php',
|
||||||
'PhabricatorDaemonLogEvent' => 'infrastructure/daemon/storage/PhabricatorDaemonLogEvent.php',
|
'PhabricatorDaemonLogEvent' => 'infrastructure/daemon/storage/PhabricatorDaemonLogEvent.php',
|
||||||
'PhabricatorDaemonLogEventsView' => 'applications/daemon/view/PhabricatorDaemonLogEventsView.php',
|
'PhabricatorDaemonLogEventsView' => 'applications/daemon/view/PhabricatorDaemonLogEventsView.php',
|
||||||
|
@ -3026,6 +3027,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorDaemonConsoleController' => 'PhabricatorDaemonController',
|
'PhabricatorDaemonConsoleController' => 'PhabricatorDaemonController',
|
||||||
'PhabricatorDaemonController' => 'PhabricatorController',
|
'PhabricatorDaemonController' => 'PhabricatorController',
|
||||||
'PhabricatorDaemonDAO' => 'PhabricatorLiskDAO',
|
'PhabricatorDaemonDAO' => 'PhabricatorLiskDAO',
|
||||||
|
'PhabricatorDaemonEventListener' => 'PhutilEventListener',
|
||||||
'PhabricatorDaemonLog' => 'PhabricatorDaemonDAO',
|
'PhabricatorDaemonLog' => 'PhabricatorDaemonDAO',
|
||||||
'PhabricatorDaemonLogEvent' => 'PhabricatorDaemonDAO',
|
'PhabricatorDaemonLogEvent' => 'PhabricatorDaemonDAO',
|
||||||
'PhabricatorDaemonLogEventsView' => 'AphrontView',
|
'PhabricatorDaemonLogEventsView' => 'AphrontView',
|
||||||
|
|
|
@ -30,6 +30,12 @@ final class PhabricatorApplicationDaemons extends PhabricatorApplication {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getEventListeners() {
|
||||||
|
return array(
|
||||||
|
new PhabricatorDaemonEventListener(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function getRoutes() {
|
public function getRoutes() {
|
||||||
return array(
|
return array(
|
||||||
'/daemon/' => array(
|
'/daemon/' => array(
|
||||||
|
|
|
@ -5,8 +5,11 @@
|
||||||
*/
|
*/
|
||||||
final class ConduitAPI_daemon_launched_Method extends ConduitAPIMethod {
|
final class ConduitAPI_daemon_launched_Method extends ConduitAPIMethod {
|
||||||
|
|
||||||
|
public function getMethodStatus() {
|
||||||
|
return self::METHOD_STATUS_DEPRECATED;
|
||||||
|
}
|
||||||
|
|
||||||
public function shouldRequireAuthentication() {
|
public function shouldRequireAuthentication() {
|
||||||
// TODO: Lock this down once we build phantoms.
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,11 @@
|
||||||
*/
|
*/
|
||||||
final class ConduitAPI_daemon_log_Method extends ConduitAPIMethod {
|
final class ConduitAPI_daemon_log_Method extends ConduitAPIMethod {
|
||||||
|
|
||||||
|
public function getMethodStatus() {
|
||||||
|
return self::METHOD_STATUS_DEPRECATED;
|
||||||
|
}
|
||||||
|
|
||||||
public function shouldRequireAuthentication() {
|
public function shouldRequireAuthentication() {
|
||||||
// TODO: Lock this down once we build phantoms.
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,11 @@
|
||||||
*/
|
*/
|
||||||
final class ConduitAPI_daemon_setstatus_Method extends ConduitAPIMethod {
|
final class ConduitAPI_daemon_setstatus_Method extends ConduitAPIMethod {
|
||||||
|
|
||||||
|
public function getMethodStatus() {
|
||||||
|
return self::METHOD_STATUS_DEPRECATED;
|
||||||
|
}
|
||||||
|
|
||||||
public function shouldRequireAuthentication() {
|
public function shouldRequireAuthentication() {
|
||||||
// TODO: Lock this down once we build phantoms.
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
104
src/applications/daemon/event/PhabricatorDaemonEventListener.php
Normal file
104
src/applications/daemon/event/PhabricatorDaemonEventListener.php
Normal file
|
@ -0,0 +1,104 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorDaemonEventListener extends PhutilEventListener {
|
||||||
|
|
||||||
|
private $daemons = array();
|
||||||
|
|
||||||
|
public function register() {
|
||||||
|
$this->listen(PhutilDaemonOverseer::EVENT_DID_LAUNCH);
|
||||||
|
$this->listen(PhutilDaemonOverseer::EVENT_DID_LOG);
|
||||||
|
$this->listen(PhutilDaemonOverseer::EVENT_DID_HEARTBEAT);
|
||||||
|
$this->listen(PhutilDaemonOverseer::EVENT_WILL_EXIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handleEvent(PhutilEvent $event) {
|
||||||
|
switch ($event->getType()) {
|
||||||
|
case PhutilDaemonOverseer::EVENT_DID_LAUNCH:
|
||||||
|
$this->handleLaunchEvent($event);
|
||||||
|
break;
|
||||||
|
case PhutilDaemonOverseer::EVENT_DID_HEARTBEAT:
|
||||||
|
$this->handleHeartbeatEvent($event);
|
||||||
|
break;
|
||||||
|
case PhutilDaemonOverseer::EVENT_DID_LOG:
|
||||||
|
$this->handleLogEvent($event);
|
||||||
|
break;
|
||||||
|
case PhutilDaemonOverseer::EVENT_WILL_EXIT:
|
||||||
|
$this->handleExitEvent($event);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function handleLaunchEvent(PhutilEvent $event) {
|
||||||
|
$id = $event->getValue('id');
|
||||||
|
|
||||||
|
$daemon = id(new PhabricatorDaemonLog())
|
||||||
|
->setDaemon($event->getValue('daemonClass'))
|
||||||
|
->setHost(php_uname('n'))
|
||||||
|
->setPID(getmypid())
|
||||||
|
->setStatus(PhabricatorDaemonLog::STATUS_RUNNING)
|
||||||
|
->setArgv($event->getValue('argv'))
|
||||||
|
->save();
|
||||||
|
|
||||||
|
$this->daemons[$id] = $daemon;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function handleHeartbeatEvent(PhutilEvent $event) {
|
||||||
|
$daemon = $this->getDaemon($event->getValue('id'));
|
||||||
|
|
||||||
|
// Just update the timestamp.
|
||||||
|
$daemon->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function handleLogEvent(PhutilEvent $event) {
|
||||||
|
$daemon = $this->getDaemon($event->getValue('id'));
|
||||||
|
|
||||||
|
// TODO: This is a bit awkward for historical reasons, clean it up after
|
||||||
|
// removing Conduit.
|
||||||
|
$message = $event->getValue('message');
|
||||||
|
$context = $event->getValue('context');
|
||||||
|
if (strlen($context) && $context !== $message) {
|
||||||
|
$message = "({$context}) {$message}";
|
||||||
|
}
|
||||||
|
|
||||||
|
$type = $event->getValue('type');
|
||||||
|
|
||||||
|
$message = phutil_utf8ize($message);
|
||||||
|
|
||||||
|
id(new PhabricatorDaemonLogEvent())
|
||||||
|
->setLogID($daemon->getID())
|
||||||
|
->setLogType($type)
|
||||||
|
->setMessage((string)$message)
|
||||||
|
->setEpoch(time())
|
||||||
|
->save();
|
||||||
|
|
||||||
|
switch ($type) {
|
||||||
|
case 'WAIT':
|
||||||
|
$current_status = PhabricatorDaemonLog::STATUS_WAIT;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$current_status = PhabricatorDaemonLog::STATUS_RUNNING;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($current_status !== $daemon->getStatus()) {
|
||||||
|
$daemon->setStatus($current_status)->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function handleExitEvent(PhutilEvent $event) {
|
||||||
|
$id = $event->getValue('id');
|
||||||
|
|
||||||
|
$daemon = $this->getDaemon($id);
|
||||||
|
$daemon->setStatus(PhabricatorDaemonLog::STATUS_EXITED)->save();
|
||||||
|
|
||||||
|
unset($this->daemons[$id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getDaemon($id) {
|
||||||
|
if (isset($this->daemons[$id])) {
|
||||||
|
return $this->daemons[$id];
|
||||||
|
}
|
||||||
|
throw new Exception("No such daemon '{$id}'!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -131,8 +131,6 @@ abstract class PhabricatorDaemonManagementWorkflow
|
||||||
$flags[] = '--daemonize';
|
$flags[] = '--daemonize';
|
||||||
}
|
}
|
||||||
|
|
||||||
$flags[] = csprintf('--conduit-uri=%s', PhabricatorEnv::getURI('/api/'));
|
|
||||||
|
|
||||||
if (!$debug) {
|
if (!$debug) {
|
||||||
$log_file = $this->getLogDirectory().'/daemons.log';
|
$log_file = $this->getLogDirectory().'/daemons.log';
|
||||||
$flags[] = csprintf('--log=%s', $log_file);
|
$flags[] = csprintf('--log=%s', $log_file);
|
||||||
|
|
|
@ -5,6 +5,7 @@ final class PhabricatorDaemonLog extends PhabricatorDaemonDAO {
|
||||||
const STATUS_UNKNOWN = 'unknown';
|
const STATUS_UNKNOWN = 'unknown';
|
||||||
const STATUS_RUNNING = 'run';
|
const STATUS_RUNNING = 'run';
|
||||||
const STATUS_DEAD = 'dead';
|
const STATUS_DEAD = 'dead';
|
||||||
|
const STATUS_WAIT = 'wait';
|
||||||
const STATUS_EXITED = 'exit';
|
const STATUS_EXITED = 'exit';
|
||||||
|
|
||||||
protected $daemon;
|
protected $daemon;
|
||||||
|
|
Loading…
Reference in a new issue