Bläddra i källkod

HUE-9510 [querybrowser] Config flag for proxy

ayush.goyal 5 år sedan
förälder
incheckning
ce7c0a5603

+ 18 - 15
apps/jobbrowser/src/jobbrowser/api2.py

@@ -29,7 +29,7 @@ from desktop.lib.rest.resource import Resource
 from desktop.views import serve_403_error
 
 from jobbrowser.apis.base_api import get_api
-from jobbrowser.conf import DISABLE_KILLING_JOBS, QUERY_STORE
+from jobbrowser.conf import DISABLE_KILLING_JOBS, QUERY_STORE, USE_PROXY
 
 LOG = logging.getLogger(__name__)
 
@@ -168,27 +168,30 @@ def profile(request):
 
 
 @api_error_handler
-def query_store_proxy(request, path=None):
+def query_store_api(request, path=None):
   response = {'status': -1}
-  content_type = 'application/json; charset=UTF-8'
-  headers = {'X-Requested-By': 'das', 'Content-Type': content_type}
 
-  client = HttpClient(QUERY_STORE.SERVER_URL.get())
-  resource = Resource(client)
+  if USE_PROXY.get():
+    content_type = 'application/json; charset=UTF-8'
+    headers = {'X-Requested-By': 'das', 'Content-Type': content_type}
 
-  try:
-    response = resource.invoke(request.method, path, request.GET.dict(), request.body, headers)
-  except RestException as e:
-    ex_response = e.get_parent_ex().response
-    response['code'] = ex_response.status_code
-    response['message'] = ex_response.reason
-    response['content'] = ex_response.text
+    client = HttpClient(QUERY_STORE.SERVER_URL.get())
+    resource = Resource(client)
 
-  return JsonResponse(response);
+    try:
+      response = resource.invoke(request.method, path, request.GET.dict(), request.body, headers)
+    except RestException as e:
+      ex_response = e.get_parent_ex().response
+      response['code'] = ex_response.status_code
+      response['message'] = ex_response.reason
+      response['content'] = ex_response.text
+
+  return JsonResponse(response)
 
 
 @api_error_handler
-def download_zip(request, id=None):
+def query_store_download_bundle(request, id=None):
+  response = {}
 
   client = HttpClient(QUERY_STORE.SERVER_URL.get())
   resource = Resource(client)

+ 7 - 0
apps/jobbrowser/src/jobbrowser/conf.py

@@ -97,3 +97,10 @@ QUERY_STORE = ConfigSection(
     )
   )
 )
+
+USE_PROXY = Config(
+  key="use_proxy",
+  help=_("Use the proxy API instead of the ORM to access the query_store."),
+  type=coerce_bool,
+  default=True
+)

+ 4 - 11
apps/jobbrowser/src/jobbrowser/urls.py

@@ -20,8 +20,6 @@ from django.conf.urls import url
 from jobbrowser import views as jobbrowser_views
 from jobbrowser import api2 as jobbrowser_api2
 
-from jobbrowser.conf import QUERY_STORE
-
 urlpatterns = [
   # "Default"
   url(r'^$', jobbrowser_views.jobs),
@@ -70,12 +68,7 @@ urlpatterns += [
   url(r'api/job(?:/(?P<interface>.+))?/?', jobbrowser_api2.job, name='job'),
 ]
 
-if QUERY_STORE.SERVER_URL.get():
-  urlpatterns += [
-    url(r'^query-proxy/data-bundle/(?P<id>.*)$', jobbrowser_api2.download_zip),
-  ]
-
-if QUERY_STORE.SERVER_URL.get():
-  urlpatterns += [
-    url(r'^query-proxy/(?P<path>.*)$', jobbrowser_api2.query_store_proxy),
-  ]
+urlpatterns += [
+  url(r'^query-store/data-bundle/(?P<id>.*)$', jobbrowser_api2.query_store_download_bundle),
+  url(r'^query-store/(?P<path>.*)$', jobbrowser_api2.query_store_api),
+]

+ 3 - 0
desktop/conf.dist/hue.ini

@@ -1655,6 +1655,9 @@
   # Show the Queries section for listing Hive/Impala query history and providing more troubleshooting information.
   ## enable_queries_list=false
 
+  # Use the proxy API instead of the ORM to access the query_store.
+  ## use_proxy=true
+
   [[query_store]]
     # URL of Query Store API server.
     ##server_url=http://localhost:8080/

+ 3 - 0
desktop/conf/pseudo-distributed.ini.tmpl

@@ -1641,6 +1641,9 @@
   # Show the Queries section for listing Hive/Impala query history and providing more troubleshooting information.
   ## enable_queries_list=false
 
+  # Use the proxy API instead of the ORM to access the query_store.
+  ## use_proxy=true
+
   [[query_store]]
     # URL of Query Store API server.
     ##server_url=http://localhost:8080/