-
Notifications
You must be signed in to change notification settings - Fork 56
Profiler CLI #1623
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
Open
sundarshankar89
wants to merge
11
commits into
feature/synapse_data_collector
Choose a base branch
from
feature/profiler_entry_point
base: feature/synapse_data_collector
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+164
−7
Open
Profiler CLI #1623
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e153a91
Initial commit with entry point
sundarshankar89 dab0fbf
fmt fixes
sundarshankar89 ba305ba
fmt fixes
sundarshankar89 76d2e1f
using DEVNULL for dependency installer
sundarshankar89 ef09e51
logger and fmt fixes
sundarshankar89 414574f
logger and fmt fixes
sundarshankar89 480a590
Merge branch 'feature/synapse_data_collector' into feature/profiler_e…
sundarshankar89 b23ad5f
Merge branch 'feature/synapse_data_collector' into feature/profiler_e…
sundarshankar89 ebce184
Merge branch 'feature/synapse_data_collector' into feature/profiler_e…
sundarshankar89 1991d8f
Merge branch 'feature/synapse_data_collector' into feature/profiler_e…
sundarshankar89 7900fba
Merge branch 'feature/synapse_data_collector' into feature/profiler_e…
sundarshankar89 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 hidden or 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 hidden or 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 hidden or 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,77 @@ | ||
import logging | ||
from pathlib import Path | ||
|
||
from databricks.labs.remorph.assessments.pipeline import PipelineClass | ||
from databricks.labs.remorph.assessments.profiler_config import PipelineConfig | ||
from databricks.labs.remorph.connections.database_manager import DatabaseManager | ||
from databricks.labs.remorph.connections.credential_manager import ( | ||
create_credential_manager, | ||
) | ||
from databricks.labs.remorph.connections.env_getter import EnvGetter | ||
|
||
_PLATFORM_TO_SOURCE_TECHNOLOGY = { | ||
"Synapse": "src/databricks/labs/remorph/resources/assessments/synapse/pipeline_config.yml", | ||
} | ||
|
||
_CONNECTOR_REQUIRED = { | ||
"Synapse": False, | ||
} | ||
|
||
PRODUCT_NAME = "remorph" | ||
PRODUCT_PATH_PREFIX = Path(__file__).home() / ".databricks" / "labs" / PRODUCT_NAME / "lib" | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Profiler: | ||
|
||
@classmethod | ||
def supported_source_technologies(cls) -> list[str]: | ||
return list(_PLATFORM_TO_SOURCE_TECHNOLOGY.keys()) | ||
|
||
@staticmethod | ||
def path_modifier(config_file: str | Path) -> PipelineConfig: | ||
# TODO: Make this work install during developer mode | ||
config = PipelineClass.load_config_from_yaml(config_file) | ||
for step in config.steps: | ||
step.extract_source = f"{PRODUCT_PATH_PREFIX}/{step.extract_source}" | ||
return config | ||
|
||
def profile(self, platform: str, extractor: DatabaseManager | None = None): | ||
config_path = _PLATFORM_TO_SOURCE_TECHNOLOGY.get(platform, None) | ||
if not config_path: | ||
raise ValueError(f"Unsupported platform: {platform}") | ||
self._execute(platform, config_path, extractor) | ||
|
||
def _setup_extractor(self, platform: str) -> DatabaseManager | None: | ||
if not _CONNECTOR_REQUIRED[platform]: | ||
return None | ||
cred_manager = create_credential_manager(PRODUCT_NAME, EnvGetter()) | ||
connect_config = cred_manager.get_credentials(platform) | ||
return DatabaseManager(platform, connect_config) | ||
|
||
def _execute(self, platform: str, config_path: str, extractor=None): | ||
try: | ||
config_full_path = self._locate_config(config_path) | ||
config = Profiler.path_modifier(config_full_path) | ||
|
||
if extractor is None: | ||
extractor = self._setup_extractor(platform) | ||
|
||
results = PipelineClass(config, extractor).execute() | ||
|
||
for result in results: | ||
logger.info(f"Step: {result.step_name}, Status: {result.status}, Error: {result.error_message}") | ||
|
||
except FileNotFoundError as e: | ||
logging.error(f"Configuration file not found for source {platform}: {e}") | ||
raise FileNotFoundError(f"Configuration file not found for source {platform}: {e}") from e | ||
except Exception as e: | ||
logging.error(f"Error executing pipeline for source {platform}: {e}") | ||
raise RuntimeError(f"Pipeline execution failed for source {platform} : {e}") from e | ||
|
||
def _locate_config(self, config_path: str) -> Path: | ||
config_file = PRODUCT_PATH_PREFIX / config_path | ||
if not config_file.exists(): | ||
raise FileNotFoundError(f"Configuration file not found: {config_file}") | ||
return config_file |
This file contains hidden or 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 hidden or 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 hidden or 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,45 @@ | ||
from pathlib import Path | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
from databricks.labs.remorph.assessments.profiler import Profiler | ||
|
||
|
||
def test_supported_source_technologies(): | ||
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. Remember to add |
||
"""Test that supported source technologies are correctly returned""" | ||
profiler = Profiler() | ||
supported_platforms = profiler.supported_source_technologies() | ||
assert isinstance(supported_platforms, list) | ||
assert "Synapse" in supported_platforms | ||
|
||
|
||
def test_profile_unsupported_platform(): | ||
"""Test that profiling an unsupported platform raises ValueError""" | ||
profiler = Profiler() | ||
with pytest.raises(ValueError, match="Unsupported platform: InvalidPlatform"): | ||
profiler.profile("InvalidPlatform") | ||
|
||
|
||
@patch( | ||
'databricks.labs.remorph.assessments.profiler._PLATFORM_TO_SOURCE_TECHNOLOGY', | ||
{"Synapse": "tests/resources/assessments/pipeline_config_main.yml"}, | ||
) | ||
@patch('databricks.labs.remorph.assessments.profiler.PRODUCT_PATH_PREFIX', Path(__file__).parent / "../../../") | ||
def test_profile_execution(): | ||
"""Test successful profiling execution using actual pipeline configuration""" | ||
profiler = Profiler() | ||
profiler.profile("Synapse") | ||
assert Path("/tmp/profiler_main/profiler_extract.db").exists(), "Profiler extract database should be created" | ||
|
||
|
||
@patch( | ||
'databricks.labs.remorph.assessments.profiler._PLATFORM_TO_SOURCE_TECHNOLOGY', | ||
{"Synapse": "tests/resources/assessments/synapse/pipeline_config_main.yml"}, | ||
) | ||
def test_profile_execution_with_invalid_config(): | ||
"""Test profiling execution with invalid configuration""" | ||
with patch('pathlib.Path.exists', return_value=False): | ||
profiler = Profiler() | ||
with pytest.raises(FileNotFoundError): | ||
profiler.profile("Synapse") |
This file contains hidden or 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,13 @@ | ||
name: ExamplePipeline | ||
version: "1.0" | ||
extract_folder: /tmp/profiler_main/ | ||
steps: | ||
- name: random_data | ||
type: python | ||
extract_source: tests/resources/assessments/db_extract.py | ||
mode: overwrite | ||
frequency: daily | ||
flag: active | ||
dependencies: | ||
- pandas | ||
- duckdb |
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.
What does Install assessment do?
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.
may be configure-assessment would be better word, it configures crednetials
Uh oh!
There was an error while loading. Please reload this page.
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.
These credentials are the same we would use for Reconcile, no? Can we call it
configure-source-credentials
or something purposeful like that?