@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+103 -9
+13 -9
src/applications/conduit/application/PhabricatorConduitApplication.php
··· 46 46 public function getRoutes() { 47 47 return array( 48 48 '/conduit/' => array( 49 - '(?:query/(?P<queryKey>[^/]+)/)?' => 'PhabricatorConduitListController', 49 + $this->getQueryRoutePattern() => 'PhabricatorConduitListController', 50 50 'method/(?P<method>[^/]+)/' => 'PhabricatorConduitConsoleController', 51 - 'log/(?:query/(?P<queryKey>[^/]+)/)?' => 52 - 'PhabricatorConduitLogController', 53 - 'log/view/(?P<view>[^/]+)/' => 'PhabricatorConduitLogController', 54 - 'token/' => 'PhabricatorConduitTokenController', 55 - 'token/edit/(?:(?P<id>\d+)/)?' => 56 - 'PhabricatorConduitTokenEditController', 57 - 'token/terminate/(?:(?P<id>\d+)/)?' => 58 - 'PhabricatorConduitTokenTerminateController', 51 + 'log/' => array( 52 + $this->getQueryRoutePattern() => 53 + 'PhabricatorConduitLogController', 54 + 'view/(?P<view>[^/]+)/' => 'PhabricatorConduitLogController', 55 + ), 56 + 'token/' => array( 57 + '' => 'PhabricatorConduitTokenController', 58 + 'edit/(?:(?P<id>\d+)/)?' => 59 + 'PhabricatorConduitTokenEditController', 60 + 'terminate/(?:(?P<id>\d+)/)?' => 61 + 'PhabricatorConduitTokenTerminateController', 62 + ), 59 63 'login/' => 'PhabricatorConduitTokenHandshakeController', 60 64 ), 61 65 '/api/(?P<method>[^/]+)' => 'PhabricatorConduitAPIController',
+22
src/applications/conduit/query/PhabricatorConduitLogQuery.php
··· 6 6 private $callerPHIDs; 7 7 private $methods; 8 8 private $methodStatuses; 9 + private $epochMin; 10 + private $epochMax; 9 11 10 12 public function withCallerPHIDs(array $phids) { 11 13 $this->callerPHIDs = $phids; ··· 19 21 20 22 public function withMethodStatuses(array $statuses) { 21 23 $this->methodStatuses = $statuses; 24 + return $this; 25 + } 26 + 27 + public function withEpochBetween($epoch_min, $epoch_max) { 28 + $this->epochMin = $epoch_min; 29 + $this->epochMax = $epoch_max; 22 30 return $this; 23 31 } 24 32 ··· 70 78 $conn, 71 79 'method IN (%Ls)', 72 80 $method_names); 81 + } 82 + 83 + if ($this->epochMin !== null) { 84 + $where[] = qsprintf( 85 + $conn, 86 + 'dateCreated >= %d', 87 + $this->epochMin); 88 + } 89 + 90 + if ($this->epochMax !== null) { 91 + $where[] = qsprintf( 92 + $conn, 93 + 'dateCreated <= %d', 94 + $this->epochMax); 73 95 } 74 96 75 97 return $where;
+68
src/applications/conduit/query/PhabricatorConduitLogSearchEngine.php
··· 34 34 $query->withMethodStatuses($map['statuses']); 35 35 } 36 36 37 + if ($map['epochMin'] || $map['epochMax']) { 38 + $query->withEpochBetween( 39 + $map['epochMin'], 40 + $map['epochMax']); 41 + } 42 + 37 43 return $query; 38 44 } 39 45 ··· 55 61 ->setDescription( 56 62 pht('Find calls to stable, unstable, or deprecated methods.')) 57 63 ->setOptions(ConduitAPIMethod::getMethodStatusMap()), 64 + id(new PhabricatorSearchDateField()) 65 + ->setLabel(pht('Called After')) 66 + ->setKey('epochMin'), 67 + id(new PhabricatorSearchDateField()) 68 + ->setLabel(pht('Called Before')) 69 + ->setKey('epochMax'), 58 70 ); 59 71 } 60 72 ··· 104 116 } 105 117 106 118 return parent::buildSavedQueryFromBuiltin($query_key); 119 + } 120 + 121 + protected function newExportFields() { 122 + $viewer = $this->requireViewer(); 123 + 124 + return array( 125 + id(new PhabricatorPHIDExportField()) 126 + ->setKey('callerPHID') 127 + ->setLabel(pht('Caller PHID')), 128 + id(new PhabricatorStringExportField()) 129 + ->setKey('caller') 130 + ->setLabel(pht('Caller')), 131 + id(new PhabricatorStringExportField()) 132 + ->setKey('method') 133 + ->setLabel(pht('Method')), 134 + id(new PhabricatorIntExportField()) 135 + ->setKey('duration') 136 + ->setLabel(pht('Call Duration (us)')), 137 + id(new PhabricatorStringExportField()) 138 + ->setKey('error') 139 + ->setLabel(pht('Error')), 140 + ); 141 + } 142 + 143 + protected function newExportData(array $logs) { 144 + $viewer = $this->requireViewer(); 145 + 146 + $phids = array(); 147 + foreach ($logs as $log) { 148 + if ($log->getCallerPHID()) { 149 + $phids[] = $log->getCallerPHID(); 150 + } 151 + } 152 + $handles = $viewer->loadHandles($phids); 153 + 154 + $export = array(); 155 + foreach ($logs as $log) { 156 + $caller_phid = $log->getCallerPHID(); 157 + if ($caller_phid) { 158 + $caller_name = $handles[$caller_phid]->getName(); 159 + } else { 160 + $caller_name = null; 161 + } 162 + 163 + $map = array( 164 + 'callerPHID' => $caller_phid, 165 + 'caller' => $caller_name, 166 + 'method' => $log->getMethod(), 167 + 'duration' => (int)$log->getDuration(), 168 + 'error' => $log->getError(), 169 + ); 170 + 171 + $export[] = $map; 172 + } 173 + 174 + return $export; 107 175 } 108 176 109 177 protected function renderResultList(