mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-20 20:40:56 +01:00
Allow Multimeter values to be locked by clicking links
Summary: Ref T6930. Mostly just playing with the UI a bit, I imagine we'll end up somewhere with a set of more standard query tools in the long run. But this feels pretty good/natural so far. Test Plan: {F389685} Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T6930 Differential Revision: https://secure.phabricator.com/D12628
This commit is contained in:
parent
7d5bcd43ba
commit
1448073314
1 changed files with 107 additions and 17 deletions
|
@ -8,15 +8,7 @@ final class MultimeterSampleController extends MultimeterController {
|
||||||
|
|
||||||
public function handleRequest(AphrontRequest $request) {
|
public function handleRequest(AphrontRequest $request) {
|
||||||
$viewer = $this->getViewer();
|
$viewer = $this->getViewer();
|
||||||
|
$group_map = $this->getColumnMap();
|
||||||
$group_map = array(
|
|
||||||
'type' => 'eventType',
|
|
||||||
'host' => 'eventHostID',
|
|
||||||
'context' => 'eventContextID',
|
|
||||||
'viewer' => 'eventViewerID',
|
|
||||||
'request' => 'requestKey',
|
|
||||||
'label' => 'eventLabelID',
|
|
||||||
);
|
|
||||||
|
|
||||||
$group = explode('.', $request->getStr('group'));
|
$group = explode('.', $request->getStr('group'));
|
||||||
$group = array_intersect($group, array_keys($group_map));
|
$group = array_intersect($group, array_keys($group_map));
|
||||||
|
@ -31,17 +23,38 @@ final class MultimeterSampleController extends MultimeterController {
|
||||||
|
|
||||||
$table = new MultimeterEvent();
|
$table = new MultimeterEvent();
|
||||||
$conn = $table->establishConnection('r');
|
$conn = $table->establishConnection('r');
|
||||||
|
|
||||||
|
$where = array();
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn,
|
||||||
|
'epoch >= %d AND epoch <= %d',
|
||||||
|
$ago,
|
||||||
|
$now);
|
||||||
|
|
||||||
|
$with = array();
|
||||||
|
foreach ($group_map as $key => $column) {
|
||||||
|
$with[$key] = $request->getStrList($key);
|
||||||
|
if ($with[$key]) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn,
|
||||||
|
'%T IN (%Ls)',
|
||||||
|
$column,
|
||||||
|
$with[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$where = '('.implode(') AND (', $where).')';
|
||||||
|
|
||||||
$data = queryfx_all(
|
$data = queryfx_all(
|
||||||
$conn,
|
$conn,
|
||||||
'SELECT *, count(*) N, SUM(sampleRate * resourceCost) as totalCost
|
'SELECT *, count(*) N, SUM(sampleRate * resourceCost) as totalCost
|
||||||
FROM %T
|
FROM %T
|
||||||
WHERE epoch >= %d AND epoch <= %d
|
WHERE %Q
|
||||||
GROUP BY %Q
|
GROUP BY %Q
|
||||||
ORDER BY totalCost DESC, MAX(id) DESC
|
ORDER BY totalCost DESC, MAX(id) DESC
|
||||||
LIMIT 100',
|
LIMIT 100',
|
||||||
$table->getTableName(),
|
$table->getTableName(),
|
||||||
$ago,
|
$where,
|
||||||
$now,
|
|
||||||
implode(', ', array_select_keys($group_map, $group)));
|
implode(', ', array_select_keys($group_map, $group)));
|
||||||
|
|
||||||
$this->loadDimensions($data);
|
$this->loadDimensions($data);
|
||||||
|
@ -51,6 +64,12 @@ final class MultimeterSampleController extends MultimeterController {
|
||||||
|
|
||||||
if (isset($group['request'])) {
|
if (isset($group['request'])) {
|
||||||
$request_col = $row['requestKey'];
|
$request_col = $row['requestKey'];
|
||||||
|
if (!$with['request']) {
|
||||||
|
$request_col = $this->renderSelectionLink(
|
||||||
|
'request',
|
||||||
|
$row['requestKey'],
|
||||||
|
$request_col);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$request_col = $this->renderGroupingLink($group, 'request');
|
$request_col = $this->renderGroupingLink($group, 'request');
|
||||||
}
|
}
|
||||||
|
@ -58,6 +77,12 @@ final class MultimeterSampleController extends MultimeterController {
|
||||||
if (isset($group['viewer'])) {
|
if (isset($group['viewer'])) {
|
||||||
$viewer_col = $this->getViewerDimension($row['eventViewerID'])
|
$viewer_col = $this->getViewerDimension($row['eventViewerID'])
|
||||||
->getName();
|
->getName();
|
||||||
|
if (!$with['viewer']) {
|
||||||
|
$viewer_col = $this->renderSelectionLink(
|
||||||
|
'viewer',
|
||||||
|
$row['eventViewerID'],
|
||||||
|
$viewer_col);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$viewer_col = $this->renderGroupingLink($group, 'viewer');
|
$viewer_col = $this->renderGroupingLink($group, 'viewer');
|
||||||
}
|
}
|
||||||
|
@ -65,6 +90,12 @@ final class MultimeterSampleController extends MultimeterController {
|
||||||
if (isset($group['context'])) {
|
if (isset($group['context'])) {
|
||||||
$context_col = $this->getContextDimension($row['eventContextID'])
|
$context_col = $this->getContextDimension($row['eventContextID'])
|
||||||
->getName();
|
->getName();
|
||||||
|
if (!$with['context']) {
|
||||||
|
$context_col = $this->renderSelectionLink(
|
||||||
|
'context',
|
||||||
|
$row['eventContextID'],
|
||||||
|
$context_col);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$context_col = $this->renderGroupingLink($group, 'context');
|
$context_col = $this->renderGroupingLink($group, 'context');
|
||||||
}
|
}
|
||||||
|
@ -72,6 +103,12 @@ final class MultimeterSampleController extends MultimeterController {
|
||||||
if (isset($group['host'])) {
|
if (isset($group['host'])) {
|
||||||
$host_col = $this->getHostDimension($row['eventHostID'])
|
$host_col = $this->getHostDimension($row['eventHostID'])
|
||||||
->getName();
|
->getName();
|
||||||
|
if (!$with['host']) {
|
||||||
|
$host_col = $this->renderSelectionLink(
|
||||||
|
'host',
|
||||||
|
$row['eventHostID'],
|
||||||
|
$host_col);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$host_col = $this->renderGroupingLink($group, 'host');
|
$host_col = $this->renderGroupingLink($group, 'host');
|
||||||
}
|
}
|
||||||
|
@ -79,10 +116,25 @@ final class MultimeterSampleController extends MultimeterController {
|
||||||
if (isset($group['label'])) {
|
if (isset($group['label'])) {
|
||||||
$label_col = $this->getLabelDimension($row['eventLabelID'])
|
$label_col = $this->getLabelDimension($row['eventLabelID'])
|
||||||
->getName();
|
->getName();
|
||||||
|
if (!$with['label']) {
|
||||||
|
$label_col = $this->renderSelectionLink(
|
||||||
|
'label',
|
||||||
|
$row['eventLabelID'],
|
||||||
|
$label_col);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$label_col = $this->renderGroupingLink($group, 'label');
|
$label_col = $this->renderGroupingLink($group, 'label');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($with['type']) {
|
||||||
|
$type_col = MultimeterEvent::getEventTypeName($row['eventType']);
|
||||||
|
} else {
|
||||||
|
$type_col = $this->renderSelectionLink(
|
||||||
|
'type',
|
||||||
|
$row['eventType'],
|
||||||
|
MultimeterEvent::getEventTypeName($row['eventType']));
|
||||||
|
}
|
||||||
|
|
||||||
$rows[] = array(
|
$rows[] = array(
|
||||||
($row['N'] == 1)
|
($row['N'] == 1)
|
||||||
? $row['id']
|
? $row['id']
|
||||||
|
@ -91,7 +143,7 @@ final class MultimeterSampleController extends MultimeterController {
|
||||||
$viewer_col,
|
$viewer_col,
|
||||||
$context_col,
|
$context_col,
|
||||||
$host_col,
|
$host_col,
|
||||||
MultimeterEvent::getEventTypeName($row['eventType']),
|
$type_col,
|
||||||
$label_col,
|
$label_col,
|
||||||
MultimeterEvent::formatResourceCost(
|
MultimeterEvent::formatResourceCost(
|
||||||
$viewer,
|
$viewer,
|
||||||
|
@ -139,7 +191,9 @@ final class MultimeterSampleController extends MultimeterController {
|
||||||
->appendChild($table);
|
->appendChild($table);
|
||||||
|
|
||||||
$crumbs = $this->buildApplicationCrumbs();
|
$crumbs = $this->buildApplicationCrumbs();
|
||||||
$crumbs->addTextCrumb(pht('Samples'), $this->getGroupURI(array()));
|
$crumbs->addTextCrumb(
|
||||||
|
pht('Samples'),
|
||||||
|
$this->getGroupURI(array(), true));
|
||||||
|
|
||||||
$crumb_map = array(
|
$crumb_map = array(
|
||||||
'host' => pht('By Host'),
|
'host' => pht('By Host'),
|
||||||
|
@ -157,7 +211,7 @@ final class MultimeterSampleController extends MultimeterController {
|
||||||
$parts[$item] = $item;
|
$parts[$item] = $item;
|
||||||
$crumbs->addTextCrumb(
|
$crumbs->addTextCrumb(
|
||||||
idx($crumb_map, $item, $item),
|
idx($crumb_map, $item, $item),
|
||||||
$this->getGroupURI($parts));
|
$this->getGroupURI($parts, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->buildApplicationPage(
|
return $this->buildApplicationPage(
|
||||||
|
@ -183,12 +237,48 @@ final class MultimeterSampleController extends MultimeterController {
|
||||||
pht('(All)'));
|
pht('(All)'));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getGroupURI(array $group) {
|
private function getGroupURI(array $group, $wipe = false) {
|
||||||
unset($group['type']);
|
unset($group['type']);
|
||||||
$uri = clone $this->getRequest()->getRequestURI();
|
$uri = clone $this->getRequest()->getRequestURI();
|
||||||
$uri->setQueryParam('group', implode('.', $group));
|
|
||||||
|
$group = implode('.', $group);
|
||||||
|
if (!strlen($group)) {
|
||||||
|
$group = null;
|
||||||
|
}
|
||||||
|
$uri->setQueryParam('group', $group);
|
||||||
|
|
||||||
|
if ($wipe) {
|
||||||
|
foreach ($this->getColumnMap() as $key => $column) {
|
||||||
|
$uri->setQueryParam($key, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $uri;
|
return $uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function renderSelectionLink($key, $value, $link_text) {
|
||||||
|
$value = (array)$value;
|
||||||
|
|
||||||
|
$uri = clone $this->getRequest()->getRequestURI();
|
||||||
|
$uri->setQueryParam($key, implode(',', $value));
|
||||||
|
|
||||||
|
return phutil_tag(
|
||||||
|
'a',
|
||||||
|
array(
|
||||||
|
'href' => $uri,
|
||||||
|
),
|
||||||
|
$link_text);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getColumnMap() {
|
||||||
|
return array(
|
||||||
|
'type' => 'eventType',
|
||||||
|
'host' => 'eventHostID',
|
||||||
|
'context' => 'eventContextID',
|
||||||
|
'viewer' => 'eventViewerID',
|
||||||
|
'request' => 'requestKey',
|
||||||
|
'label' => 'eventLabelID',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue