mirror of
https://we.phorge.it/source/phorge.git
synced 2025-04-06 01:18:25 +02:00
Make Multimeter sample browsing UI a bit more useful
Summary: Ref T6930. Just iterating on this a bit: add some column grouping stuff so you can slice results apart and figure out where they came from. Test Plan: {F389632} Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T6930 Differential Revision: https://secure.phabricator.com/D12626
This commit is contained in:
parent
7b6c320e15
commit
7d5bcd43ba
1 changed files with 121 additions and 12 deletions
|
@ -9,29 +9,94 @@ final class MultimeterSampleController extends MultimeterController {
|
||||||
public function handleRequest(AphrontRequest $request) {
|
public function handleRequest(AphrontRequest $request) {
|
||||||
$viewer = $this->getViewer();
|
$viewer = $this->getViewer();
|
||||||
|
|
||||||
|
$group_map = array(
|
||||||
|
'type' => 'eventType',
|
||||||
|
'host' => 'eventHostID',
|
||||||
|
'context' => 'eventContextID',
|
||||||
|
'viewer' => 'eventViewerID',
|
||||||
|
'request' => 'requestKey',
|
||||||
|
'label' => 'eventLabelID',
|
||||||
|
);
|
||||||
|
|
||||||
|
$group = explode('.', $request->getStr('group'));
|
||||||
|
$group = array_intersect($group, array_keys($group_map));
|
||||||
|
$group = array_fuse($group);
|
||||||
|
|
||||||
|
if (empty($group['type'])) {
|
||||||
|
$group['type'] = 'type';
|
||||||
|
}
|
||||||
|
|
||||||
|
$now = PhabricatorTime::getNow();
|
||||||
|
$ago = ($now - phutil_units('24 hours in seconds'));
|
||||||
|
|
||||||
$table = new MultimeterEvent();
|
$table = new MultimeterEvent();
|
||||||
$conn = $table->establishConnection('r');
|
$conn = $table->establishConnection('r');
|
||||||
$data = queryfx_all(
|
$data = queryfx_all(
|
||||||
$conn,
|
$conn,
|
||||||
'SELECT * FROM %T ORDER BY id DESC LIMIT 100',
|
'SELECT *, count(*) N, SUM(sampleRate * resourceCost) as totalCost
|
||||||
$table->getTableName());
|
FROM %T
|
||||||
|
WHERE epoch >= %d AND epoch <= %d
|
||||||
|
GROUP BY %Q
|
||||||
|
ORDER BY totalCost DESC, MAX(id) DESC
|
||||||
|
LIMIT 100',
|
||||||
|
$table->getTableName(),
|
||||||
|
$ago,
|
||||||
|
$now,
|
||||||
|
implode(', ', array_select_keys($group_map, $group)));
|
||||||
|
|
||||||
$this->loadDimensions($data);
|
$this->loadDimensions($data);
|
||||||
|
|
||||||
$rows = array();
|
$rows = array();
|
||||||
foreach ($data as $row) {
|
foreach ($data as $row) {
|
||||||
|
|
||||||
|
if (isset($group['request'])) {
|
||||||
|
$request_col = $row['requestKey'];
|
||||||
|
} else {
|
||||||
|
$request_col = $this->renderGroupingLink($group, 'request');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($group['viewer'])) {
|
||||||
|
$viewer_col = $this->getViewerDimension($row['eventViewerID'])
|
||||||
|
->getName();
|
||||||
|
} else {
|
||||||
|
$viewer_col = $this->renderGroupingLink($group, 'viewer');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($group['context'])) {
|
||||||
|
$context_col = $this->getContextDimension($row['eventContextID'])
|
||||||
|
->getName();
|
||||||
|
} else {
|
||||||
|
$context_col = $this->renderGroupingLink($group, 'context');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($group['host'])) {
|
||||||
|
$host_col = $this->getHostDimension($row['eventHostID'])
|
||||||
|
->getName();
|
||||||
|
} else {
|
||||||
|
$host_col = $this->renderGroupingLink($group, 'host');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($group['label'])) {
|
||||||
|
$label_col = $this->getLabelDimension($row['eventLabelID'])
|
||||||
|
->getName();
|
||||||
|
} else {
|
||||||
|
$label_col = $this->renderGroupingLink($group, 'label');
|
||||||
|
}
|
||||||
|
|
||||||
$rows[] = array(
|
$rows[] = array(
|
||||||
$row['id'],
|
($row['N'] == 1)
|
||||||
$row['requestKey'],
|
? $row['id']
|
||||||
$this->getViewerDimension($row['eventViewerID'])->getName(),
|
: pht('%s Events', new PhutilNumber($row['N'])),
|
||||||
$this->getContextDimension($row['eventContextID'])->getName(),
|
$request_col,
|
||||||
$this->getHostDimension($row['eventHostID'])->getName(),
|
$viewer_col,
|
||||||
|
$context_col,
|
||||||
|
$host_col,
|
||||||
MultimeterEvent::getEventTypeName($row['eventType']),
|
MultimeterEvent::getEventTypeName($row['eventType']),
|
||||||
$this->getLabelDimension($row['eventLabelID'])->getName(),
|
$label_col,
|
||||||
MultimeterEvent::formatResourceCost(
|
MultimeterEvent::formatResourceCost(
|
||||||
$viewer,
|
$viewer,
|
||||||
$row['eventType'],
|
$row['eventType'],
|
||||||
$row['resourceCost']),
|
$row['totalCost']),
|
||||||
$row['sampleRate'],
|
$row['sampleRate'],
|
||||||
phabricator_datetime($row['epoch'], $viewer),
|
phabricator_datetime($row['epoch'], $viewer),
|
||||||
);
|
);
|
||||||
|
@ -53,7 +118,7 @@ final class MultimeterSampleController extends MultimeterController {
|
||||||
))
|
))
|
||||||
->setColumnClasses(
|
->setColumnClasses(
|
||||||
array(
|
array(
|
||||||
null,
|
'n',
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
|
@ -66,11 +131,34 @@ final class MultimeterSampleController extends MultimeterController {
|
||||||
));
|
));
|
||||||
|
|
||||||
$box = id(new PHUIObjectBoxView())
|
$box = id(new PHUIObjectBoxView())
|
||||||
->setHeaderText(pht('Samples'))
|
->setHeaderText(
|
||||||
|
pht(
|
||||||
|
'Samples (%s - %s)',
|
||||||
|
phabricator_datetime($ago, $viewer),
|
||||||
|
phabricator_datetime($now, $viewer)))
|
||||||
->appendChild($table);
|
->appendChild($table);
|
||||||
|
|
||||||
$crumbs = $this->buildApplicationCrumbs();
|
$crumbs = $this->buildApplicationCrumbs();
|
||||||
$crumbs->addTextCrumb(pht('Samples'));
|
$crumbs->addTextCrumb(pht('Samples'), $this->getGroupURI(array()));
|
||||||
|
|
||||||
|
$crumb_map = array(
|
||||||
|
'host' => pht('By Host'),
|
||||||
|
'context' => pht('By Context'),
|
||||||
|
'viewer' => pht('By Viewer'),
|
||||||
|
'request' => pht('By Request'),
|
||||||
|
'label' => pht('By Label'),
|
||||||
|
);
|
||||||
|
|
||||||
|
$parts = array();
|
||||||
|
foreach ($group as $item) {
|
||||||
|
if ($item == 'type') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$parts[$item] = $item;
|
||||||
|
$crumbs->addTextCrumb(
|
||||||
|
idx($crumb_map, $item, $item),
|
||||||
|
$this->getGroupURI($parts));
|
||||||
|
}
|
||||||
|
|
||||||
return $this->buildApplicationPage(
|
return $this->buildApplicationPage(
|
||||||
array(
|
array(
|
||||||
|
@ -82,4 +170,25 @@ final class MultimeterSampleController extends MultimeterController {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function renderGroupingLink(array $group, $key) {
|
||||||
|
$group[] = $key;
|
||||||
|
$uri = $this->getGroupURI($group);
|
||||||
|
|
||||||
|
return phutil_tag(
|
||||||
|
'a',
|
||||||
|
array(
|
||||||
|
'href' => $uri,
|
||||||
|
'style' => 'font-weight: bold',
|
||||||
|
),
|
||||||
|
pht('(All)'));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getGroupURI(array $group) {
|
||||||
|
unset($group['type']);
|
||||||
|
$uri = clone $this->getRequest()->getRequestURI();
|
||||||
|
$uri->setQueryParam('group', implode('.', $group));
|
||||||
|
return $uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue