-
Notifications
You must be signed in to change notification settings - Fork 27
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
🎨 expose service_run_id
as an env var for both comp and new style dynamic services
#6942
Open
GitHK
wants to merge
24
commits into
ITISFoundation:master
Choose a base branch
from
GitHK:pr-osparc-allow-user-services-to-request-dy-sidecar-run-id
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
24ff119
run_id can now be requested as an env var on request by a service
df34a54
Merge branch 'master' into pr-osparc-allow-user-services-to-request-d…
GitHK 47c4eb8
Merge remote-tracking branch 'upstream/master' into pr-osparc-allow-u…
daccfdc
added context for run_id in comp tasks
8d9b796
Merge branch 'pr-osparc-allow-user-services-to-request-dy-sidecar-run…
d6b89a9
added fixture and refactor tests
4204990
fixed broken tests
ff3298c
moved fixture where it is used
2d1b08e
refactor with proper values
13d56de
refactor
dfdacbb
fixed test
486fb33
refactor to use new RunID
978f407
refactor types
0cb9f1f
fixed type
af0bed3
repalced
a72b6b5
fixed imports
98de753
Merge remote-tracking branch 'upstream/master' into pr-osparc-allow-u…
b0d715c
Merge remote-tracking branch 'upstream/master' into pr-osparc-allow-u…
5b67d46
renamed run_id to service_run_id and RunID to ServiceRunID
e9be2ee
rename
40ac24e
refactor
fe7ee55
fixed naming
2ded5fe
Merge remote-tracking branch 'upstream/master' into pr-osparc-allow-u…
e726e78
fixed failing test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 | ||||
---|---|---|---|---|---|---|
@@ -1,18 +1,28 @@ | ||||||
from typing import Annotated, Any, TypeAlias | ||||||
from typing import TYPE_CHECKING, Annotated, Any, Self, TypeAlias | ||||||
from uuid import uuid4 | ||||||
|
||||||
import arrow | ||||||
from pydantic import GetCoreSchemaHandler, StringConstraints, ValidationInfo | ||||||
from pydantic import ( | ||||||
GetCoreSchemaHandler, | ||||||
PositiveInt, | ||||||
StringConstraints, | ||||||
ValidationInfo, | ||||||
) | ||||||
from pydantic_core import CoreSchema, core_schema | ||||||
|
||||||
from .basic_regex import PROPERTY_KEY_RE, SIMPLE_VERSION_RE | ||||||
from .projects_nodes_io import NodeID | ||||||
from .services_regex import ( | ||||||
COMPUTATIONAL_SERVICE_KEY_RE, | ||||||
DYNAMIC_SERVICE_KEY_RE, | ||||||
FILENAME_RE, | ||||||
SERVICE_ENCODED_KEY_RE, | ||||||
SERVICE_KEY_RE, | ||||||
) | ||||||
from .users import UserID | ||||||
|
||||||
if TYPE_CHECKING: | ||||||
from .projects import ProjectID | ||||||
|
||||||
ServicePortKey: TypeAlias = Annotated[str, StringConstraints(pattern=PROPERTY_KEY_RE)] | ||||||
|
||||||
|
@@ -35,7 +45,7 @@ | |||||
ServiceVersion: TypeAlias = Annotated[str, StringConstraints(pattern=SIMPLE_VERSION_RE)] | ||||||
|
||||||
|
||||||
class RunID(str): | ||||||
class ServiceRunID(str): | ||||||
""" | ||||||
Used to assign a unique identifier to the run of a service. | ||||||
|
||||||
|
@@ -44,12 +54,15 @@ class RunID(str): | |||||
and old volumes for different runs. | ||||||
Avoids overwriting data that left dropped on the node (due to an error) | ||||||
and gives the osparc-agent an opportunity to back it up. | ||||||
The resource-usage-tracker tracker uses these RunIDs to keep track of | ||||||
resource usage from comp and dynamic services. | ||||||
""" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
__slots__ = () | ||||||
|
||||||
@classmethod | ||||||
def create(cls) -> "RunID": | ||||||
def get_resource_tracking_run_id_for_dynamic(cls) -> Self: | ||||||
"""used for dynamic services""" | ||||||
# NOTE: there was a legacy version of this RunID | ||||||
# legacy version: | ||||||
# '0ac3ed64-665b-42d2-95f7-e59e0db34242' | ||||||
|
@@ -59,6 +72,17 @@ def create(cls) -> "RunID": | |||||
run_id_format = f"{utc_int_timestamp}_{uuid4()}" | ||||||
return cls(run_id_format) | ||||||
|
||||||
@classmethod | ||||||
def get_resource_tracking_run_id_for_computational( | ||||||
cls, | ||||||
user_id: UserID, | ||||||
project_id: "ProjectID", | ||||||
node_id: NodeID, | ||||||
iteration: PositiveInt, | ||||||
) -> Self: | ||||||
"""used by computational services""" | ||||||
return cls(f"comp_{user_id}_{project_id}_{node_id}_{iteration}") | ||||||
|
||||||
@classmethod | ||||||
def __get_pydantic_core_schema__( | ||||||
cls, | ||||||
|
@@ -68,7 +92,7 @@ def __get_pydantic_core_schema__( | |||||
return core_schema.no_info_after_validator_function(cls, handler(str)) | ||||||
|
||||||
@classmethod | ||||||
def validate(cls, v: "RunID | str", _: ValidationInfo) -> "RunID": | ||||||
def validate(cls, v: "ServiceRunID | str", _: ValidationInfo) -> "ServiceRunID": | ||||||
if isinstance(v, cls): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Q: should this not raise a ValueError instead of TypeError? |
||||||
return v | ||||||
if isinstance(v, str): | ||||||
|
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,40 @@ | ||
import pytest | ||
from models_library.projects import ProjectID | ||
from models_library.projects_nodes import NodeID | ||
from models_library.services_types import ServiceRunID | ||
from models_library.users import UserID | ||
from pydantic import PositiveInt | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"user_id, project_id, node_id, iteration, expected_result", | ||
[ | ||
( | ||
2, | ||
ProjectID("e08356e4-eb74-49e9-b769-2c26e34c61d9"), | ||
NodeID("a08356e4-eb74-49e9-b769-2c26e34c61d1"), | ||
5, | ||
"comp_2_e08356e4-eb74-49e9-b769-2c26e34c61d9_a08356e4-eb74-49e9-b769-2c26e34c61d1_5", | ||
) | ||
], | ||
) | ||
def test_run_id_get_resource_tracking_run_id( | ||
user_id: UserID, | ||
project_id: ProjectID, | ||
node_id: NodeID, | ||
iteration: PositiveInt, | ||
expected_result: str, | ||
): | ||
resource_tracking_service_run_id = ( | ||
ServiceRunID.get_resource_tracking_run_id_for_computational( | ||
user_id, project_id, node_id, iteration | ||
) | ||
) | ||
assert isinstance(resource_tracking_service_run_id, ServiceRunID) | ||
assert resource_tracking_service_run_id == expected_result | ||
|
||
|
||
def test_get_resource_tracking_run_id_for_dynamic(): | ||
assert isinstance( | ||
ServiceRunID.get_resource_tracking_run_id_for_dynamic(), ServiceRunID | ||
) |
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why this this necessary? Is it because of cyclic dependencies?
TIP: For things like
ProjectID
we can always move these tocommon_library
. I already did that with user_enums and groups_enums (check how it is imported in the Groups and Users models)