Repository: incubator-impala Updated Branches: refs/heads/master 58d8861c5 -> c62d8244a
IMPALA-4048: Misc. improvements to /sessions * Make table searchable and sortable * Fix 'last accessed time' being printed in UTC * Made table contents more compact so that it mostly fits on screen * Clarify summary text re: active and inactive sessions * Include fix in mustache-cpp required to print 64-bit integers correctly (see https://github.com/henryr/cpp-mustache/commit/29768bf0e84f5a1e95e006fc64996d375499dbda) Testing: Visual inspection and manual sorting, searching etc. Change-Id: I14edcb6d60cf031a62c5a20b2d2b4d23248633a3 Reviewed-on: http://gerrit.cloudera.org:8080/4880 Reviewed-by: Thomas Tauber-Marshall <[email protected]> Tested-by: Internal Jenkins Reviewed-by: Tim Armstrong <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/incubator-impala/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-impala/commit/c62d8244 Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/c62d8244 Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/c62d8244 Branch: refs/heads/master Commit: c62d8244a4c3c674367dfa90831fc714d869ecb0 Parents: 58d8861 Author: Henry Robinson <[email protected]> Authored: Fri Oct 28 15:01:26 2016 -0700 Committer: Henry Robinson <[email protected]> Committed: Mon Nov 7 20:50:04 2016 +0000 ---------------------------------------------------------------------- be/src/service/impala-hs2-server.cc | 2 +- be/src/service/impala-http-handler.cc | 18 +++++- be/src/service/impala-server.cc | 2 +- be/src/service/impala-server.h | 6 +- be/src/thirdparty/mustache/mustache.cc | 2 + www/sessions.tmpl | 94 +++++++++++++++++------------ 6 files changed, 78 insertions(+), 46 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/c62d8244/be/src/service/impala-hs2-server.cc ---------------------------------------------------------------------- diff --git a/be/src/service/impala-hs2-server.cc b/be/src/service/impala-hs2-server.cc index 05a58a4..eb96359 100644 --- a/be/src/service/impala-hs2-server.cc +++ b/be/src/service/impala-hs2-server.cc @@ -281,7 +281,7 @@ void ImpalaServer::OpenSession(TOpenSessionResp& return_val, // TODO: Fix duplication of code between here and ConnectionStart(). shared_ptr<SessionState> state = make_shared<SessionState>(); state->closed = false; - state->start_time = TimestampValue::LocalTime(); + state->start_time_ms = UnixMillis(); state->session_type = TSessionType::HIVESERVER2; state->network_address = ThriftServer::GetThreadConnectionContext()->network_address; state->last_accessed_ms = UnixMillis(); http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/c62d8244/be/src/service/impala-http-handler.cc ---------------------------------------------------------------------- diff --git a/be/src/service/impala-http-handler.cc b/be/src/service/impala-http-handler.cc index b335a29..834fd42 100644 --- a/be/src/service/impala-http-handler.cc +++ b/be/src/service/impala-http-handler.cc @@ -427,6 +427,7 @@ void ImpalaHttpHandler::SessionsHandler(const Webserver::ArgumentMap& args, Document* document) { lock_guard<mutex> l(server_->session_state_map_lock_); Value sessions(kArrayType); + int num_active = 0; for (const ImpalaServer::SessionStateMap::value_type& session: server_->session_state_map_) { shared_ptr<ImpalaServer::SessionState> state = session.second; @@ -457,18 +458,26 @@ void ImpalaHttpHandler::SessionsHandler(const Webserver::ArgumentMap& args, Value default_db(state->database.c_str(), document->GetAllocator()); session_json.AddMember("default_database", default_db, document->GetAllocator()); - Value start_time(state->start_time.DebugString().c_str(), document->GetAllocator()); + TimestampValue local_start_time(session.second->start_time_ms / 1000); + local_start_time.UtcToLocal(); + Value start_time(local_start_time.DebugString().c_str(), document->GetAllocator()); session_json.AddMember("start_time", start_time, document->GetAllocator()); + session_json.AddMember( + "start_time_sort", session.second->start_time_ms, document->GetAllocator()); + TimestampValue local_last_accessed(session.second->last_accessed_ms / 1000); + local_last_accessed.UtcToLocal(); Value last_accessed( - TimestampValue(session.second->last_accessed_ms / 1000).DebugString().c_str(), - document->GetAllocator()); + local_last_accessed.DebugString().c_str(), document->GetAllocator()); session_json.AddMember("last_accessed", last_accessed, document->GetAllocator()); + session_json.AddMember( + "last_accessed_sort", session.second->last_accessed_ms, document->GetAllocator()); session_json.AddMember("session_timeout", state->session_timeout, document->GetAllocator()); session_json.AddMember("expired", state->expired, document->GetAllocator()); session_json.AddMember("closed", state->closed, document->GetAllocator()); + if (!state->expired && !state->closed) ++num_active; session_json.AddMember("ref_count", state->ref_count, document->GetAllocator()); sessions.PushBack(session_json, document->GetAllocator()); } @@ -477,6 +486,9 @@ void ImpalaHttpHandler::SessionsHandler(const Webserver::ArgumentMap& args, document->AddMember("num_sessions", static_cast<uint64_t>(server_->session_state_map_.size()), document->GetAllocator()); + document->AddMember("num_active", num_active, document->GetAllocator()); + document->AddMember("num_inactive", server_->session_state_map_.size() - num_active, + document->GetAllocator()); } void ImpalaHttpHandler::CatalogHandler(const Webserver::ArgumentMap& args, http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/c62d8244/be/src/service/impala-server.cc ---------------------------------------------------------------------- diff --git a/be/src/service/impala-server.cc b/be/src/service/impala-server.cc index c7180fd..024cd24 100644 --- a/be/src/service/impala-server.cc +++ b/be/src/service/impala-server.cc @@ -1621,7 +1621,7 @@ void ImpalaServer::ConnectionStart( shared_ptr<SessionState> session_state; session_state.reset(new SessionState); session_state->closed = false; - session_state->start_time = TimestampValue::LocalTime(); + session_state->start_time_ms = UnixMillis(); session_state->last_accessed_ms = UnixMillis(); session_state->database = "default"; session_state->session_timeout = FLAGS_idle_session_timeout; http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/c62d8244/be/src/service/impala-server.h ---------------------------------------------------------------------- diff --git a/be/src/service/impala-server.h b/be/src/service/impala-server.h index b884ea4..836e619 100644 --- a/be/src/service/impala-server.h +++ b/be/src/service/impala-server.h @@ -687,8 +687,8 @@ class ImpalaServer : public ImpalaServiceIf, public ImpalaHiveServer2ServiceIf, TSessionType::type session_type; - /// Time the session was created. - TimestampValue start_time; + /// Time the session was created, in ms since epoch (UTC). + int64_t start_time_ms; /// Connected user for this session, i.e. the user which originated this session. std::string connected_user; @@ -733,7 +733,7 @@ class ImpalaServer : public ImpalaServiceIf, public ImpalaHiveServer2ServiceIf, /// Total number of queries run as part of this session. int64_t total_queries; - /// Time the session was last accessed. + /// Time the session was last accessed, in ms since epoch (UTC). int64_t last_accessed_ms; /// The latest Kudu timestamp observed after DML operations executed within this http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/c62d8244/be/src/thirdparty/mustache/mustache.cc ---------------------------------------------------------------------- diff --git a/be/src/thirdparty/mustache/mustache.cc b/be/src/thirdparty/mustache/mustache.cc index 59aeafc..7d5a840 100644 --- a/be/src/thirdparty/mustache/mustache.cc +++ b/be/src/thirdparty/mustache/mustache.cc @@ -275,6 +275,8 @@ int EvaluateSubstitution(const string& document, const int idx, // TODO: Triple {{{ means don't escape (*out) << context->GetString(); } + } else if (context->IsInt64()) { + (*out) << context->GetInt64(); } else if (context->IsInt()) { (*out) << context->GetInt(); } else if (context->IsDouble()) { http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/c62d8244/www/sessions.tmpl ---------------------------------------------------------------------- diff --git a/www/sessions.tmpl b/www/sessions.tmpl index e0a5216..8c4f206 100644 --- a/www/sessions.tmpl +++ b/www/sessions.tmpl @@ -19,45 +19,63 @@ under the License. {{> www/common-header.tmpl }} <h2>Sessions</h2> -There are {{num_sessions}} active sessions. -<table class='table table-bordered table-hover'> - <tr> - <th>Session Type</th> - <th>Open Queries</th> - <th>Total Queries</th> - <th>User</th> - <th>Delegated User</th> - <th>Session ID</th> - <th>Network Address</th> - <th>Default Database</th> - <th>Start Time</th> - <th>Last Accessed</th> - <th>Idle Timeout (s)</th> - <th>Expired</th> - <th>Closed</th> - <th>Ref count</th> - <th>Action</th> - </tr> -{{#sessions}} - <tr> - <td>{{type}}</td> - <td>{{inflight_queries}}</td> - <td>{{total_queries}}</td> - <td>{{user}}</td> - <td>{{delegated_user}}</td> - <td>{{session_id}}</td> - <td>{{network_address}}</td> - <td>{{default_database}}</td> - <td>{{start_time}}</td> - <td>{{last_accessed}}</td> - <td>{{session_timeout}}</td> - <td>{{expired}}</td> - <td>{{closed}}</td> - <td>{{ref_count}}</td> - <td><a href='/close_session?session_id={{session_id}}'>Close Session</a></td> - </tr> -{{/sessions}} +<div class="alert alert-info" role="alert"> +<h4>There are {{num_sessions}} sessions, of which {{num_active}} are active</h4> Sessions +may be <strong>closed</strong> either when they are idle for some time (see Idle Timeout +below), or if they are deliberately closed, otherwise they are +called <strong>active</strong>.</div> + +<table id="sessions-tbl" class='table table-bordered table-hover table-condensed'> + <thead> + <tr> + <th><small>Session Type</small></th> + <th><small>Open Queries</small></th> + <th><small>Total Queries</small></th> + <th><small>User</small></th> + <th><small>Delegated User</small></th> + <th><small>Session ID</small></th> + <th><small>Network Address</small></th> + <th><small>Default Database</small></th> + <th><small>Start Time</small></th> + <th><small>Last Accessed</small></th> + <th><small>Idle Timeout (s)</small></th> + <th><small>Expired</small></th> + <th><small>Closed</small></th> + <th><small>Ref count</small></th> + <th><small>Action</small></th> + </tr> + </thead> + <tbody> + {{#sessions}} + <tr> + <td><small>{{type}}</small></td> + <td><small>{{inflight_queries}}</small></td> + <td><small>{{total_queries}}</small></td> + <td><small>{{user}}</small></td> + <td><small>{{delegated_user}}</small></td> + <td><small>{{session_id}}</small></td> + <td><small>{{network_address}}</small></td> + <td><small>{{default_database}}</small></td> + <td data-order="{{start_time_sort}}"><small>{{start_time}}</small></td> + <td data-order="{{last_accessed_sort}}"><small>{{last_accessed}}</small></td> + <td><small>{{session_timeout}}</small></td> + <td><small>{{expired}}</small></td> + <td><small>{{closed}}</small></td> + <td><small>{{ref_count}}</small></td> + <td><small><a href='/close_session?session_id={{session_id}}'>Close</a></small></td> + </tr> + {{/sessions}} + </tbody> </table> +<script> + $(document).ready(function() { + $('#sessions-tbl').DataTable({ + "order": [[ 1, "desc" ]], + "pageLength": 100 + }); + }); +</script> + {{> www/common-footer.tmpl }}
