Skip to content
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

Add server option for serving only artifacts and proxied serving mode #5045

Merged
merged 22 commits into from Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
69a26b8
Add --serve-artifacts-opt and --artifacts-only options to mlflow server
BenWilson2 Nov 10, 2021
a649b6f
Merge branch 'master' of https://github.com/mlflow/mlflow into suppor…
BenWilson2 Nov 10, 2021
c44e62a
Update examples to show cli arguments in MLflow Artifacts
BenWilson2 Nov 10, 2021
74fa204
Update examples to turn on the REST API endpoints
BenWilson2 Nov 10, 2021
d1b986d
linting
BenWilson2 Nov 10, 2021
7dbd469
PR changes and adjust test for serve-artifact option flag
BenWilson2 Nov 11, 2021
4a0053a
Merge branch 'master' of https://github.com/mlflow/mlflow into suppor…
BenWilson2 Nov 11, 2021
e0a02fb
Merge branch 'master' of https://github.com/mlflow/mlflow into suppor…
BenWilson2 Nov 11, 2021
d6b2f32
PR changes
BenWilson2 Nov 11, 2021
b0987a5
PR updates
BenWilson2 Nov 11, 2021
45b9498
PR feedback changes
BenWilson2 Nov 12, 2021
3f0cbb0
lint
BenWilson2 Nov 12, 2021
05899d9
Add ui server support for proxied artifacts and update exception mess…
BenWilson2 Nov 15, 2021
d83c7a3
Rebase and discard formatting commits
BenWilson2 Nov 25, 2021
6d5641c
typos
BenWilson2 Nov 29, 2021
1370034
Merge branch 'master' of https://github.com/mlflow/mlflow into suppor…
BenWilson2 Nov 29, 2021
8fffe43
fix parsing of uri for trailing slash
BenWilson2 Nov 29, 2021
374e209
Test complexity reduction
BenWilson2 Nov 30, 2021
de2e78c
tracking uri validation checks and test simplification
BenWilson2 Nov 30, 2021
d530c50
Parameterize the uri resolution tests to aid in test debugging
BenWilson2 Nov 30, 2021
5db552b
Cleaner test syntax
BenWilson2 Nov 30, 2021
85d191c
Add and adjust pydoc strings
BenWilson2 Nov 30, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions dev/small-requirements.txt
Expand Up @@ -12,3 +12,4 @@ pytest-localserver==0.5.0
moto!=2.0.7
azure-storage-blob>=12.0.0
azure-identity>=1.6.1
requests
3 changes: 3 additions & 0 deletions examples/mlflow_artifacts/README.md
Expand Up @@ -16,16 +16,19 @@ First, launch the tracking server with the artifacts service via `mlflow server`
```sh
# Launch a tracking server with the artifacts service
$ mlflow server \
--serve-artifacts
BenWilson2 marked this conversation as resolved.
Show resolved Hide resolved
--artifacts-destination ./mlartifacts \
--default-artifact-root http://localhost:5000/api/2.0/mlflow-artifacts/artifacts/experiments \
--gunicorn-opts "--log-level debug"
```

Notes:

- `--serve-artifacts` enables the MLflow Artifacts service endpoints to enable proxied serving of artifacts through the REST API
- `--artifacts-destination` specifies the base artifact location from which to resolve artifact upload/download/list requests. In this examples, we're using a local directory `./mlartifacts`, but it can be changed to a s3 bucket or
- `--default-artifact-root` points to the `experiments` directory of the artifacts service. Therefore, the default artifact location of a newly-created experiment is set to `./mlartifacts/experiments/<experiment_id>`.
- `--gunicorn-opts "--log-level debug"` is specified to print out request logs but can be omitted if unnecessary.
- `--artifacts-only` disables all other endpoints for the tracking server apart from those involved in listing, uploading, and downloading artifacts. This makes the MLflow server a single-purpose proxy for artifact handling only.

Then, run `example.py` that performs upload, download, and list operations for artifacts:

Expand Down
1 change: 1 addition & 0 deletions examples/mlflow_artifacts/docker-compose.yml
Expand Up @@ -54,6 +54,7 @@ services:
--port 5500
--artifacts-destination s3://bucket
--gunicorn-opts "--log-level debug"
--serve-artifacts
harupy marked this conversation as resolved.
Show resolved Hide resolved

