Unverified Commit f29bb3ba authored by Tao Feng's avatar Tao Feng Committed by GitHub

Update dashboard ES document (#236)

* Update dashboard ES document

* bump deps

* update tests

* update search query

* fix flake8
parent c4878da2
...@@ -69,22 +69,26 @@ class Neo4jSearchDataExtractor(Extractor): ...@@ -69,22 +69,26 @@ class Neo4jSearchDataExtractor(Extractor):
""" """
) )
# todo: 1. change total_read once we have the usage; # todo: 1. change mode to generic once add more support for dashboard
# 2. add more fields once we have in the graph; 3. change mode to generic once add more support for dashboard
DEFAULT_NEO4J_DASHBOARD_CYPHER_QUERY = textwrap.dedent( DEFAULT_NEO4J_DASHBOARD_CYPHER_QUERY = textwrap.dedent(
""" """
MATCH (dashboard:Dashboard) MATCH (db:Dashboard)
OPTIONAL MATCH (dashboard)-[:DASHBOARD_OF]->(dbg:Dashboardgroup) MATCH (db)-[:DASHBOARD_OF]->(dbg:Dashboardgroup)
OPTIONAL MATCH (dashboard)-[:DESCRIPTION]->(db_descr:Description) MATCH (dbg)-[:DASHBOARD_GROUP_OF]->(cluster:Cluster)
OPTIONAL MATCH (db)-[:DESCRIPTION]->(db_descr:Description)
OPTIONAL MATCH (dbg)-[:DESCRIPTION]->(dbg_descr:Description) OPTIONAL MATCH (dbg)-[:DESCRIPTION]->(dbg_descr:Description)
{publish_tag_filter} OPTIONAL MATCH (db)-[:EXECUTED]->(last_exec:Execution)
with dashboard, dbg, db_descr, dbg_descr WHERE split(last_exec.key, '/')[5] = '_last_successful_execution'
where dashboard.name is not null OPTIONAL MATCH (db)-[read:READ_BY]->(user:User)
return dbg.name as dashboard_group, dashboard.name as dashboard_name, OPTIONAL MATCH (db)-[:HAS_QUERY]->(query:Query)
with db, dbg, db_descr, dbg_descr, cluster, last_exec, query, SUM(read.read_count) AS total_usage
return dbg.name as dashboard_group, db.name as dashboard_name, cluster.name as cluster,
coalesce(db_descr.description, '') as description, coalesce(db_descr.description, '') as description,
coalesce(dbg.description, '') as dashboard_group_description, coalesce(dbg.description, '') as dashboard_group_description, dbg.dashboard_group_url as group_url,
'mode' as product, db.dashboard_url as url, db.key as uri,
1 AS total_usage 'mode' as product, last_exec.timestamp as last_successful_run_timestamp,
COLLECT(DISTINCT query.name) as query_names,
total_usage
order by dbg.name order by dbg.name
""" """
) )
......
...@@ -13,14 +13,26 @@ class DashboardESDocument(ElasticsearchDocument): ...@@ -13,14 +13,26 @@ class DashboardESDocument(ElasticsearchDocument):
description, # type: Union[str, None] description, # type: Union[str, None]
total_usage, # type: int total_usage, # type: int
product='', # type: Optional[str] product='', # type: Optional[str]
cluster='', # type: Optional[str]
dashboard_group_description=None, # type: Optional[str] dashboard_group_description=None, # type: Optional[str]
query_names=None, # type: Union[List[str], None]
group_url=None, # type: Optional[str]
url=None, # type: Optional[str]
uri=None, # type: Optional[str]
last_successful_run_timestamp=None, # type: Optional[int]
tags=None # type: list tags=None # type: list
): ):
# type: (...) -> None # type: (...) -> None
self.dashboard_group = dashboard_group self.dashboard_group = dashboard_group
self.dashboard_name = dashboard_name self.dashboard_name = dashboard_name
self.description = description self.description = description
self.cluster = cluster
self.product = product self.product = product
self.group_url = group_url
self.url = url
self.uri = uri
self.last_successful_run_timestamp = last_successful_run_timestamp
self.total_usage = total_usage self.total_usage = total_usage
self.dashboard_group_description = dashboard_group_description self.dashboard_group_description = dashboard_group_description
self.query_names = query_names
self.tags = tags self.tags = tags
...@@ -2,7 +2,7 @@ import os ...@@ -2,7 +2,7 @@ import os
from setuptools import setup, find_packages from setuptools import setup, find_packages
__version__ = '2.5.0' __version__ = '2.5.1'
requirements_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'requirements.txt') requirements_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'requirements.txt')
with open(requirements_path) as requirements_file: with open(requirements_path) as requirements_file:
......
...@@ -15,7 +15,13 @@ class TestDashboardElasticsearchDocument(unittest.TestCase): ...@@ -15,7 +15,13 @@ class TestDashboardElasticsearchDocument(unittest.TestCase):
dashboard_name='test_dashboard_name', dashboard_name='test_dashboard_name',
description='test_description', description='test_description',
product='mode', product='mode',
cluster='gold',
dashboard_group_description='work space group', dashboard_group_description='work space group',
query_names=['query1'],
group_url='mode_group_url',
url='mode_report_url',
uri='mode_dashboard://gold.cluster/dashboard_group/dashboard',
last_successful_run_timestamp=10,
total_usage=10, total_usage=10,
tags=['test']) tags=['test'])
...@@ -23,6 +29,12 @@ class TestDashboardElasticsearchDocument(unittest.TestCase): ...@@ -23,6 +29,12 @@ class TestDashboardElasticsearchDocument(unittest.TestCase):
"dashboard_name": "test_dashboard_name", "dashboard_name": "test_dashboard_name",
"description": "test_description", "description": "test_description",
"product": "mode", "product": "mode",
"cluster": "gold",
"group_url": "mode_group_url",
"url": "mode_report_url",
"uri": "mode_dashboard://gold.cluster/dashboard_group/dashboard",
"query_names": ['query1'],
"last_successful_run_timestamp": 10,
"dashboard_group_description": "work space group", "dashboard_group_description": "work space group",
"total_usage": 10, "total_usage": 10,
"tags": ["test"] "tags": ["test"]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment