Skip to content

Commit

Permalink
KUDU-936: web UI should show a server's UUID
Browse files Browse the repository at this point in the history
This adds a footer at the bottom of every web page which includes
the Kudu version number and server UUID in a fairly muted presentation.

Since this required a bit more CSS, I moved the CSS to a new /kudu.css
file which is included.

Change-Id: I57fe42f2c104b95cc9dab6adf43a524eb487a46b
Reviewed-on: http://gerrit.sjc.cloudera.com:8080/7612
Reviewed-by: Adar Dembo <[email protected]>
Tested-by: jenkins
  • Loading branch information
toddlipcon committed Aug 26, 2015
1 parent 025818b commit 99663d6
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 13 deletions.
9 changes: 9 additions & 0 deletions src/kudu/server/server_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "kudu/common/wire_protocol.pb.h"
#include "kudu/fs/fs_manager.h"
#include "kudu/gutil/strings/strcat.h"
#include "kudu/gutil/strings/substitute.h"
#include "kudu/gutil/walltime.h"
#include "kudu/rpc/messenger.h"
#include "kudu/server/default-path-handlers.h"
Expand Down Expand Up @@ -46,6 +47,7 @@ DECLARE_bool(use_hybrid_clock);
using std::string;
using std::stringstream;
using std::vector;
using strings::Substitute;

namespace kudu {
namespace server {
Expand Down Expand Up @@ -269,6 +271,12 @@ void ServerBase::MetricsLoggingThread() {
WARN_NOT_OK(log.Close(), "Unable to close metric log");
}

std::string ServerBase::FooterHtml() const {
return Substitute("<pre>$0\nserver uuid $1</pre>",
VersionInfo::GetShortVersionString(),
instance_pb_->permanent_uuid());
}

Status ServerBase::Start() {
GenerateInstanceID();

Expand All @@ -281,6 +289,7 @@ Status ServerBase::Start() {
AddRpczPathHandlers(messenger_, web_server_.get());
RegisterMetricsJsonHandler(web_server_.get(), metric_registry_.get());
TracingPathHandlers::RegisterHandlers(web_server_.get());
web_server_->set_footer_html(FooterHtml());
RETURN_NOT_OK(web_server_->Start());

if (!options_.dump_info_path.empty()) {
Expand Down
1 change: 1 addition & 0 deletions src/kudu/server/server_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class ServerBase {
const std::string& format) const;
Status StartMetricsLogging();
void MetricsLoggingThread();
std::string FooterHtml() const;

ServerBaseOptions options_;

Expand Down
28 changes: 17 additions & 11 deletions src/kudu/server/webserver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ int Webserver::BeginRequestCallback(struct sq_connection* connection,
struct sq_request_info* request_info) {
PathHandler* handler;
{
boost::shared_lock<boost::shared_mutex> lock(path_handlers_lock_);
boost::shared_lock<boost::shared_mutex> lock(lock_);
PathHandlerMap::const_iterator it = path_handlers_.find(request_info->uri);
if (it == path_handlers_.end()) {
// Let Mongoose deal with this request; returning NULL will fall through
Expand Down Expand Up @@ -359,7 +359,7 @@ int Webserver::RunPathHandler(const PathHandler& handler,

void Webserver::RegisterPathHandler(const string& path, const string& alias,
const PathHandlerCallback& callback, bool is_styled, bool is_on_nav_bar) {
boost::lock_guard<boost::shared_mutex> lock(path_handlers_lock_);
boost::lock_guard<boost::shared_mutex> lock(lock_);
PathHandlerMap::iterator it = path_handlers_.find(path);
if (it == path_handlers_.end()) {
it = path_handlers_.insert(
Expand All @@ -371,17 +371,11 @@ void Webserver::RegisterPathHandler(const string& path, const string& alias,
const char* const PAGE_HEADER = "<!DOCTYPE html>"
" <html>"
" <head><title>Cloudera Kudu</title>"
" <link href='bootstrap/css/bootstrap.min.css' rel='stylesheet' media='screen' />"
" <style>"
" body {"
" padding-top: 60px; "
" }"
" </style>"
" <link href='/bootstrap/css/bootstrap.min.css' rel='stylesheet' media='screen' />"
" <link href='/kudu.css' rel='stylesheet' />"
" </head>"
" <body>";

static const char* const PAGE_FOOTER = "</div></body></html>";

static const char* const NAVIGATION_BAR_PREFIX =
"<div class='navbar navbar-inverse navbar-fixed-top'>"
" <div class='navbar-inner'>"
Expand Down Expand Up @@ -422,8 +416,20 @@ bool Webserver::static_pages_available() const {
return !opts_.doc_root.empty() && opts_.enable_doc_root;
}

void Webserver::set_footer_html(const std::string& html) {
boost::lock_guard<boost::shared_mutex> l(lock_);
footer_html_ = html;
}

void Webserver::BootstrapPageFooter(stringstream* output) {
(*output) << PAGE_FOOTER;
boost::shared_lock<boost::shared_mutex> l(lock_);
*output << "</div>\n"; // end bootstrap 'container' div
if (!footer_html_.empty()) {
*output << "<footer class=\"footer\"><div class=\"container text-muted\">";
*output << footer_html_;
*output << "</div></footer>";
}
*output << "</body></html>";
}

} // namespace kudu
11 changes: 9 additions & 2 deletions src/kudu/server/webserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class Webserver : public WebCallbackRegistry {
const PathHandlerCallback& callback,
bool is_styled = true, bool is_on_nav_bar = true) OVERRIDE;

// Change the footer HTML to be displayed at the bottom of all styled web pages.
void set_footer_html(const std::string& html);

// True if serving all traffic over SSL, false otherwise
bool IsSecure() const;
private:
Expand Down Expand Up @@ -128,15 +131,19 @@ class Webserver : public WebCallbackRegistry {

const WebserverOptions opts_;

// Lock guarding the path_handlers_ map
boost::shared_mutex path_handlers_lock_;
// Lock guarding the path_handlers_ map and footer_html.
boost::shared_mutex lock_;

// Map of path to a PathHandler containing a list of handlers for that
// path. More than one handler may register itself with a path so that many
// components may contribute to a single page.
typedef std::map<std::string, PathHandler*> PathHandlerMap;
PathHandlerMap path_handlers_;

// Snippet of HTML which will be displayed in the footer of all pages
// rendered by this server. Protected by 'lock_'.
std::string footer_html_;

// The address of the interface on which to run this webserver.
std::string http_address_;

Expand Down
30 changes: 30 additions & 0 deletions www/kudu.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2015, Cloudera, inc.
* Confidential Cloudera Information: Covered by NDA.
*/

body {
padding-top: 60px;
}

/* Sticky footer styles
-------------------------------------------------- */
html {
position: relative;
min-height: 100%;
}
body {
/* Margin bottom by footer height */
margin-bottom: 60px;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
/* Set the fixed height of the footer here */
height: 60px;
background-color: #f5f5f5;
}
.footer pre {
border: none;
}

0 comments on commit 99663d6

Please sign in to comment.