mirror of
https://github.com/apache/impala.git
synced 2026-01-07 09:02:19 -05:00
In order to make the query life-cycle clearer to users, added a new section to the /queries webui page for queries that are 'waiting', not actively running either due to an error or to returning all of their results, but that have not been closed so they are still using resources. This section is marked 'waiting to be closed' to indicate that they still need to be closed even though they are not actively running. These queries previously would have appeared in the 'in flight' list. There is a tooltip with a full explanation. The 'in_flight_queries' json endpoint was left as is, so that CM will continue to work as expected, and filtering queries for the different lists is done in the html template. This was tested manually. Change-Id: I47d0b642ecb573fefbbf337b8c8f2c479b0d49b2 Reviewed-on: http://gerrit.cloudera.org:8080/2625 Reviewed-by: Matthew Jacobs <mj@cloudera.com> Tested-by: Internal Jenkins
87 lines
3.9 KiB
Python
87 lines
3.9 KiB
Python
# Copyright (c) 2016 Cloudera, Inc. All rights reserved.
|
|
#
|
|
# Licensed 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.
|
|
#
|
|
# Tests for query expiration.
|
|
|
|
import json
|
|
import pytest
|
|
|
|
from urllib2 import urlopen
|
|
|
|
from tests.hs2.hs2_test_suite import HS2TestSuite
|
|
from TCLIService import TCLIService
|
|
|
|
class TestJsonEndpoints(HS2TestSuite):
|
|
def _get_json_queries(self, http_addr):
|
|
"""Get the json output of the /queries page from the impalad web UI at http_addr."""
|
|
resp = urlopen("http://%s/queries?json" % http_addr)
|
|
assert resp.msg == 'OK'
|
|
return json.loads(resp.read())
|
|
|
|
@pytest.mark.execute_serially
|
|
def test_waiting_in_flight_queries(self):
|
|
"""Confirm that the in_flight_queries endpoint shows a query at eos as waiting"""
|
|
open_session_req = TCLIService.TOpenSessionReq()
|
|
default_database = "functional"
|
|
open_session_req.configuration = {"use:database": default_database}
|
|
open_session_resp = self.hs2_client.OpenSession(open_session_req)
|
|
TestJsonEndpoints.check_response(open_session_resp)
|
|
http_addr = open_session_resp.configuration['http_addr']
|
|
|
|
# Execute a SELECT, and check that in_flight_queries shows one executing query.
|
|
select_statement_req = TCLIService.TExecuteStatementReq()
|
|
select_statement_req.sessionHandle = open_session_resp.sessionHandle
|
|
select_statement_req.statement = "SELECT * FROM functional.alltypes LIMIT 0"
|
|
select_statement_resp = self.hs2_client.ExecuteStatement(select_statement_req)
|
|
TestJsonEndpoints.check_response(select_statement_resp)
|
|
queries_json = self._get_json_queries(http_addr)
|
|
assert len(queries_json["in_flight_queries"]) == 1
|
|
assert queries_json["num_in_flight_queries"] == 1
|
|
assert queries_json["num_executing_queries"] == 1
|
|
assert queries_json["num_waiting_queries"] == 0
|
|
query = queries_json["in_flight_queries"][0]
|
|
assert query["default_db"] == default_database
|
|
assert query["stmt"] == select_statement_req.statement
|
|
assert query["stmt_type"] == "QUERY"
|
|
assert query["rows_fetched"] == 0
|
|
assert query["executing"]
|
|
assert not query["waiting"]
|
|
|
|
# Fetch the results, putting the query at eos, and check that in_flight_queries
|
|
# shows one waiting query.
|
|
fetch_results_req = TCLIService.TFetchResultsReq()
|
|
fetch_results_req.operationHandle = select_statement_resp.operationHandle
|
|
fetch_results_req.maxRows = 100
|
|
fetch_results_resp = self.hs2_client.FetchResults(fetch_results_req)
|
|
TestJsonEndpoints.check_response(fetch_results_resp)
|
|
queries_json = self._get_json_queries(http_addr)
|
|
assert len(queries_json["in_flight_queries"]) == 1
|
|
assert queries_json["num_in_flight_queries"] == 1
|
|
assert queries_json["num_executing_queries"] == 0
|
|
assert queries_json["num_waiting_queries"] == 1
|
|
query = queries_json["in_flight_queries"][0]
|
|
assert not query["executing"]
|
|
assert query["waiting"]
|
|
|
|
# Close the query and check that in_flight_queries is empty.
|
|
close_operation_req = TCLIService.TCloseOperationReq()
|
|
close_operation_req.operationHandle = select_statement_resp.operationHandle
|
|
close_operation_resp = self.hs2_client.CloseOperation(close_operation_req)
|
|
TestJsonEndpoints.check_response(close_operation_resp)
|
|
queries_json = self._get_json_queries(http_addr)
|
|
assert len(queries_json["in_flight_queries"]) == 0
|
|
assert queries_json["num_in_flight_queries"] == 0
|
|
assert queries_json["num_executing_queries"] == 0
|
|
assert queries_json["num_waiting_queries"] == 0
|