Skip to content

Commit

Permalink
Add support for Tableau multi-site deployment
Browse files Browse the repository at this point in the history
Tableau supports multi-tenancy as "site", but current databuilder
implementation does not support the feature.
Now, dashboard_url and dashboard_group_url contain site name
(e.g. https://tableau-server/#/site/my-site/...).

Signed-off-by: Shuichiro MAKIGAKI <[email protected]>
  • Loading branch information
shuichiro-makigaki committed Mar 26, 2021
1 parent a579a96 commit dddf7a1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class TableauGraphQLApiMetadataExtractor(TableauGraphQLApiExtractor):

CLUSTER = const.CLUSTER
EXCLUDED_PROJECTS = const.EXCLUDED_PROJECTS
SITE_NAME = const.SITE_NAME
TABLEAU_BASE_URL = const.TABLEAU_BASE_URL

def execute(self) -> Iterator[Dict[str, Any]]:
Expand All @@ -39,6 +40,10 @@ def execute(self) -> Iterator[Dict[str, Any]]:
if workbook['projectName'] not in
self._conf.get_list(TableauGraphQLApiMetadataExtractor.EXCLUDED_PROJECTS, [])]
base_url = self._conf.get(TableauGraphQLApiMetadataExtractor.TABLEAU_BASE_URL)
site_name = self._conf.get_string(TableauGraphQLApiMetadataExtractor.SITE_NAME)
site_url_path = ""
if site_name != "":
site_url_path = f'/site/{site_name}'
for workbook in workbooks_data:
if None in (workbook['projectName'], workbook['name']):
LOGGER.warning(f'Ignoring workbook (ID:{workbook["vizportalUrlId"]}) ' +
Expand All @@ -49,8 +54,8 @@ def execute(self) -> Iterator[Dict[str, Any]]:
'dashboard_name': TableauDashboardUtils.sanitize_workbook_name(workbook['name']),
'description': workbook.get('description', ''),
'created_timestamp': workbook['createdAt'],
'dashboard_group_url': f'{base_url}/#/projects/{workbook["projectVizportalUrlId"]}',
'dashboard_url': f'{base_url}/#/workbooks/{workbook["vizportalUrlId"]}/views',
'dashboard_group_url': f'{base_url}/#{site_url_path}/projects/{workbook["projectVizportalUrlId"]}',
'dashboard_url': f'{base_url}/#{site_url_path}/workbooks/{workbook["vizportalUrlId"]}/views',
'cluster': self._conf.get_string(TableauGraphQLApiMetadataExtractor.CLUSTER)
}
yield data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class TestTableauDashboardExtractor(unittest.TestCase):
def test_dashboard_metadata_extractor(self) -> None:

config = ConfigFactory.from_dict({
'extractor.tableau_dashboard_metadata.api_base_url': 'api_base_url',
'extractor.tableau_dashboard_metadata.tableau_base_url': 'tableau_base_url',
'extractor.tableau_dashboard_metadata.api_base_url': 'https://api_base_url',
'extractor.tableau_dashboard_metadata.tableau_base_url': 'https://tableau_base_url',
'extractor.tableau_dashboard_metadata.api_version': 'tableau_api_version',
'extractor.tableau_dashboard_metadata.site_name': 'tableau_site_name',
'extractor.tableau_dashboard_metadata.tableau_personal_access_token_name':
Expand All @@ -79,6 +79,43 @@ def test_dashboard_metadata_extractor(self) -> None:
self.assertEqual(record.dashboard_group, 'Test Project')
self.assertEqual(record.product, 'tableau')
self.assertEqual(record.cluster, 'tableau_dashboard_cluster')
self.assertEqual(record.dashboard_group_url, 'https://tableau_base_url/#/site/tableau_site_name/projects/123')
self.assertEqual(record.dashboard_url, 'https://tableau_base_url/#/site/tableau_site_name/workbooks/456/views')
self.assertEqual(record.created_timestamp, 1586323921)

record = extractor.extract()
self.assertIsNone(record)

# Test for Tableau single site deployment
config = ConfigFactory.from_dict({
'extractor.tableau_dashboard_metadata.api_base_url': 'https://api_base_url',
'extractor.tableau_dashboard_metadata.tableau_base_url': 'https://tableau_base_url',
'extractor.tableau_dashboard_metadata.api_version': 'tableau_api_version',
'extractor.tableau_dashboard_metadata.site_name': '',
'extractor.tableau_dashboard_metadata.tableau_personal_access_token_name':
'tableau_personal_access_token_name',
'extractor.tableau_dashboard_metadata.tableau_personal_access_token_secret':
'tableau_personal_access_token_secret',
'extractor.tableau_dashboard_metadata.excluded_projects': [],
'extractor.tableau_dashboard_metadata.cluster': 'tableau_dashboard_cluster',
'extractor.tableau_dashboard_metadata.database': 'tableau_dashboard_database',
'extractor.tableau_dashboard_metadata.transformer.timestamp_str_to_epoch.timestamp_format':
'%Y-%m-%dT%H:%M:%SZ',

})

extractor = TableauDashboardExtractor()
extractor.init(Scoped.get_scoped_conf(conf=config, scope=extractor.get_scope()))

record = extractor.extract()
self.assertEqual(record.dashboard_id, 'Test Workbook')
self.assertEqual(record.dashboard_name, 'Test Workbook')
self.assertEqual(record.dashboard_group_id, 'Test Project')
self.assertEqual(record.dashboard_group, 'Test Project')
self.assertEqual(record.product, 'tableau')
self.assertEqual(record.cluster, 'tableau_dashboard_cluster')
self.assertEqual(record.dashboard_group_url, 'https://tableau_base_url/#/projects/123')
self.assertEqual(record.dashboard_url, 'https://tableau_base_url/#/workbooks/456/views')
self.assertEqual(record.created_timestamp, 1586323921)

record = extractor.extract()
Expand Down

0 comments on commit dddf7a1

Please sign in to comment.