You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by al...@apache.org on 2018/11/21 03:29:41 UTC
[3/4] kudu git commit: [webui] Fancy table for /mem-trackers and
sortable tables
[webui] Fancy table for /mem-trackers and sortable tables
This fancifies the table of trackers on /mem-trackers in the style of
6ae9ecbe2595090c78e7afd271aae9d04dd4d0b5. It also adds the ability to
sort some tables by some numeric columns. Namely:
- the /mem-trackers trackers table is sortable by current consumption
and peak consumption
- the /tablets page tablets tables are sortable by on-disk size
- the /maintenance-manager "non-running op" table is sortable by RAM
anchored, logs retained, and perf.
I tested this change out manually, verifying that ascending and
descending sort looked good. Unfortunately, the bootstrap table
library doesn't seem to use a stable sort.
Change-Id: Ibdf8e7bd82fe2b95e699b8bb238a9cf0e5a7e727
Reviewed-on: http://gerrit.cloudera.org:8080/11968
Reviewed-by: Adar Dembo <ad...@cloudera.com>
Reviewed-by: Andrew Wong <aw...@cloudera.com>
Tested-by: Kudu Jenkins
Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/7437626f
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/7437626f
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/7437626f
Branch: refs/heads/master
Commit: 7437626f42b30811720d59e792bc905662efd2b3
Parents: b8595f8
Author: Will Berkeley <wd...@gmail.org>
Authored: Tue Nov 20 14:46:09 2018 -0800
Committer: Will Berkeley <wd...@gmail.com>
Committed: Wed Nov 21 01:31:15 2018 +0000
----------------------------------------------------------------------
src/kudu/server/default_path_handlers.cc | 24 ++++++----
src/kudu/server/webserver.cc | 1 +
www/kudu.js | 68 +++++++++++++++++++++++++++
www/maintenance-manager.mustache | 6 +--
www/tablets.mustache | 4 +-
5 files changed, 90 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/7437626f/src/kudu/server/default_path_handlers.cc
----------------------------------------------------------------------
diff --git a/src/kudu/server/default_path_handlers.cc b/src/kudu/server/default_path_handlers.cc
index 7574def..390630c 100644
--- a/src/kudu/server/default_path_handlers.cc
+++ b/src/kudu/server/default_path_handlers.cc
@@ -28,9 +28,7 @@
#include <vector>
#include <boost/algorithm/string/predicate.hpp>
-#include <boost/algorithm/string/replace.hpp>
#include <boost/bind.hpp> // IWYU pragma: keep
-#include <boost/iterator/iterator_traits.hpp>
#include <gflags/gflags.h>
#include <gflags/gflags_declare.h>
#include <glog/logging.h>
@@ -50,7 +48,6 @@
#include "kudu/util/array_view.h"
#include "kudu/util/debug-util.h"
#include "kudu/util/easy_json.h"
-#include "kudu/util/faststring.h"
#include "kudu/util/flag_tags.h"
#include "kudu/util/flags.h"
#include "kudu/util/jsonwriter.h"
@@ -203,7 +200,7 @@ static void MemUsageHandler(const Webserver::WebRequest& req,
#endif
}
-// Registered to handle "/mem-trackers", and prints out to handle memory tracker information.
+// Registered to handle "/mem-trackers", and prints out memory tracker information.
static void MemTrackersHandler(const Webserver::WebRequest& /*req*/,
Webserver::PrerenderedWebResponse* resp) {
std::ostringstream* output = resp->output;
@@ -231,9 +228,20 @@ static void MemTrackersHandler(const Webserver::WebRequest& /*req*/,
#endif
*output << "<h1>Memory usage by subsystem</h1>\n";
- *output << "<table class='table table-striped'>\n";
- *output << " <thead><tr><th>Id</th><th>Parent</th><th>Limit</th><th>Current Consumption</th>"
- "<th>Peak consumption</th></tr></thead>\n";
+ *output << "<table data-toggle='table' "
+ " data-pagination='true' "
+ " data-search='true' "
+ " class='table table-striped'>\n";
+ *output << "<thead><tr>"
+ "<th>Id</th>"
+ "<th>Parent</th>"
+ "<th>Limit</th>"
+ "<th data-sorter='bytesSorter' "
+ " data-sortable='true' "
+ "'>Current Consumption</th>"
+ "<th data-sorter='bytesSorter' "
+ " data-sortable='true' "
+ ">Peak Consumption</th>";
*output << "<tbody>\n";
vector<shared_ptr<MemTracker> > trackers;
@@ -244,7 +252,7 @@ static void MemTrackersHandler(const Webserver::WebRequest& /*req*/,
HumanReadableNumBytes::ToString(tracker->limit());
string current_consumption_str = HumanReadableNumBytes::ToString(tracker->consumption());
string peak_consumption_str = HumanReadableNumBytes::ToString(tracker->peak_consumption());
- (*output) << Substitute(" <tr><td>$0</td><td>$1</td><td>$2</td>" // id, parent, limit
+ (*output) << Substitute("<tr><td>$0</td><td>$1</td><td>$2</td>" // id, parent, limit
"<td>$3</td><td>$4</td></tr>\n", // current, peak
tracker->id(), parent, limit_str, current_consumption_str,
peak_consumption_str);
http://git-wip-us.apache.org/repos/asf/kudu/blob/7437626f/src/kudu/server/webserver.cc
----------------------------------------------------------------------
diff --git a/src/kudu/server/webserver.cc b/src/kudu/server/webserver.cc
index 0fc0aec..d0fde6b 100644
--- a/src/kudu/server/webserver.cc
+++ b/src/kudu/server/webserver.cc
@@ -566,6 +566,7 @@ static const char* const kMainTemplate = R"(
<script src='/jquery-3.2.1.min.js' defer></script>
<script src='/bootstrap/js/bootstrap.min.js' defer></script>
<script src='/bootstrap/js/bootstrap-table.min.js' defer></script>
+ <script src='/kudu.js' defer></script>
<link href='/kudu.css' rel='stylesheet' />
</head>
<body>
http://git-wip-us.apache.org/repos/asf/kudu/blob/7437626f/www/kudu.js
----------------------------------------------------------------------
diff --git a/www/kudu.js b/www/kudu.js
new file mode 100644
index 0000000..0933ca2
--- /dev/null
+++ b/www/kudu.js
@@ -0,0 +1,68 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+// Converts a human-readable bytes value like '1.23B' or '985.32M' to a number
+// of bytes. The suffix must be present: '1.23' is not valid but '1.23B' is.
+// Returns -1 if there's some failure.
+function toNumBytes(humanReadableBytes) {
+ len = humanReadableBytes.length;
+ if (len <= 1) {
+ return -1;
+ }
+ unit = humanReadableBytes[len - 1];
+ val = parseFloat(humanReadableBytes.substring(0, len - 1));
+ if (isNaN(val)) {
+ return -1;
+ }
+ // Fallthrough intended throughout.
+ switch (unit) {
+ case 'Y': val *= 1024.0; // Enough bytes to handle any double.
+ case 'Z': val *= 1024.0;
+ case 'E': val *= 1024.0;
+ case 'P': val *= 1024.0;
+ case 'T': val *= 1024.0;
+ case 'G': val *= 1024.0;
+ case 'M': val *= 1024.0;
+ case 'K': val *= 1024.0;
+ case 'B': break;
+ default:
+ return -1;
+ }
+ return val;
+}
+
+// A comparison function for human-readable byte strings.
+function bytesSorter(left, right) {
+ if (right.length == 0 && left.length == 0) {
+ return 0;
+ }
+ if (left.length == 0) {
+ return -1;
+ }
+ if (right.length == 0) {
+ return 1;
+ }
+ left_bytes = toNumBytes(left.trim());
+ right_bytes = toNumBytes(right.trim());
+ if (left_bytes < right_bytes) {
+ return -1;
+ }
+ if (left_bytes > right_bytes) {
+ return 1;
+ }
+ return 0;
+}
http://git-wip-us.apache.org/repos/asf/kudu/blob/7437626f/www/maintenance-manager.mustache
----------------------------------------------------------------------
diff --git a/www/maintenance-manager.mustache b/www/maintenance-manager.mustache
index 269a7d2..81d5247 100644
--- a/www/maintenance-manager.mustache
+++ b/www/maintenance-manager.mustache
@@ -63,9 +63,9 @@ under the License.
<tr>
<th>Name</th>
<th>Runnable</th>
- <th>RAM anchored</th>
- <th>Logs retained</th>
- <th>Perf</th>
+ <th data-sorter="bytesSorter" data-sortable="true">RAM anchored</th>
+ <th data-sorter="bytesSorter" data-sortable="true">Logs retained</th>
+ <th data-sortable="true">Perf</th>
</tr>
</thead>
<tbody>
http://git-wip-us.apache.org/repos/asf/kudu/blob/7437626f/www/tablets.mustache
----------------------------------------------------------------------
diff --git a/www/tablets.mustache b/www/tablets.mustache
index ea1f94a..7a3f904 100644
--- a/www/tablets.mustache
+++ b/www/tablets.mustache
@@ -39,7 +39,7 @@ There are no tablet replicas.
<th>Tablet ID</th>
<th>Partition</th>
<th>State</th>
- <th>On-disk size</th>
+ <th data-sorter="bytesSorter" data-sortable="true">On-disk size</th>
<th>RaftConfig</th>
</tr>
</thead>
@@ -83,7 +83,7 @@ There are no tablet replicas.
<th>Tablet ID</th>
<th>Partition</th>
<th>State</th>
- <th>On-disk size</th>
+ <th data-sorter="bytesSorter" data-sortable="true">On-disk size</th>
<th>Last status</th>
</tr>
</thead>