mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +01:00
Allow Conduit method call logs to be exported with the standard export pipeline
Summary: See PHI1026. Allow installs to export Conduit call logs to a flat format. Also, add date range queries. Test Plan: - Exported some call logs. - Filtered logs by date. Reviewers: amckinley Reviewed By: amckinley Differential Revision: https://secure.phabricator.com/D19996
This commit is contained in:
parent
6bb31de305
commit
e6ca2b998f
3 changed files with 103 additions and 9 deletions
|
@ -46,16 +46,20 @@ final class PhabricatorConduitApplication extends PhabricatorApplication {
|
|||
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',
|
||||
|
|
|
@ -6,6 +6,8 @@ final class PhabricatorConduitLogQuery
|
|||
private $callerPHIDs;
|
||||
private $methods;
|
||||
private $methodStatuses;
|
||||
private $epochMin;
|
||||
private $epochMax;
|
||||
|
||||
public function withCallerPHIDs(array $phids) {
|
||||
$this->callerPHIDs = $phids;
|
||||
|
@ -22,6 +24,12 @@ final class PhabricatorConduitLogQuery
|
|||
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 @@ final class PhabricatorConduitLogQuery
|
|||
$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;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,12 @@ final class PhabricatorConduitLogSearchEngine
|
|||
$query->withMethodStatuses($map['statuses']);
|
||||
}
|
||||
|
||||
if ($map['epochMin'] || $map['epochMax']) {
|
||||
$query->withEpochBetween(
|
||||
$map['epochMin'],
|
||||
$map['epochMax']);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
@ -55,6 +61,12 @@ final class PhabricatorConduitLogSearchEngine
|
|||
->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 @@ final class PhabricatorConduitLogSearchEngine
|
|||
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,
|
||||
|
|
Loading…
Reference in a new issue