Skip to content

feat: add connection info to command on the CLI#3356

Merged
izeigerman merged 6 commits intoSQLMesh:mainfrom
Kayrnt:info-connection
Nov 13, 2024
Merged

feat: add connection info to command on the CLI#3356
izeigerman merged 6 commits intoSQLMesh:mainfrom
Kayrnt:info-connection

Conversation

@Kayrnt
Copy link
Contributor

@Kayrnt Kayrnt commented Nov 10, 2024

Description

Adds connection details to help users to ensure that the project is configured as expected.
The output looks like the following:

sqlmesh -p ./sqlmesh_project info
Models: 1
Macros: 0


Connection:
  concurrent_tasks: 1
  execution_project: my-great-project
  job_retries: 1
  keyfile: '****'
  location: US
  method: oauth
  pre_ping: false
  priority: interactive
  project: my-great-project
  register_comments: true
  scopes:
  - https://www.googleapis.com/auth/bigquery
  type: bigquery




Test Connection:
  concurrent_tasks: 1
  execution_project: my-great-project
  job_retries: 1
  keyfile: '****'
  location: US
  method: oauth
  pre_ping: false
  priority: interactive
  project: my-great-project
  register_comments: true
  scopes:
  - https://www.googleapis.com/auth/bigquery
  type: bigquery




State Connection:
  concurrent_tasks: 1
  connector_config: {}
  database: local_state.db
  extensions: []
  pre_ping: false
  register_comments: true
  type: duckdb


Data warehouse connection succeeded
State backend connection succeeded

@Kayrnt Kayrnt marked this pull request as ready for review November 10, 2024 23:26

def get_sensitive_fields(self) -> Set[str]:
"""Returns a set of common sensitive field names"""
return {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea! Thanks for pointing out!

strict=strict,
)

def get_sensitive_fields(self) -> Set[str]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be a method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be a just a value then?

"ssh_key",
}

def is_sensitive_field(self, field_name: str, sensitive_fields: Set[str]) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be a method. Let's move this to utils along with the list of sensitive fields.

field_lower = field_name.lower()
return any(sensitive in field_lower for sensitive in sensitive_fields)

def mask_sensitive_value(self, value: Any) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

return "*" * len(str(value))
return "None"

def print_config(self, config: ConnectionConfig | None, console: Any) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's already self available, why pass console as an argument? Also let's make this private (prefix with _). We should be careful about adding public methods to the Context since it's a gateway into SQLMesh Python API.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also be a candidate for utils

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, do you prefer that I create a dedicated utils file for that?

self.console.log_status_update(f"Models: {len(self.models)}")
self.console.log_status_update(f"Macros: {len(self._macros) - len(macro.get_registry())}")

self.console.log_status_update("\n\nConnection:")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make the headers more pronounced? Otherwise they blend in with individual connection attributes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you do that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can make it bold by adding appropriate tags, eg:

self.console.log_status_update("\n\n[bold]Connection:[/bold]")

Ideally we also want to indent everything that follows under the configuration. This way we may not even need to do the highlighting.

Actually, can we just put this into dict and serialize as YAML instead? Eg.:

config = {"Test Connection": { ... }}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I can try that

@Kayrnt
Copy link
Contributor Author

Kayrnt commented Nov 11, 2024

@izeigerman, I moved the code but I didn't make any change yet regarding the template for the info output.

@@ -0,0 +1,71 @@
from typing import Any, Optional, Set
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's call make this module more descriptive by calling it config.py since everything here is related to configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright! I updated the PR.

console.log_status_update("No connection configuration found.")
return

configDict = config.dict(mode="json")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
configDict = config.dict(mode="json")
config_dict = config.dict(mode="json")


configDict = config.dict(mode="json")

for field_name in configDict:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for field_name in configDict:
for field_name in config_dict:

from typing import Any, Optional, Set

from sqlmesh.core.config.connection import ConnectionConfig
import yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from sqlmesh.utils import yaml

@izeigerman izeigerman merged commit c66efd3 into SQLMesh:main Nov 13, 2024
@github-christophe-oudar

Thank you for the review and merge 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants