-
Notifications
You must be signed in to change notification settings - Fork 80
Add SQL Server Profiler #2151
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
goodwillpunning
wants to merge
14
commits into
main
Choose a base branch
from
feature/add_mssql_profiler
base: main
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.
Open
Add SQL Server Profiler #2151
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
5e4ff3d
Add initial MSSQL profiler files
goodwillpunning bd40c8a
Add activity extract tables.
goodwillpunning 4ba54c3
Merge branch 'main' into feature/add_mssql_profiler
goodwillpunning 46f5e75
Add info extract queries.
goodwillpunning 866bfc7
Add info extraction step.
goodwillpunning 6db273d
Update MSSQL configuration
goodwillpunning 60c38d8
Update common DuckDB helpers with MSSQL schemas
goodwillpunning adbaf7a
Add missing pipeline dependency
goodwillpunning 5a8185f
Merge branch 'main' into feature/add_mssql_profiler
goodwillpunning 6a1c150
Update MSSQL prompt.
goodwillpunning 777e9d1
Fix arg parsing.
goodwillpunning 1d39231
Remove loop through all SQL servers in subscription.
goodwillpunning 60a1f05
Refactor info extract script.
goodwillpunning 42d0028
Simplify config prompts.
goodwillpunning 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
Empty file.
72 changes: 72 additions & 0 deletions
72
src/databricks/labs/lakebridge/resources/assessments/mssql/activity_extract.py
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,72 @@ | ||
| import json | ||
| import sys | ||
|
|
||
| from databricks.labs.lakebridge.connections.credential_manager import create_credential_manager | ||
| from databricks.labs.lakebridge.assessments import PRODUCT_NAME | ||
| from databricks.labs.lakebridge.resources.assessments.mssql.common.connector import get_sqlserver_reader | ||
| from databricks.labs.lakebridge.resources.assessments.mssql.common.queries import MSSQLQueries | ||
| from databricks.labs.lakebridge.resources.assessments.synapse.common.duckdb_helpers import save_resultset_to_db | ||
| from databricks.labs.lakebridge.resources.assessments.synapse.common.functions import arguments_loader, set_logger | ||
|
|
||
|
|
||
| def execute(): | ||
| logger = set_logger(__file__) | ||
|
|
||
| db_path, creds_file = arguments_loader(desc="MSSQL Server Activity Extract Script") | ||
| cred_manager = create_credential_manager(PRODUCT_NAME, creds_file) | ||
| mssql_settings = cred_manager.get_credentials("mssql") | ||
| auth_type = mssql_settings.get("auth_type", "sql_authentication") | ||
| server_name = mssql_settings.get("server", "") | ||
| try: | ||
|
|
||
| # TODO: get the last time the profiler was executed | ||
| # For now, we'll default to None, but this will eventually need | ||
| # input from a scheduler component. | ||
| last_execution_time = None | ||
| mode = "overwrite" | ||
|
|
||
| # Extract activity metrics | ||
| logger.info(f"Extracting activity metrics for: {server_name}") | ||
| print(f"Extracting activity metrics for: {server_name}") | ||
| connection = get_sqlserver_reader( | ||
| mssql_settings, db_name="master", server_name=server_name, auth_type=auth_type | ||
| ) | ||
|
|
||
| # Query stats | ||
| table_name = "query_stats" | ||
| table_query = MSSQLQueries.get_query_stats(last_execution_time) | ||
| logger.info(f"Loading '{table_name}' for SQL server: {server_name}") | ||
| result = connection.fetch(table_query) | ||
| save_resultset_to_db(result, f"mssql_{table_name}", db_path, mode=mode) | ||
|
|
||
| # Stored procedure stats | ||
| table_name = "proc_stats" | ||
| table_query = MSSQLQueries.get_procedure_stats(last_execution_time) | ||
| logger.info(f"Loading '{table_name}' for SQL server: {server_name}") | ||
| result = connection.fetch(table_query) | ||
| save_resultset_to_db(result, f"mssql_{table_name}", db_path, mode=mode) | ||
|
|
||
| # Session info | ||
| table_name = "sessions" | ||
| table_query = MSSQLQueries.get_sessions(last_execution_time) | ||
| logger.info(f"Loading '{table_name}' for SQL server: {server_name}") | ||
| result = connection.fetch(table_query) | ||
| save_resultset_to_db(result, f"mssql_{table_name}", db_path, mode=mode) | ||
|
|
||
| # CPU Utilization | ||
| table_name = "cpu_utilization" | ||
| table_query = MSSQLQueries.get_cpu_utilization(last_execution_time) | ||
| logger.info(f"Loading '{table_name}' for SQL server: {server_name}") | ||
| result = connection.fetch(table_query) | ||
| save_resultset_to_db(result, f"mssql_{table_name}", db_path, mode=mode) | ||
|
|
||
| print(json.dumps({"status": "success", "message": "All data loaded successfully loaded successfully"})) | ||
|
|
||
| except Exception as e: | ||
| logger.error(f"Failed to extract activity info for SQL server: {str(e)}") | ||
| print(json.dumps({"status": "error", "message": str(e)}), file=sys.stderr) | ||
| sys.exit(1) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| execute() |
Empty file.
22 changes: 22 additions & 0 deletions
22
src/databricks/labs/lakebridge/resources/assessments/mssql/common/connector.py
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,22 @@ | ||
| from databricks.labs.lakebridge.connections.database_manager import DatabaseManager | ||
|
|
||
|
|
||
| def get_sqlserver_reader( | ||
| input_cred: dict, | ||
| db_name: str, | ||
| *, | ||
| server_name: str, | ||
| auth_type: str = 'sql_authentication', | ||
| ) -> DatabaseManager: | ||
| config = { | ||
| "driver": input_cred['driver'], | ||
| "server": server_name, | ||
| "database": db_name, | ||
| "user": input_cred['user'], | ||
| "password": input_cred['password'], | ||
| "port": input_cred.get('port', 1433), | ||
| "auth_type": auth_type, | ||
| } | ||
| source = "mssql" | ||
|
|
||
| return DatabaseManager(source, config) | ||
9 changes: 9 additions & 0 deletions
9
src/databricks/labs/lakebridge/resources/assessments/mssql/common/functions.py
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,9 @@ | ||
| from azure.identity import DefaultAzureCredential | ||
| from azure.mgmt.sql import SqlManagementClient | ||
|
|
||
|
|
||
| def create_msql_sql_client(config: dict) -> SqlManagementClient: | ||
| """ | ||
| Creates an Azure SQL management client for the provided subscription using the default Azure credential. | ||
| """ | ||
| return SqlManagementClient(credential=DefaultAzureCredential(), subscription_id=config["subscription_id"]) |
Oops, something went wrong.
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.
Database manager should already have the MSSQLConnector we should be using that.