-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial support for dashboard search
- Loading branch information
feng-tao
committed
Apr 10, 2020
1 parent
f368576
commit ffa1c55
Showing
10 changed files
with
264 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
from http import HTTPStatus | ||
from typing import Iterable, Any | ||
|
||
from flask_restful import fields, Resource, marshal_with, reqparse # noqa: I201 | ||
from flasgger import swag_from | ||
from amundsen_common.models.dashboard import DashboardSummary, DashboardSummarySchema | ||
|
||
from search_service.proxy import get_proxy_client | ||
|
||
|
||
DASHBOARD_INDEX = 'dashboard_search_index' | ||
|
||
|
||
# Use common | ||
dashboard_fields = { | ||
"uri": fields.String, | ||
"cluster": fields.String, | ||
"group_name": fields.String, | ||
"group_url": fields.String, | ||
"product": fields.String, | ||
"name": fields.String, | ||
"url": fields.String, | ||
"description": fields.String, | ||
"last_successful_run_timestamp": fields.Integer | ||
} | ||
|
||
search_dashboard_results = { | ||
"total_results": fields.Integer, | ||
"results": fields.Nested(DashboardSummary, default=[]) | ||
} | ||
|
||
|
||
class SearchDashboardAPI(Resource): | ||
""" | ||
Search Dashboard API | ||
""" | ||
|
||
def __init__(self) -> None: | ||
self.proxy = get_proxy_client() | ||
|
||
self.parser = reqparse.RequestParser(bundle_errors=True) | ||
|
||
self.parser.add_argument('query_term', required=True, type=str) | ||
self.parser.add_argument('page_index', required=False, default=0, type=int) | ||
self.parser.add_argument('index', required=False, default=DASHBOARD_INDEX, type=str) | ||
|
||
super(SearchDashboardAPI, self).__init__() | ||
|
||
@swag_from('swagger_doc/dashboard/search_dashboard.yml') | ||
def get(self) -> Iterable[Any]: | ||
""" | ||
Fetch dashboard search results based on query_term. | ||
:return: list of dashboard results. List can be empty if query | ||
doesn't match any dashboards | ||
""" | ||
args = self.parser.parse_args(strict=True) | ||
|
||
try: | ||
results = self.proxy.fetch_dashboard_search_result( | ||
query_term=args.get('query_term'), | ||
page_index=args['page_index'], | ||
index=args['index'] | ||
) | ||
|
||
return results, HTTPStatus.OK | ||
|
||
except RuntimeError: | ||
|
||
err_msg = 'Exception encountered while processing search request' | ||
return {'message': err_msg}, HTTPStatus.INTERNAL_SERVER_ERROR |
39 changes: 39 additions & 0 deletions
39
search_service/api/swagger_doc/dashboard/search_dashboard.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
Table search | ||
This is used by the frontend API to search dashboard information. | ||
--- | ||
tags: | ||
- 'search' | ||
parameters: | ||
- name: query_term | ||
in: query | ||
type: string | ||
schema: | ||
type: string | ||
required: true | ||
- name: page_index | ||
in: query | ||
type: integer | ||
schema: | ||
type: integer | ||
default: 0 | ||
required: false | ||
- name: index | ||
in: query | ||
type: string | ||
schema: | ||
type: string | ||
default: 'dashboard_search_index' | ||
required: false | ||
responses: | ||
200: | ||
description: dashboard result information | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/SearchDashboardResults' | ||
500: | ||
description: Exception encountered while searching | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/ErrorResponse' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from typing import List, Set | ||
|
||
import attr | ||
from marshmallow_annotations.ext.attrs import AttrsSchema | ||
from amundsen_common.models.dashboard import DashboardSummary, DashboardSummarySchema | ||
|
||
from search_service.models.base import Base | ||
|
||
|
||
@attr.s(auto_attribs=True, kw_only=True) | ||
class Dashboard(Base, | ||
DashboardSummary): | ||
""" | ||
This represents the part of a dashboard stored in the search proxy | ||
""" | ||
|
||
def get_id(self) -> str: | ||
# uses the table key as the document id in ES | ||
return self.name | ||
|
||
@classmethod | ||
def get_attrs(cls) -> Set: | ||
return { | ||
'uri', | ||
'cluster', | ||
'group_name', | ||
'group_url', | ||
'product', | ||
'name', | ||
'url', | ||
'description', | ||
'last_successful_run_timestamp' | ||
} | ||
|
||
@staticmethod | ||
def get_type() -> str: | ||
return 'dashboard' | ||
|
||
|
||
class DashboardSchema(DashboardSummarySchema): | ||
class Meta: | ||
target = Dashboard | ||
register_as_scheme = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters