Skip to content

Commit fa78e52

Browse files
authored
Merge pull request #428 from simvue-io/hotfix/pre-send-checks
Check metrics before sending them
2 parents 19cec9f + 7871518 commit fa78e52

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

simvue/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
from typing import Annotated, Dict, List, Optional, Union
2-
32
from pydantic import BaseModel, Field, StringConstraints, PositiveInt
43

54
FOLDER_REGEX: str = r"^/.*"
65
NAME_REGEX: str = r"^[a-zA-Z0-9\-\_\s\/\.:]+$"
6+
METRIC_KEY_REGEX: str = r"^[a-zA-Z0-9\-\_\s\/\.:=><]+$"
77

88
MetadataKeyString = Annotated[str, StringConstraints(pattern=r"^[\w\-\s\.]+$")]
99
TagString = Annotated[str, StringConstraints(pattern=r"^[\w\-\s\.]+$")]
10+
MetricKeyString = Annotated[str, StringConstraints(pattern=METRIC_KEY_REGEX)]
1011

1112

1213
# Pydantic class to validate run.init()

simvue/run.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from .executor import Executor
3939
from .factory.proxy import Simvue
4040
from .metrics import get_gpu_metrics, get_process_cpu, get_process_memory
41-
from .models import RunInput, FOLDER_REGEX, NAME_REGEX
41+
from .models import RunInput, FOLDER_REGEX, NAME_REGEX, MetricKeyString
4242
from .serialization import serialize_object
4343
from .system import get_system
4444
from .metadata import git_info
@@ -1114,7 +1114,7 @@ def _add_metrics_to_dispatch(
11141114
@pydantic.validate_call
11151115
def log_metrics(
11161116
self,
1117-
metrics: dict[str, typing.Union[int, float]],
1117+
metrics: dict[MetricKeyString, typing.Union[int, float]],
11181118
step: typing.Optional[int] = None,
11191119
time: typing.Optional[float] = None,
11201120
timestamp: typing.Optional[str] = None,

simvue/utilities.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
logger = logging.getLogger(__name__)
2020

21+
if typing.TYPE_CHECKING:
22+
from simvue.run import Run
23+
2124

2225
def parse_validation_response(
2326
response: dict[str, list[dict[str, str]]],
@@ -147,7 +150,7 @@ def skip_if_failed(
147150

148151
def decorator(class_func: typing.Callable) -> typing.Callable:
149152
@functools.wraps(class_func)
150-
def wrapper(self, *args, **kwargs) -> typing.Any:
153+
def wrapper(self: "Run", *args, **kwargs) -> typing.Any:
151154
if getattr(self, failure_attr, None) and getattr(
152155
self, ignore_exc_attr, None
153156
):
@@ -166,7 +169,7 @@ def wrapper(self, *args, **kwargs) -> typing.Any:
166169
setattr(self, failure_attr, True)
167170
logger.error(error_str)
168171
return on_failure_return
169-
raise RuntimeError(error_str)
172+
self._error(error_str)
170173

171174
setattr(wrapper, "__fail_safe", True)
172175
return wrapper

0 commit comments

Comments
 (0)