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

feat: add options to output registered entity summary #3028

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

paullongtan
Copy link

@paullongtan paullongtan commented Jan 2, 2025

Tracking issue

Closes flyteorg/flyte#3919

Why are the changes needed?

Currently, pyflyte register does not have an option to output registered entities to a file. This PR creates such functionality.

What changes were proposed in this pull request?

  1. Added two options --summary-format and --summary-dir to pyflyte register in flytekit/flytekit/clis/sdk_in_container/register.py.
  • --summary-format: Sets output format for registration summary. Lists registered workflows, tasks, and launch plans. 'json' and 'yaml' supported.
  • --summary-dir: Directory to save registration summary. Uses current working directory if not specified.
  1. Collects registered entity information in flytekit/flytekit/tools/repo.py. Results are then saved to designated directory in selected file format.
  2. Updated the unit test for register.py.

How was this patch tested?

  • Unit testing
  • Built and run some Flytekit test

Setup process

Screenshots

image image image image

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

Docs link

Summary by Bito

Enhanced pyflyte register command with new summary output capabilities, adding --summary-format (JSON/YAML) and --summary-dir options. Implementation includes registration result collection and flexible output formats. Added comprehensive test suite to validate summary file generation, output data structure, and proper handling of required fields (id, type, version, status) in registration summaries.

Unit tests added: True

Estimated effort to review (1-5, lower is better): 2

Copy link

welcome bot commented Jan 2, 2025

Thank you for opening this pull request! 🙌

These tips will help get your PR across the finish line:

  • Most of the repos have a PR template; if not, fill it out to the best of your knowledge.
  • Sign off your commits (Reference: DCO Guide).

@flyte-bot
Copy link
Contributor

Code Review Agent Run Status

  • Limitations and other issues: ❌ Failure - The AI Code Review Agent skipped reviewing this change because it is configured to exclude certain pull requests based on the source/target branch or the pull request status. You can change the settings here, or contact the agent instance creator at [email protected].

@paullongtan paullongtan force-pushed the feat/add_register_output_format branch from 47d8b92 to dda078c Compare January 2, 2025 00:51
@flyte-bot
Copy link
Contributor

Code Review Agent Run Status

  • Limitations and other issues: ❌ Failure - The AI Code Review Agent skipped reviewing this change because it is configured to exclude certain pull requests based on the source/target branch or the pull request status. You can change the settings here, or contact the agent instance creator at [email protected].

@paullongtan paullongtan force-pushed the feat/add_register_output_format branch from ef2743a to 0395846 Compare January 2, 2025 04:57
Copy link
Contributor

@Mecoli1219 Mecoli1219 left a comment

Choose a reason for hiding this comment

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

Nice first PR! I think you can add more unit tests.

  1. yaml
  2. testing registration without specifying --summary-dir

else:
summary_dir = os.getcwd()

summary_file = f"registration_summary.{summary_format}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean that the other registration may overwrite the summary? I think we could name the file with other unique names (ie. tmp file, py file name, wf name, version number)

Copy link
Author

Choose a reason for hiding this comment

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

Yes! The summary will be overwritten if the registration is rerun.

tests/flytekit/unit/cli/pyflyte/test_register.py Outdated Show resolved Hide resolved

except Exception as e:
if not skip_errors:
raise e
print_registration_status(og_id, success=False)
result["status"] = "failed"
Copy link
Contributor

Choose a reason for hiding this comment

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

If it fails, what will the values of other keys be?

Copy link
Author

Choose a reason for hiding this comment

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

The values of the other keys(id, type, version) are pre-computed before registration. Thus, the values will not be empty even if the registration fails.

The values are from:

result = {
"id": og_id.name,
"type": og_id.resource_type_name(),
"version": og_id.version,
"status": "skipped", # default status
}
where og_id is the id of the entity's template / entity itself.

@flyte-bot
Copy link
Contributor

flyte-bot commented Jan 2, 2025

Code Review Agent Run #9a3edb

Actionable Suggestions - 3
  • flytekit/tools/repo.py - 2
    • Consider enhancing registration result information · Line 341-346
    • Consider using set for format checking · Line 402-404
  • flytekit/clis/sdk_in_container/register.py - 1
    • Consider validating summary format and directory · Line 146-159
Additional Suggestions - 1
  • tests/flytekit/unit/cli/pyflyte/test_register.py - 1
Review Details
  • Files reviewed - 3 · Commit Range: f51be71..9bba92f
    • flytekit/clis/sdk_in_container/register.py
    • flytekit/tools/repo.py
    • tests/flytekit/unit/cli/pyflyte/test_register.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

