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

AWS focussed CLI implementation for Shareable Viz #1661

Merged
merged 31 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
910709f
initial draft
ravi-kumar-pilla Nov 29, 2023
907125b
add unit tests
ravi-kumar-pilla Nov 30, 2023
4664dc0
adjust exception handlers
ravi-kumar-pilla Dec 1, 2023
f97fad1
Merge branch 'main' into feature/cli-share-viz
ravi-kumar-pilla Dec 4, 2023
95bacc0
test viz group initial draft
ravi-kumar-pilla Dec 5, 2023
94259cc
update viz group help text
ravi-kumar-pilla Dec 5, 2023
8e72d30
add pytest
ravi-kumar-pilla Dec 5, 2023
75b6e94
fix e2e tests
ravi-kumar-pilla Dec 5, 2023
0b8a984
Add new notes for upcoming release
MehdiNV Dec 6, 2023
754c6b7
Merge branch 'main' into chore/viz-group
MehdiNV Dec 6, 2023
aef34b2
merge 1616
ravi-kumar-pilla Dec 6, 2023
946188c
merge viz group and adjust deploy command
ravi-kumar-pilla Dec 6, 2023
901412f
Correct typo in RELEASE file
MehdiNV Dec 7, 2023
b4329d7
Remove redundant bullet point in RELEASE.md
MehdiNV Dec 7, 2023
a670026
Remove redundant command deploy from group
MehdiNV Dec 7, 2023
6356057
Adjust doc refs of 'kedro viz' to 'kedro viz run'
MehdiNV Dec 7, 2023
d754849
Update more doc references to 'kedro viz run'
MehdiNV Dec 7, 2023
1a5cf9e
remove custom command group class
ravi-kumar-pilla Dec 8, 2023
be329af
Merge branch 'chore/viz-group' of https://github.com/kedro-org/kedro-…
ravi-kumar-pilla Dec 9, 2023
6ff2e34
merge main
ravi-kumar-pilla Dec 11, 2023
08fd959
adjust test case
ravi-kumar-pilla Dec 11, 2023
86560b1
add release note
ravi-kumar-pilla Dec 11, 2023
d62cba4
update docs
ravi-kumar-pilla Dec 11, 2023
0b1be13
add timer message
ravi-kumar-pilla Dec 12, 2023
7a85113
add pytest for timer
ravi-kumar-pilla Dec 12, 2023
ae1b4e0
Merge branch 'main' into feature/cli-share-viz
ravi-kumar-pilla Dec 12, 2023
63d8c4a
Merge branch 'main' into feature/cli-share-viz
rashidakanchwala Dec 14, 2023
0a46ee7
Merge branch 'main' into feature/cli-share-viz
rashidakanchwala Dec 15, 2023
dbd7d16
Update docs/source/share_kedro_viz.md
rashidakanchwala Dec 15, 2023
d9a38c0
fix based on reviews
rashidakanchwala Dec 15, 2023
5f92476
typo in docs
rashidakanchwala Dec 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,24 @@ Options:
-h, --help Show this message and exit.
```

To deploy Kedro-Viz from the command line as a Kedro plugin, use the following command from the root folder of your Kedro project:

```bash
kedro viz deploy
```

```bash
Usage: kedro viz deploy [OPTIONS]

Deploy and host Kedro Viz on AWS S3.