postgres:
image: postgres
Expand Down
4 changes: 4 additions & 0 deletions examples/mlflow_artifacts/example.py
Expand Up @@ -10,6 +10,10 @@ def save_text(path, text):
f.write(text)


# NOTE: ensure the tracking server has been started with --serve-artifacts to enable
# MLflow artifact serving functionality.
harupy marked this conversation as resolved.
Show resolved Hide resolved


def main():
assert "MLFLOW_TRACKING_URI" in os.environ

Expand Down
23 changes: 23 additions & 0 deletions mlflow/cli.py
Expand Up @@ -320,6 +320,25 @@ def _validate_static_prefix(ctx, param, value): # pylint: disable=unused-argume
"Default: Within file store, if a file:/ URI is provided. If a sql backend is"
" used, then this option is required.",
)
@click.option(
"--serve-artifacts",
is_flag=True,
help="If specified, enables serving of artifact uploads, downloads, and list requests "
"by routing these requests to the storage location that is specified by "
"'--artifact-destination' directly through a proxy. The default location that "
"these requests are served from is a local './mlartifacts' directory which can be "
"overridden via '--artifact-destination' arguments. "
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"overridden via '--artifact-destination' arguments. "
"overridden via '--artifacts-destination' argument. "

nit

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

"Default: False",
)
@click.option(
"--artifacts-only",
is_flag=True,
help="If specified, configures the mlflow server to be used only for proxied artifact serving. "
"With this mode enabled, functionality of the mlflow tracking service (e.g. run creation, "
"metric logging, and parameter logging are disabled. The server will only expose "
"endpoints for uploading, downloading, and listing artifacts. "
"Default: False",
)
@cli_args.ARTIFACTS_DESTINATION
@cli_args.HOST
@cli_args.PORT
Expand Down Expand Up @@ -348,6 +367,8 @@ def _validate_static_prefix(ctx, param, value): # pylint: disable=unused-argume
def server(
backend_store_uri,
default_artifact_root,
serve_artifacts,
artifacts_only,
artifacts_destination,
host,
port,
Expand Down Expand Up @@ -395,6 +416,8 @@ def server(
_run_server(
backend_store_uri,
default_artifact_root,
serve_artifacts,
artifacts_only,
artifacts_destination,
host,
port,
Expand Down
8 changes: 8 additions & 0 deletions mlflow/server/__init__.py
Expand Up @@ -20,6 +20,8 @@
ARTIFACT_ROOT_ENV_VAR = "_MLFLOW_SERVER_ARTIFACT_ROOT"
ARTIFACTS_DESTINATION_ENV_VAR = "_MLFLOW_SERVER_ARTIFACT_DESTINATION"
PROMETHEUS_EXPORTER_ENV_VAR = "prometheus_multiproc_dir"
SERVE_ARTIFACTS_ENV_VAR = "_MLFLOW_SERVER_SERVE_ARTIFACTS"
ARTIFACTS_ONLY_ENV_VAR = "_MLFLOW_SERVER_ARTIFACTS_ONLY"

REL_STATIC_DIR = "js/build"

Expand Down Expand Up @@ -106,6 +108,8 @@ def _build_gunicorn_command(gunicorn_opts, host, port, workers):
def _run_server(
file_store_path,
default_artifact_root,
serve_artifacts,
artifacts_only,
artifacts_destination,
host,
port,
Expand All @@ -126,6 +130,10 @@ def _run_server(
env_map[BACKEND_STORE_URI_ENV_VAR] = file_store_path
if default_artifact_root:
env_map[ARTIFACT_ROOT_ENV_VAR] = default_artifact_root
if serve_artifacts:
env_map[SERVE_ARTIFACTS_ENV_VAR] = "true"
if artifacts_only:
env_map[ARTIFACTS_ONLY_ENV_VAR] = "true"
if artifacts_destination:
env_map[ARTIFACTS_DESTINATION_ENV_VAR] = artifacts_destination
if static_prefix:
Expand Down