AI Code Review powered by Bito Logo

@flyte-bot
Copy link
Contributor

flyte-bot commented Jan 2, 2025

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
Feature Improvement - Enhanced Registration Output Capabilities

register.py - Added new CLI options for summary format and directory specification

repo.py - Implemented registration result collection and output formatting functionality

test_register.py - Added comprehensive tests for new summary output features

Comment on lines +341 to +346
result = {
"id": og_id.name,
"type": og_id.resource_type_name(),
"version": og_id.version,
"status": "skipped", # default status
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider enhancing registration result information

Consider adding more detailed status information in the result dictionary. The current status field only captures high-level states ('skipped', 'success', 'failed'). Additional fields like error_message and timestamp could provide more context for debugging and monitoring.

Code suggestion
Check the AI-generated fix before applying
Suggested change
result = {
"id": og_id.name,
"type": og_id.resource_type_name(),
"version": og_id.version,
"status": "skipped", # default status
}
result = {
"id": og_id.name,
"type": og_id.resource_type_name(),
"version": og_id.version,
"status": "skipped", # default status
"timestamp": datetime.datetime.now().isoformat(),
"error_message": "",
"details": {}
}

Code Review Run #9a3edb


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Comment on lines +402 to +404
supported_format = ["json", "yaml"]
if summary_format not in supported_format:
raise ValueError(f"Unsupported file format: {summary_format}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using set for format checking

Consider using a set for supported_format instead of a list since we're only checking membership. This would provide O(1) lookup instead of O(n). Could be defined as supported_format = {'json', 'yaml'}.

Code suggestion
Check the AI-generated fix before applying
Suggested change
supported_format = ["json", "yaml"]
if summary_format not in supported_format:
raise ValueError(f"Unsupported file format: {summary_format}")
if summary_format not in {"json", "yaml"}:
raise ValueError(f"Unsupported file format: {summary_format}")

Code Review Run #9a3edb


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Comment on lines +146 to +159
"--summary-format",
"-f",
required=False,
type=click.Choice(["json", "yaml"], case_sensitive=False),
default=None,
help="Set output format for registration summary. Lists registered workflows, tasks, and launch plans. 'json' and 'yaml' supported.",
)
@click.option(
"--summary-dir",
required=False,
type=click.Path(dir_okay=True, file_okay=False, writable=True, resolve_path=True),
default=None,
help="Directory to save registration summary. Uses current working directory if not specified.",
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider validating summary format and directory

Consider adding validation for summary-format and summary-dir options. When summary-format is specified but summary-dir is not, the summary may not be saved correctly. Consider making summary-dir required when summary-format is provided.

Code suggestion
Check the AI-generated fix before applying
Suggested change
"--summary-format",
"-f",
required=False,
type=click.Choice(["json", "yaml"], case_sensitive=False),
default=None,
help="Set output format for registration summary. Lists registered workflows, tasks, and launch plans. 'json' and 'yaml' supported.",
)
@click.option(
"--summary-dir",
required=False,
type=click.Path(dir_okay=True, file_okay=False, writable=True, resolve_path=True),
default=None,
help="Directory to save registration summary. Uses current working directory if not specified.",
)
"--summary-format",
"-f",
required=False,
type=click.Choice(["json", "yaml"], case_sensitive=False),
default=None,
help="Set output format for registration summary. Lists registered workflows, tasks, and launch plans. 'json' and 'yaml' supported.",
callback=validate_summary_options,
)
"--summary-dir",
required=False,
type=click.Path(dir_okay=True, file_okay=False, writable=True, resolve_path=True),
default=None,
help="Directory to save registration summary. Uses current working directory if not specified.",
callback=validate_summary_options,
)

Code Review Run #9a3edb


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Signed-off-by: paullongtan <[email protected]>
…mmary-dir testings to unit test

Signed-off-by: paullongtan <[email protected]>
@paullongtan paullongtan force-pushed the feat/add_register_output_format branch from 2bbe0d1 to db9f744 Compare January 2, 2025 06:39
@flyte-bot
Copy link
Contributor

flyte-bot commented Jan 2, 2025

Code Review Agent Run #a2cf6a

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: 9bba92f..db9f744
    • tests/flytekit/unit/cli/pyflyte/test_register.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

AI Code Review powered by Bito Logo

@paullongtan
Copy link
Author

Nice first PR! I think you can add more unit tests.

  1. yaml
  2. testing registration without specifying --summary-dir

Thanks!
I have added unit tests for both yaml and registration without specifying --summary-dir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

[FlyteCTL Feature] add a --output flag for pyflyte register
3 participants