-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨Saving volume stats inside the shared store volume (#4267)
Co-authored-by: Andrei Neagu <[email protected]>
- Loading branch information
Showing
34 changed files
with
561 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
packages/models-library/src/models_library/sidecar_volumes.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from datetime import datetime | ||
from enum import auto | ||
|
||
import arrow | ||
from pydantic import BaseModel, Field | ||
|
||
from .utils.enums import StrAutoEnum | ||
|
||
|
||
class VolumeCategory(StrAutoEnum): | ||
""" | ||
These uniquely identify volumes which are mounted by | ||
the dynamic-sidecar and user services. | ||
This is primarily used to keep track of the status of | ||
each individual volume on the volumes. | ||
The status is ingested by the agent and processed | ||
when the volume is removed. | ||
""" | ||
|
||
# contains data relative to output ports | ||
OUTPUTS = auto() | ||
|
||
# contains data relative to input ports | ||
INPUTS = auto() | ||
|
||
# contains files which represent the state of the service | ||
# usually the user's workspace | ||
STATES = auto() | ||
|
||
# contains dynamic-sidecar data required to maintain state | ||
# between restarts | ||
SHARED_STORE = auto() | ||
|
||
|
||
class VolumeStatus(StrAutoEnum): | ||
""" | ||
Used by the agent to figure out what to do with the data | ||
present on the volume. | ||
""" | ||
|
||
CONTENT_NEEDS_TO_BE_SAVED = auto() | ||
CONTENT_WAS_SAVED = auto() | ||
CONTENT_NO_SAVE_REQUIRED = auto() | ||
|
||
|
||
class VolumeState(BaseModel): | ||
status: VolumeStatus | ||
last_changed: datetime = Field(default_factory=lambda: arrow.utcnow().datetime) | ||
|
||
def __eq__(self, other: object) -> bool: | ||
# only include status for equality last_changed is not important | ||
is_equal: bool = self.status == getattr(other, "status", None) | ||
return is_equal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,3 @@ class Profile(BaseModel): | |
|
||
data = Profile(email=email_input) | ||
assert data.email == "[email protected]" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# pylint: disable=redefined-outer-name | ||
|
||
import pytest | ||
from models_library.sidecar_volumes import VolumeState, VolumeStatus | ||
from pytest import FixtureRequest | ||
|
||
|
||
@pytest.fixture(params=VolumeStatus) | ||
def status(request: FixtureRequest) -> VolumeStatus: | ||
return request.param | ||
|
||
|
||
def test_volume_state_equality_does_not_use_last_changed(status: VolumeStatus): | ||
# NOTE: `last_changed` is initialized with the utc datetime | ||
# at the moment of the creation of the object. | ||
assert VolumeState(status=status) == VolumeState(status=status) | ||
schema_property_count = len(VolumeState.schema()["properties"]) | ||
assert len(VolumeState(status=status).dict()) == schema_property_count |
Oops, something went wrong.