Skip to content

Commit f29bb3b

Browse files
authored
Update dashboard ES document (#236)
* Update dashboard ES document * bump deps * update tests * update search query * fix flake8
1 parent c4878da commit f29bb3b

File tree

4 files changed

+41
-13
lines changed

4 files changed

+41
-13
lines changed

databuilder/extractor/neo4j_search_data_extractor.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,26 @@ class Neo4jSearchDataExtractor(Extractor):
6969
"""
7070
)
7171

72-
# todo: 1. change total_read once we have the usage;
73-
# 2. add more fields once we have in the graph; 3. change mode to generic once add more support for dashboard
72+
# todo: 1. change mode to generic once add more support for dashboard
7473
DEFAULT_NEO4J_DASHBOARD_CYPHER_QUERY = textwrap.dedent(
7574
"""
76-
MATCH (dashboard:Dashboard)
77-
OPTIONAL MATCH (dashboard)-[:DASHBOARD_OF]->(dbg:Dashboardgroup)
78-
OPTIONAL MATCH (dashboard)-[:DESCRIPTION]->(db_descr:Description)
75+
MATCH (db:Dashboard)
76+
MATCH (db)-[:DASHBOARD_OF]->(dbg:Dashboardgroup)
77+
MATCH (dbg)-[:DASHBOARD_GROUP_OF]->(cluster:Cluster)
78+
OPTIONAL MATCH (db)-[:DESCRIPTION]->(db_descr:Description)
7979
OPTIONAL MATCH (dbg)-[:DESCRIPTION]->(dbg_descr:Description)
80-
{publish_tag_filter}
81-
with dashboard, dbg, db_descr, dbg_descr
82-
where dashboard.name is not null
83-
return dbg.name as dashboard_group, dashboard.name as dashboard_name,
80+
OPTIONAL MATCH (db)-[:EXECUTED]->(last_exec:Execution)
81+
WHERE split(last_exec.key, '/')[5] = '_last_successful_execution'
82+
OPTIONAL MATCH (db)-[read:READ_BY]->(user:User)
83+
OPTIONAL MATCH (db)-[:HAS_QUERY]->(query:Query)
84+
with db, dbg, db_descr, dbg_descr, cluster, last_exec, query, SUM(read.read_count) AS total_usage
85+
return dbg.name as dashboard_group, db.name as dashboard_name, cluster.name as cluster,
8486
coalesce(db_descr.description, '') as description,
85-
coalesce(dbg.description, '') as dashboard_group_description,
86-
'mode' as product,
87-
1 AS total_usage
87+
coalesce(dbg.description, '') as dashboard_group_description, dbg.dashboard_group_url as group_url,
88+
db.dashboard_url as url, db.key as uri,
89+
'mode' as product, last_exec.timestamp as last_successful_run_timestamp,
90+
COLLECT(DISTINCT query.name) as query_names,
91+
total_usage
8892
order by dbg.name
8993
"""
9094
)

databuilder/models/dashboard_elasticsearch_document.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,26 @@ def __init__(self,
1313
description, # type: Union[str, None]
1414
total_usage, # type: int
1515
product='', # type: Optional[str]
16+
cluster='', # type: Optional[str]
1617
dashboard_group_description=None, # type: Optional[str]
18+
query_names=None, # type: Union[List[str], None]
19+
group_url=None, # type: Optional[str]
20+
url=None, # type: Optional[str]
21+
uri=None, # type: Optional[str]
22+
last_successful_run_timestamp=None, # type: Optional[int]
1723
tags=None # type: list
1824
):
1925
# type: (...) -> None
2026
self.dashboard_group = dashboard_group
2127
self.dashboard_name = dashboard_name
2228
self.description = description
29+
self.cluster = cluster
2330
self.product = product
31+
self.group_url = group_url
32+
self.url = url
33+
self.uri = uri
34+
self.last_successful_run_timestamp = last_successful_run_timestamp
2435
self.total_usage = total_usage
2536
self.dashboard_group_description = dashboard_group_description
37+
self.query_names = query_names
2638
self.tags = tags

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from setuptools import setup, find_packages
33

44

5-
__version__ = '2.5.0'
5+
__version__ = '2.5.1'
66

77
requirements_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'requirements.txt')
88
with open(requirements_path) as requirements_file:

tests/unit/models/test_dashboard_elasticsearch_document.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,26 @@ def test_to_json(self):
1515
dashboard_name='test_dashboard_name',
1616
description='test_description',
1717
product='mode',
18+
cluster='gold',
1819
dashboard_group_description='work space group',
20+
query_names=['query1'],
21+
group_url='mode_group_url',
22+
url='mode_report_url',
23+
uri='mode_dashboard://gold.cluster/dashboard_group/dashboard',
24+
last_successful_run_timestamp=10,
1925
total_usage=10,
2026
tags=['test'])
2127

2228
expected_document_dict = {"dashboard_group": "test_dashboard_group",
2329
"dashboard_name": "test_dashboard_name",
2430
"description": "test_description",
2531
"product": "mode",
32+
"cluster": "gold",
33+
"group_url": "mode_group_url",
34+
"url": "mode_report_url",
35+
"uri": "mode_dashboard://gold.cluster/dashboard_group/dashboard",
36+
"query_names": ['query1'],
37+
"last_successful_run_timestamp": 10,
2638
"dashboard_group_description": "work space group",
2739
"total_usage": 10,
2840
"tags": ["test"]

0 commit comments

Comments
 (0)