chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
# UI Preview
|
||||
|
||||
Deploy a live preview of the MLflow UI as a [Databricks App](https://docs.databricks.com/aws/en/dev-tools/databricks-apps/) when a PR modifies the frontend (`mlflow/server/js/`).
|
||||
|
||||
## How it works
|
||||
|
||||
1. Add the `ui-preview` label to a PR with UI changes
|
||||
2. The [UI Preview workflow](../workflows/ui-preview.yml) builds the frontend and deploys it to a Databricks App
|
||||
3. A comment with the preview URL is posted on the PR
|
||||
4. The app is automatically deleted when the PR is closed
|
||||
|
||||
## Access
|
||||
|
||||
Preview apps are only accessible to core maintainers with workspace access.
|
||||
|
||||
## API access
|
||||
|
||||
To query or add data to a preview app, set the following environment variables:
|
||||
|
||||
```bash
|
||||
export DATABRICKS_HOST="https://..."
|
||||
export DATABRICKS_CLIENT_ID="..."
|
||||
export DATABRICKS_CLIENT_SECRET="..."
|
||||
export APP_URL="..."
|
||||
```
|
||||
|
||||
Then, obtain an access token:
|
||||
|
||||
```bash
|
||||
export TOKEN=$(curl -s -X POST "$DATABRICKS_HOST/oidc/v1/token" \
|
||||
-d "grant_type=client_credentials&client_id=$DATABRICKS_CLIENT_ID&client_secret=$DATABRICKS_CLIENT_SECRET&scope=all-apis" \
|
||||
| jq -r '.access_token')
|
||||
```
|
||||
|
||||
Once the token is obtained, run the following command to verify it works:
|
||||
|
||||
```bash
|
||||
curl -s "$APP_URL/api/2.0/mlflow/experiments/search" \
|
||||
-X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
|
||||
-d '{"max_results": 10}' | jq .
|
||||
```
|
||||
|
||||
You can also use the MLflow Python client:
|
||||
|
||||
```bash
|
||||
export MLFLOW_TRACKING_URI="$APP_URL"
|
||||
export MLFLOW_TRACKING_TOKEN="$TOKEN"
|
||||
```
|
||||
|
||||
```python
|
||||
import mlflow
|
||||
|
||||
mlflow.search_experiments(max_results=10)
|
||||
```
|
||||
|
||||
See [Connect to Databricks Apps](https://docs.databricks.com/aws/en/dev-tools/databricks-apps/connect-local) for more details on authentication.
|
||||
@@ -0,0 +1,57 @@
|
||||
import logging
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import mlflow.server
|
||||
from mlflow.demo import generate_all_demos
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def setup():
|
||||
# Extract UI build assets into the mlflow package's expected location
|
||||
tar_path = Path(__file__).parent.resolve() / "build.tar.gz"
|
||||
target_dir = Path(mlflow.server.__file__).parent / "js"
|
||||
target_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
_logger.info("Extracting UI assets to %s", target_dir)
|
||||
subprocess.check_call(["tar", "xzf", tar_path, "-C", target_dir])
|
||||
|
||||
# Generate demo data. Always refresh so the preview app reflects the latest
|
||||
# demo content (e.g. new trace types) even if the SQLite database persisted
|
||||
# from a previous deploy with stale demo data.
|
||||
os.environ["MLFLOW_TRACKING_URI"] = "sqlite:///mlflow.db"
|
||||
_logger.info("Generating demo data...")
|
||||
generate_all_demos(refresh=True)
|
||||
_logger.info("Demo data generated.")
|
||||
|
||||
|
||||
def main():
|
||||
setup()
|
||||
|
||||
cmd = [
|
||||
sys.executable,
|
||||
"-m",
|
||||
"mlflow",
|
||||
"server",
|
||||
"--backend-store-uri",
|
||||
"sqlite:///mlflow.db",
|
||||
"--default-artifact-root",
|
||||
"./mlartifacts",
|
||||
"--serve-artifacts",
|
||||
"--host",
|
||||
"0.0.0.0",
|
||||
"--port",
|
||||
"8000",
|
||||
"--workers",
|
||||
"1",
|
||||
]
|
||||
_logger.info("Starting MLflow server: %s", " ".join(cmd))
|
||||
os.execvp(cmd[0], cmd)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,10 @@
|
||||
command:
|
||||
- "python"
|
||||
- "app.py"
|
||||
env:
|
||||
- name: MLFLOW_SERVER_CORS_ALLOWED_ORIGINS
|
||||
value: "__APP_URL__"
|
||||
- name: MLFLOW_SERVER_ALLOWED_HOSTS
|
||||
value: "*"
|
||||
- name: MLFLOW_CRYPTO_KEK_PASSPHRASE
|
||||
value: "__KEK_PASSPHRASE__"
|
||||
Reference in New Issue
Block a user