Options:
--region TEXT AWS region where your S3 bucket is located [required]
--bucket-name TEXT AWS S3 bucket name where Kedro Viz will be hosted
[required]
-h, --help Show this message and exit.
```

### Experiment Tracking usage

To enable [experiment tracking](https://docs.kedro.org/en/stable/experiment_tracking/index.html) in Kedro-Viz, you need to add the Kedro-Viz `SQLiteStore` to your Kedro project.
Expand Down
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Please follow the established format:
## Major features and improvements

- Display hosted URL in CLI while launching kedro viz. (#1644)
- AWS focussed CLI implementation `kedro viz deploy` for shareable viz. (#1661)

## Bug fixes and other changes

Expand Down
6 changes: 6 additions & 0 deletions docs/source/share_kedro_viz.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ Here's an example of the flow:

![](./images/kedro-publish-share.gif)

From Kedro-Viz version 7.0.0, you can now publish and share your Kedro-Viz project from the command line. Use the following command from the root folder of your Kedro project
rashidakanchwala marked this conversation as resolved.
Show resolved Hide resolved

```bash
kedro viz deploy --region=[aws-bucket-region] --bucket-name=[aws-bucket-name]
```

## Permissions and access control

All permissions and access control are controlled by AWS. It's up to you, the user, if you want to allow anyone to see your project or limit access to certain IP addresses, users, or groups.
Expand Down
2 changes: 1 addition & 1 deletion package/kedro_viz/api/rest/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ def save_api_responses_to_fs(api_dir: str):
protocol, path = get_protocol_and_path(api_dir)
remote_fs = fsspec.filesystem(protocol)

logger.debug(
logger.info(
"""Saving/Uploading api files to %s""",
api_dir,
)
Expand Down
35 changes: 35 additions & 0 deletions package/kedro_viz/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,38 @@

DEFAULT_HOST = "127.0.0.1"
DEFAULT_PORT = 4141

VIZ_DEPLOY_TIME_LIMIT = 60

AWS_REGIONS = [
"us-east-2",
"us-east-1",
"us-west-1",
"us-west-2",
"af-south-1",
"ap-east-1",
"ap-south-2",
"ap-southeast-3",
"ap-southeast-4",
"ap-south-1",
"ap-northeast-3",
"ap-northeast-2",
"ap-southeast-1",
"ap-southeast-2",
"ap-northeast-1",
"ca-central-1",
"cn-north-1",
"cn-northwest-1",
"eu-central-1",
"eu-west-1",
"eu-west-2",
"eu-south-1",
"eu-west-3",
"eu-north-1",
"eu-south-2",
"eu-central-2",
"sa-east-1",
"me-south-1",
"me-central-1",
"il-central-1",
]
6 changes: 3 additions & 3 deletions package/kedro_viz/integrations/deployment/s3_deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def _ingest_heap_analytics(self):
env = Environment(loader=FileSystemLoader(_HTML_DIR))

if should_add_telemetry:
logger.debug("Ingesting heap analytics.")
logger.info("Ingesting heap analytics.")
Copy link
Member

Choose a reason for hiding this comment

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

Should this be a info message?

telemetry_content = env.get_template("telemetry.html").render(
heap_app_id=heap_app_id, heap_user_identity=heap_user_identity
)
Expand All @@ -82,7 +82,7 @@ def _ingest_heap_analytics(self):

def _upload_static_files(self, html_dir: Path):
"""Upload static HTML files to S3."""
logger.debug("Uploading static html files to %s.", self._bucket_path)
logger.info("Uploading static html files to %s.", self._bucket_path)
try:
self._remote_fs.put(f"{str(html_dir)}/*", self._bucket_path, recursive=True)
self._ingest_heap_analytics()
Expand All @@ -91,7 +91,7 @@ def _upload_static_files(self, html_dir: Path):
raise exc

def _upload_deploy_viz_metadata_file(self):
logger.debug(
logger.info(
"Creating and Uploading deploy viz metadata file to %s.",
self._bucket_path,
)
Expand Down
81 changes: 79 additions & 2 deletions package/kedro_viz/launchers/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@
from watchgod import RegExpWatcher, run_process

from kedro_viz import __version__
from kedro_viz.constants import DEFAULT_HOST, DEFAULT_PORT
from kedro_viz.constants import AWS_REGIONS, DEFAULT_HOST, DEFAULT_PORT
from kedro_viz.integrations.deployment.s3_deployer import S3Deployer
from kedro_viz.integrations.pypi import get_latest_version, is_running_outdated_version
from kedro_viz.launchers.utils import _check_viz_up, _start_browser, _wait_for
from kedro_viz.launchers.utils import (
_check_viz_up,
_start_browser,
_wait_for,
viz_deploy_progress_timer,
)
from kedro_viz.server import load_and_populate_data

_VIZ_PROCESSES: Dict[str, int] = {}

Expand Down Expand Up @@ -193,3 +200,73 @@ def run(
except Exception as ex: # pragma: no cover
traceback.print_exc()
raise KedroCliError(str(ex)) from ex


@viz.command(context_settings={"help_option_names": ["-h", "--help"]})
@click.option(
"--region",
type=str,
required=True,
help="AWS region where your S3 bucket is located",
)
@click.option(
"--bucket-name",
type=str,
required=True,
help="AWS S3 bucket name where Kedro Viz will be hosted",
)
def deploy(region, bucket_name):
"""Deploy and host Kedro Viz on AWS S3"""
if region not in AWS_REGIONS:
click.echo(
click.style(
"ERROR: Invalid AWS region. Please enter a valid AWS Region (eg., us-east-2).\n"
"Please find the complete list of available regions at :\n"
"https://docs.aws.amazon.com/AmazonRDS/latest"
"/UserGuide/Concepts.RegionsAndAvailabilityZones.html"
"#Concepts.RegionsAndAvailabilityZones.Regions",
fg="red",
),
)
return

try:
viz_deploy_timer = multiprocessing.Process(target=viz_deploy_progress_timer)
viz_deploy_timer.start()

# Loads and populates data from underlying Kedro Project
load_and_populate_data(Path.cwd(), ignore_plugins=True)
ravi-kumar-pilla marked this conversation as resolved.
Show resolved Hide resolved

# Start the deployment
deployer = S3Deployer(region, bucket_name)
url = deployer.deploy_and_get_url()

click.echo(
click.style(
"\u2728 Success! Kedro Viz has been deployed on AWS S3. It can be accessed at :\n"
f"{url}",
fg="green",
),
)
except PermissionError: # pragma: no cover
click.echo(
click.style(
"PERMISSION ERROR: Deploying and hosting Kedro-Viz requires "
"AWS access keys, a valid AWS region and bucket name.\n"
"Please supply your AWS access keys as environment variables "
"and make sure the AWS region and bucket name are valid.\n"
"More information can be found at : "
"https://docs.kedro.org/en/stable/visualisation/share_kedro_viz.html",
fg="red",
)
)
# pylint: disable=broad-exception-caught
except Exception as exc: # pragma: no cover
click.echo(
click.style(
f"ERROR: Failed to deploy and host Kedro-Viz on AWS S3 : {exc} ",
fg="red",
)
)
finally:
viz_deploy_timer.terminate()
14 changes: 14 additions & 0 deletions package/kedro_viz/launchers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import requests

from kedro_viz.constants import VIZ_DEPLOY_TIME_LIMIT

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -90,3 +92,15 @@ def _start_browser(host: str, port: int):

if _is_localhost(host):
webbrowser.open_new(f"http://{host}:{port}/")


def viz_deploy_progress_timer():
"""Shows progress timer and message for kedro viz deploy"""
seconds = 0
try:
while seconds <= VIZ_DEPLOY_TIME_LIMIT:
print(f"...Creating your webpage ({seconds}s)", end="\r", flush=True)
sleep(1)
seconds += 1
except KeyboardInterrupt: # pragma: no cover
print("\nCreating your webpage interrupted. Exiting...")
40 changes: 26 additions & 14 deletions package/kedro_viz/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,30 @@ def populate_data(
data_access_manager.add_pipelines(pipelines)


def load_and_populate_data(
path: Path,
env: Optional[str] = None,
ignore_plugins: bool = False,
extra_params: Optional[Dict[str, Any]] = None,
pipeline_name: Optional[str] = None,
):
"""Loads underlying Kedro project data and populates Kedro Viz Repositories"""

# Loads data from underlying Kedro Project
catalog, pipelines, session_store, stats_dict = kedro_data_loader.load_data(
path, env, ignore_plugins, extra_params
)

pipelines = (
pipelines
if pipeline_name is None
else {pipeline_name: pipelines[pipeline_name]}
)

# Creates data repositories which are used by Kedro Viz Backend APIs
populate_data(data_access_manager, catalog, pipelines, session_store, stats_dict)


def run_server(
host: str = DEFAULT_HOST,
port: int = DEFAULT_PORT,
Expand All @@ -58,7 +82,7 @@ def run_server(
autoreload: bool = False,
ignore_plugins: bool = False,
extra_params: Optional[Dict[str, Any]] = None,
): # pylint: disable=redefined-outer-name, too-many-locals
): # pylint: disable=redefined-outer-name
"""Run a uvicorn server with a FastAPI app that either launches API response data from a file
or from reading data from a real Kedro project.

Expand All @@ -83,19 +107,7 @@ def run_server(
path = Path(project_path) if project_path else Path.cwd()

if load_file is None:
# Loads data from underlying Kedro Project
catalog, pipelines, session_store, stats_dict = kedro_data_loader.load_data(
path, env, ignore_plugins, extra_params
)
pipelines = (
pipelines
if pipeline_name is None
else {pipeline_name: pipelines[pipeline_name]}
)
# Creates data repositories which are used by Kedro Viz Backend APIs
populate_data(
data_access_manager, catalog, pipelines, session_store, stats_dict
)
load_and_populate_data(path, env, ignore_plugins, extra_params, pipeline_name)

if save_file:
save_api_responses_to_fs(save_file)
Expand Down
Loading