diff --git a/src/applications/conduit/application/PhabricatorConduitApplication.php b/src/applications/conduit/application/PhabricatorConduitApplication.php --- a/src/applications/conduit/application/PhabricatorConduitApplication.php +++ b/src/applications/conduit/application/PhabricatorConduitApplication.php @@ -46,16 +46,20 @@ public function getRoutes() { return array( '/conduit/' => array( - '(?:query/(?P<queryKey>[^/]+)/)?' => 'PhabricatorConduitListController', + $this->getQueryRoutePattern() => 'PhabricatorConduitListController', 'method/(?P<method>[^/]+)/' => 'PhabricatorConduitConsoleController', - 'log/(?:query/(?P<queryKey>[^/]+)/)?' => - 'PhabricatorConduitLogController', - 'log/view/(?P<view>[^/]+)/' => 'PhabricatorConduitLogController', - 'token/' => 'PhabricatorConduitTokenController', - 'token/edit/(?:(?P<id>\d+)/)?' => - 'PhabricatorConduitTokenEditController', - 'token/terminate/(?:(?P<id>\d+)/)?' => - 'PhabricatorConduitTokenTerminateController', + 'log/' => array( + $this->getQueryRoutePattern() => + 'PhabricatorConduitLogController', + 'view/(?P<view>[^/]+)/' => 'PhabricatorConduitLogController', + ), + 'token/' => array( + '' => 'PhabricatorConduitTokenController', + 'edit/(?:(?P<id>\d+)/)?' => + 'PhabricatorConduitTokenEditController', + 'terminate/(?:(?P<id>\d+)/)?' => + 'PhabricatorConduitTokenTerminateController', + ), 'login/' => 'PhabricatorConduitTokenHandshakeController', ), '/api/(?P<method>[^/]+)' => 'PhabricatorConduitAPIController', diff --git a/src/applications/conduit/query/PhabricatorConduitLogQuery.php b/src/applications/conduit/query/PhabricatorConduitLogQuery.php --- a/src/applications/conduit/query/PhabricatorConduitLogQuery.php +++ b/src/applications/conduit/query/PhabricatorConduitLogQuery.php @@ -6,6 +6,8 @@ private $callerPHIDs; private $methods; private $methodStatuses; + private $epochMin; + private $epochMax; public function withCallerPHIDs(array $phids) { $this->callerPHIDs = $phids; @@ -22,6 +24,12 @@ return $this; } + public function withEpochBetween($epoch_min, $epoch_max) { + $this->epochMin = $epoch_min; + $this->epochMax = $epoch_max; + return $this; + } + public function newResultObject() { return new PhabricatorConduitMethodCallLog(); } @@ -72,6 +80,20 @@ $method_names); } + if ($this->epochMin !== null) { + $where[] = qsprintf( + $conn, + 'dateCreated >= %d', + $this->epochMin); + } + + if ($this->epochMax !== null) { + $where[] = qsprintf( + $conn, + 'dateCreated <= %d', + $this->epochMax); + } + return $where; } diff --git a/src/applications/conduit/query/PhabricatorConduitLogSearchEngine.php b/src/applications/conduit/query/PhabricatorConduitLogSearchEngine.php --- a/src/applications/conduit/query/PhabricatorConduitLogSearchEngine.php +++ b/src/applications/conduit/query/PhabricatorConduitLogSearchEngine.php @@ -34,6 +34,12 @@ $query->withMethodStatuses($map['statuses']); } + if ($map['epochMin'] || $map['epochMax']) { + $query->withEpochBetween( + $map['epochMin'], + $map['epochMax']); + } + return $query; } @@ -55,6 +61,12 @@ ->setDescription( pht('Find calls to stable, unstable, or deprecated methods.')) ->setOptions(ConduitAPIMethod::getMethodStatusMap()), + id(new PhabricatorSearchDateField()) + ->setLabel(pht('Called After')) + ->setKey('epochMin'), + id(new PhabricatorSearchDateField()) + ->setLabel(pht('Called Before')) + ->setKey('epochMax'), ); } @@ -106,6 +118,62 @@ return parent::buildSavedQueryFromBuiltin($query_key); } + protected function newExportFields() { + $viewer = $this->requireViewer(); + + return array( + id(new PhabricatorPHIDExportField()) + ->setKey('callerPHID') + ->setLabel(pht('Caller PHID')), + id(new PhabricatorStringExportField()) + ->setKey('caller') + ->setLabel(pht('Caller')), + id(new PhabricatorStringExportField()) + ->setKey('method') + ->setLabel(pht('Method')), + id(new PhabricatorIntExportField()) + ->setKey('duration') + ->setLabel(pht('Call Duration (us)')), + id(new PhabricatorStringExportField()) + ->setKey('error') + ->setLabel(pht('Error')), + ); + } + + protected function newExportData(array $logs) { + $viewer = $this->requireViewer(); + + $phids = array(); + foreach ($logs as $log) { + if ($log->getCallerPHID()) { + $phids[] = $log->getCallerPHID(); + } + } + $handles = $viewer->loadHandles($phids); + + $export = array(); + foreach ($logs as $log) { + $caller_phid = $log->getCallerPHID(); + if ($caller_phid) { + $caller_name = $handles[$caller_phid]->getName(); + } else { + $caller_name = null; + } + + $map = array( + 'callerPHID' => $caller_phid, + 'caller' => $caller_name, + 'method' => $log->getMethod(), + 'duration' => (int)$log->getDuration(), + 'error' => $log->getError(), + ); + + $export[] = $map; + } + + return $export; + } + protected function renderResultList( array $logs, PhabricatorSavedQuery $query,