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
Print table schema in DB initialization test #5248
Changes from 12 commits
8978467
c47dba7
1926377
77b65bc
3d74401
9285ade
b6dbab5
6759b73
f20817b
d9a71b2
ef56686
13578eb
e7681fc
4e8a2fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
** | ||
|
||
!dist/*.whl | ||
!log.py | ||
!init-mssql-db.sh | ||
!init-mssql-db.sql |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
schemas | ||
mlflowdb |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,9 +19,3 @@ RUN apt-get update && ACCEPT_EULA=Y apt-get install -y mssql-tools unixodbc-dev | |
RUN pip install dist/*.whl | ||
RUN pip install pyodbc | ||
RUN pip list | ||
|
||
COPY log.py . | ||
COPY init-mssql-db.sh . | ||
COPY init-mssql-db.sql . | ||
|
||
RUN chmod +x init-mssql-db.sh | ||
Comment on lines
-22
to
-27
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. We no longer need these line since we mount |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,8 @@ services: | |
- postgres | ||
build: | ||
context: . | ||
volumes: | ||
- .:/tmp/mlflow | ||
environment: | ||
MLFLOW_TRACKING_URI: postgresql://mlflowuser:mlflowpassword@postgres:5432/mlflowdb | ||
|
||
|
@@ -30,6 +32,8 @@ services: | |
- mysql | ||
build: | ||
context: . | ||
volumes: | ||
- .:/tmp/mlflow | ||
Comment on lines
+35
to
+36
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. Use volumes for faster development cycle instead of copying scripts in the docker image. |
||
environment: | ||
MLFLOW_TRACKING_URI: mysql://mlflowuser:mlflowpassword@mysql:3306/mlflowdb | ||
|
||
|
@@ -46,5 +50,17 @@ services: | |
build: | ||
context: . | ||
dockerfile: Dockerfile.mssql | ||
volumes: | ||
- .:/tmp/mlflow | ||
environment: | ||
MLFLOW_TRACKING_URI: mssql+pyodbc://mlflowuser:Mlfl*wpassword1@mssql/mlflowdb?driver=ODBC+Driver+17+for+SQL+Server | ||
|
||
mlflow-sqlite: | ||
depends_on: | ||
- postgres | ||
build: | ||
context: . | ||
volumes: | ||
- .:/tmp/mlflow | ||
environment: | ||
MLFLOW_TRACKING_URI: sqlite:////tmp/mlflow/mlflowdb |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import os | ||
import argparse | ||
|
||
import sqlalchemy | ||
from sqlalchemy.schema import MetaData, CreateTable | ||
|
||
import mlflow | ||
from mlflow.tracking._tracking_service.utils import _TRACKING_URI_ENV_VAR | ||
|
||
|
||
class MockModel(mlflow.pyfunc.PythonModel): | ||
def load_context(self, context): | ||
pass | ||
|
||
def predict(self, context, model_input): | ||
pass | ||
|
||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--schema-output", required=True, help="Output path of DB schema") | ||
return parser.parse_args() | ||
|
||
|
||
def run_logging_operations(): | ||
with mlflow.start_run() as run: | ||
print("Tracking URI:", mlflow.get_tracking_uri()) | ||
mlflow.log_param("p", "param") | ||
mlflow.log_metric("m", 1.0) | ||
mlflow.set_tag("t", "tag") | ||
mlflow.pyfunc.log_model( | ||
artifact_path="model", | ||
python_model=MockModel(), | ||
registered_model_name="mock", | ||
) | ||
print(mlflow.get_run(run.info.run_id)) | ||
|
||
|
||
def get_db_schema(): | ||
engine = sqlalchemy.create_engine(mlflow.get_tracking_uri()) | ||
created_tables_metadata = MetaData(bind=engine) | ||
created_tables_metadata.reflect() | ||
# Write out table schema as described in | ||
# https://docs.sqlalchemy.org/en/13/faq/metadata_schema.html#how-can-i-get-the-create-table-drop-table-output-as-a-string | ||
lines = [] | ||
for ti in created_tables_metadata.sorted_tables: | ||
lines += list(map(str.rstrip, str(CreateTable(ti)).splitlines())) | ||
return "\n".join(lines) | ||
|
||
|
||
def main(): | ||
assert _TRACKING_URI_ENV_VAR in os.environ | ||
|
||
args = parse_args() | ||
run_logging_operations() | ||
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. is this line for triggering table creation ? 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. Yep! 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. + for making sure we can run logging operations successfully. |
||
schema = get_db_schema() | ||
title = "Schema" | ||
print("=" * 10, title, "=" * 10) | ||
print(schema) | ||
print("=" * (20 + 2 + len(title))) | ||
os.makedirs(os.path.dirname(args.schema_output), exist_ok=True) | ||
with open(args.schema_output, "w") as f: | ||
f.write(schema) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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.
Dump the table schema to make it easier to debug locally.