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

Rename ephemeral_storage to disk for simplicity #3095

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

Conversation

JiangJiaWei1103
Copy link
Contributor

@JiangJiaWei1103 JiangJiaWei1103 commented Jan 25, 2025

Tracking issue

Closes flyteorg/flyte#6142.

Why are the changes needed?

The attribute ephemeral_storage of Resources (i.e., K8s pod resources) is too complicated and should be simplified.

What changes were proposed in this pull request?

At this stage, we propose to support both disk and ephemeral_storage for backward compatibility.

The behavior of different configurations is summarized as follows:

  1. Both disk and ephemeral_storage are specified: Raise an error
  2. ephemeral_storage is used: Warn users about the future deprecation
  3. disk is used: Use disk directly and allow ephemeral_storage to mirror disk value

How was this patch tested?

Setup process

Screenshots

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

This PR renames 'ephemeral_storage' to 'disk' in the Resources class while maintaining backward compatibility through deprecation warnings. The implementation allows both attributes to function, with 'ephemeral_storage' mirroring the 'disk' value. The changes include comprehensive test coverage and improved parameter handling for better code clarity.

Unit tests added: True

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

1. Support `ephemeral_storage` as an alias for backward compatibility
    and developer-facing code
2. Encourage users to switch to `disk` when configuring this property

Signed-off-by: JiangJiaWei1103 <[email protected]>
@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].

@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].

JiangJiaWei1103 and others added 3 commits February 9, 2025 15:01
`|` is supported for 3.10+, please see PEP 604.

Signed-off-by: JiangJiaWei1103 <[email protected]>
@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].

@JiangJiaWei1103 JiangJiaWei1103 marked this pull request as ready for review February 9, 2025 08:17
@JiangJiaWei1103 JiangJiaWei1103 changed the title [WIP] Rename ephemeral_storage to disk for simplicity Rename ephemeral_storage to disk for simplicity Feb 9, 2025
@flyte-bot
Copy link
Contributor

flyte-bot commented Feb 9, 2025

Code Review Agent Run #c7015e

Actionable Suggestions - 3
  • flytekit/core/resources.py - 2
    • Consider maintaining backward compatibility for parameters · Line 25-25
    • Consider consistent type annotation for resources · Line 38-38
  • tests/flytekit/unit/core/test_resources.py - 1
    • Consider removing redundant test assertions · Line 181-181
Review Details
  • Files reviewed - 2 · Commit Range: 649b6b8..92ddd0e
    • flytekit/core/resources.py
    • tests/flytekit/unit/core/test_resources.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

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
Feature Improvement - Resource Attribute Renaming and Deprecation

resources.py - Renamed ephemeral_storage to disk while maintaining backward compatibility

test_resources.py - Added test cases for disk and ephemeral_storage attribute handling

# This allocates 1Gi of such local storage.
Resources(ephemeral_storage="1Gi")
Resources(disk="1Gi")
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider maintaining backward compatibility for parameters

Consider maintaining backward compatibility by keeping both disk and ephemeral_storage parameters functional. While renaming to disk improves clarity, some existing code may still use ephemeral_storage. Consider handling both parameters and adding a deprecation warning for ephemeral_storage.

Code suggestion
Check the AI-generated fix before applying
 -    disk: InitVar[Optional[Union[str, int]]] = None
 -    ephemeral_storage: Optional[Union[str, int]] = None
 +    disk: Optional[Union[str, int]] = None
 +    ephemeral_storage: InitVar[Optional[Union[str, int]]] = None
 
      def __post_init__(self, disk):
 +        if disk is not None:
 +            self.disk = disk
 +        if self.ephemeral_storage is not None:
 +            warnings.warn('The ephemeral_storage parameter is deprecated. Please use disk instead.', DeprecationWarning)
 +            if self.disk is None:
 +                self.disk = self.ephemeral_storage

Code Review Run #c7015e


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

  • it was incorrectly flagged

@@ -33,9 +35,10 @@ class Resources(DataClassJSONMixin):
cpu: Optional[Union[str, int, float]] = None
mem: Optional[Union[str, int]] = None
gpu: Optional[Union[str, int]] = None
disk: InitVar[Optional[Union[str, int]]] = None
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider consistent type annotation for resources

Consider using a consistent type annotation pattern for resource fields. While disk is marked as InitVar, other similar resource fields (cpu, mem, gpu, ephemeral_storage) are not. This inconsistency might lead to confusion in how these fields are processed.

Code suggestion
Check the AI-generated fix before applying
 -    cpu: Optional[Union[str, int, float]] = None
 -    mem: Optional[Union[str, int]] = None
 -    gpu: Optional[Union[str, int]] = None
 -    disk: InitVar[Optional[Union[str, int]]] = None
 -    ephemeral_storage: Optional[Union[str, int]] = None
 +    cpu: InitVar[Optional[Union[str, int, float]]] = None
 +    mem: InitVar[Optional[Union[str, int]]] = None
 +    gpu: InitVar[Optional[Union[str, int]]] = None
 +    disk: InitVar[Optional[Union[str, int]]] = None
 +    ephemeral_storage: InitVar[Optional[Union[str, int]]] = None

Code Review Run #c7015e


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

  • it was incorrectly flagged

# Specify only disk
resources = Resources(cpu="1", mem="1Gi", gpu="1", disk="1Gi")
assert resources.disk == "1Gi"
assert resources.ephemeral_storage == "1Gi"
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider removing redundant test assertions

Consider removing redundant assertions since disk and ephemeral_storage are expected to have the same value. A single assertion would be sufficient to verify the behavior.

Code suggestion
Check the AI-generated fix before applying
Suggested change
assert resources.ephemeral_storage == "1Gi"

Code Review Run #c7015e


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

  • it was incorrectly flagged

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

Successfully merging this pull request may close these issues.

[flytekit] Polish - Resources
2 participants