-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ingestion/tableau): introduce project_path_pattern #10855
Merged
hsheth2
merged 12 commits into
datahub-project:master
from
haeniya:feature/add-exclusive-project-path-pattern
Sep 27, 2024
+645
−26
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1b5cfb9
introduce platform_path_pattern
2f02caf
Merge branch 'master' of https://github.com/haeniya/datahub into feat…
cd9b9cb
revert removal of extract_project_hierarchy config property
6724969
fix linting issues
891928c
Merge branch 'master' of https://github.com/haeniya/datahub into feat…
135428e
change description and fix project hierarchy bug
59300c2
Merge branch 'master' into feature/add-exclusive-project-path-pattern
haeniya 3b91a2d
Merge branch 'master' into feature/add-exclusive-project-path-pattern
haeniya e26aec9
deprecate project_pattern
721f3ab
fix linting issues
d73b058
add new tests for project_path_pattern
90c407f
Merge branch 'master' into feature/add-exclusive-project-path-pattern
haeniya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -313,12 +313,22 @@ class TableauConfig( | |
# Tableau project pattern | ||
project_pattern: AllowDenyPattern = Field( | ||
default=AllowDenyPattern.allow_all(), | ||
description="Filter for specific Tableau projects. For example, use 'My Project' to ingest a root-level Project with name 'My Project', or 'My Project/Nested Project' to ingest a nested Project with name 'Nested Project'. " | ||
description="[deprecated] Use project_path_pattern instead. Filter for specific Tableau projects. For example, use 'My Project' to ingest a root-level Project with name 'My Project', or 'My Project/Nested Project' to ingest a nested Project with name 'Nested Project'. " | ||
"By default, all Projects nested inside a matching Project will be included in ingestion. " | ||
"You can both allow and deny projects based on their name using their name, or a Regex pattern. " | ||
"Deny patterns always take precedence over allow patterns. " | ||
"By default, all projects will be ingested.", | ||
) | ||
_deprecate_projects_pattern = pydantic_field_deprecated("project_pattern") | ||
|
||
project_path_pattern: AllowDenyPattern = Field( | ||
default=AllowDenyPattern.allow_all(), | ||
description="Filters Tableau projects by their full path. For instance, 'My Project/Nested Project' targets a specific nested project named 'Nested Project'." | ||
" This is also useful when you need to exclude all nested projects under a particular project." | ||
" You can allow or deny projects by specifying their path or a regular expression pattern." | ||
" Deny patterns always override allow patterns." | ||
" By default, all projects are ingested.", | ||
) | ||
|
||
project_path_separator: str = Field( | ||
default="/", | ||
|
@@ -454,17 +464,23 @@ class TableauConfig( | |
def projects_backward_compatibility(cls, values: Dict) -> Dict: | ||
projects = values.get("projects") | ||
project_pattern = values.get("project_pattern") | ||
if project_pattern is None and projects: | ||
project_path_pattern = values.get("project_path_pattern") | ||
if project_pattern is None and project_path_pattern is None and projects: | ||
logger.warning( | ||
"project_pattern is not set but projects is set. projects is deprecated, please use " | ||
"project_pattern instead." | ||
"projects is deprecated, please use " "project_path_pattern instead." | ||
) | ||
logger.info("Initializing project_pattern from projects") | ||
values["project_pattern"] = AllowDenyPattern( | ||
allow=[f"^{prj}$" for prj in projects] | ||
) | ||
elif project_pattern != AllowDenyPattern.allow_all() and projects: | ||
raise ValueError("projects is deprecated. Please use project_pattern only.") | ||
elif (project_pattern or project_path_pattern) and projects: | ||
raise ValueError( | ||
"projects is deprecated. Please use project_path_pattern only." | ||
) | ||
elif project_path_pattern and project_pattern: | ||
raise ValueError( | ||
"project_pattern is deprecated. Please use project_path_pattern only." | ||
) | ||
|
||
return values | ||
|
||
|
@@ -850,12 +866,13 @@ def form_path(project_id: str) -> List[str]: | |
|
||
def _is_allowed_project(self, project: TableauProject) -> bool: | ||
# Either project name or project path should exist in allow | ||
is_allowed: bool = self.config.project_pattern.allowed( | ||
project.name | ||
) or self.config.project_pattern.allowed(self._get_project_path(project)) | ||
is_allowed: bool = ( | ||
self.config.project_pattern.allowed(project.name) | ||
or self.config.project_pattern.allowed(self._get_project_path(project)) | ||
) and self.config.project_path_pattern.allowed(self._get_project_path(project)) | ||
if is_allowed is False: | ||
logger.info( | ||
f"project({project.name}) is not allowed as per project_pattern" | ||
f"Project ({project.name}) is not allowed as per project_pattern or project_path_pattern" | ||
) | ||
return is_allowed | ||
|
||
|
@@ -887,28 +904,29 @@ def _init_tableau_project_registry(self, all_project_map: dict) -> None: | |
logger.debug(f"Project {project.name} is added in project registry") | ||
projects_to_ingest[project.id] = project | ||
|
||
# We rely on automatic browse paths (v2) when creating containers. That's why we need to sort the projects here. | ||
# Otherwise, nested projects will not have the correct browse paths if not created in correct order / hierarchy. | ||
self.tableau_project_registry = OrderedDict( | ||
sorted(projects_to_ingest.items(), key=lambda item: len(item[1].path)) | ||
) | ||
|
||
if self.config.extract_project_hierarchy is False: | ||
logger.debug( | ||
"Skipping project hierarchy processing as configuration extract_project_hierarchy is " | ||
"disabled" | ||
) | ||
return | ||
else: | ||
logger.debug( | ||
"Reevaluating projects as extract_project_hierarchy is enabled" | ||
) | ||
|
||
logger.debug("Reevaluating projects as extract_project_hierarchy is enabled") | ||
for project in list_of_skip_projects: | ||
if ( | ||
project.parent_id in projects_to_ingest | ||
and self._is_denied_project(project) is False | ||
): | ||
logger.debug(f"Project {project.name} is added in project registry") | ||
projects_to_ingest[project.id] = project | ||
|
||
for project in list_of_skip_projects: | ||
if ( | ||
project.parent_id in self.tableau_project_registry | ||
and self._is_denied_project(project) is False | ||
): | ||
logger.debug(f"Project {project.name} is added in project registry") | ||
self.tableau_project_registry[project.id] = project | ||
# We rely on automatic browse paths (v2) when creating containers. That's why we need to sort the projects here. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I reverted the changes to include the extract_project_hierarchy part again, as discussed. However, I slightly refactored it so we do the sorting below at the very end for all the projects to ingest. Let me know if you see any problem with this. |
||
# Otherwise, nested projects will not have the correct browse paths if not created in correct order / hierarchy. | ||
self.tableau_project_registry = OrderedDict( | ||
sorted(projects_to_ingest.items(), key=lambda item: len(item[1].path)) | ||
) | ||
|
||
def _init_datasource_registry(self) -> None: | ||
if self.server is None: | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sid-acryl I now deprecated
project_pattern
but I wanted to point out that for now this validation rule still initializesproject_pattern
whenprojects
is set. Ideally, we would remove the oldprojects
completely now but I tried it and it would require quite some refactoring in the tests.