Skip to content

Commit

Permalink
🐛Dynamic schldr: deferred tasks passing invalid kwargs parameters to …
Browse files Browse the repository at this point in the history
…exceptions (#6573)
  • Loading branch information
sanderegg authored Oct 22, 2024
1 parent 4c5aa41 commit 682d4fa
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .env-devel
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ DYNAMIC_SIDECAR_PROMETHEUS_MONITORING_NETWORKS=[]
DYNAMIC_SIDECAR_PROMETHEUS_SERVICE_LABELS={}
DYNAMIC_SIDECAR_API_SAVE_RESTORE_STATE_TIMEOUT=3600
# DIRECTOR_V2 ----

DYNAMIC_SCHEDULER_LOGLEVEL=DEBUG
DYNAMIC_SCHEDULER_PROFILING=1
DYNAMIC_SCHEDULER_STOP_SERVICE_TIMEOUT=3600

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ async def wrapper(*args, **kwargs):
f"Please check code at: '{func.__module__}.{func.__name__}'"
)
_logger.exception(msg)
raise RejectMessage(reason=msg) from e
raise RejectMessage(msg) from e

return wrapper
8 changes: 5 additions & 3 deletions packages/settings-library/tests/test_utils_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ class Settings(BaseCustomSettings, MixinLoggingSettings):
],
)

APPNAME_DEBUG: bool = Field(False, description="Starts app in debug mode")
APPNAME_DEBUG: bool = Field(
default=False, description="Starts app in debug mode"
)

@validator("LOG_LEVEL")
@validator("LOG_LEVEL", pre=True)
@classmethod
def _v(cls, value) -> str:
def _v(cls, value: str) -> str:
return cls.validate_log_level(value)

# -----------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings):
def LOG_LEVEL(self): # noqa: N802
return self.AUTOSCALING_LOGLEVEL

@validator("AUTOSCALING_LOGLEVEL")
@validator("AUTOSCALING_LOGLEVEL", pre=True)
@classmethod
def _valid_log_level(cls, value: str) -> str:
return cls.validate_log_level(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,9 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings):
"(default to seconds, or see https://pydantic-docs.helpmanual.io/usage/types/#datetime-types for string formating)",
)

CLUSTERS_KEEPER_MAX_MISSED_HEARTBEATS_BEFORE_CLUSTER_TERMINATION: NonNegativeInt = (
Field(
default=5,
description="Max number of missed heartbeats before a cluster is terminated",
)
CLUSTERS_KEEPER_MAX_MISSED_HEARTBEATS_BEFORE_CLUSTER_TERMINATION: NonNegativeInt = Field(
default=5,
description="Max number of missed heartbeats before a cluster is terminated",
)

CLUSTERS_KEEPER_COMPUTATIONAL_BACKEND_DOCKER_IMAGE_TAG: str = Field(
Expand Down Expand Up @@ -352,7 +350,7 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings):
def LOG_LEVEL(self) -> LogLevel: # noqa: N802
return self.CLUSTERS_KEEPER_LOGLEVEL

@validator("CLUSTERS_KEEPER_LOGLEVEL")
@validator("CLUSTERS_KEEPER_LOGLEVEL", pre=True)
@classmethod
def valid_log_level(cls, value: str) -> str:
return cls.validate_log_level(value)
Expand Down
1 change: 1 addition & 0 deletions services/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ services:
REDIS_PASSWORD: ${REDIS_PASSWORD}
DIRECTOR_V2_HOST: ${DIRECTOR_V2_HOST}
DIRECTOR_V2_PORT: ${DIRECTOR_V2_PORT}
DYNAMIC_SCHEDULER_LOGLEVEL: ${DYNAMIC_SCHEDULER_LOGLEVEL}
DYNAMIC_SCHEDULER_STOP_SERVICE_TIMEOUT: ${DYNAMIC_SCHEDULER_STOP_SERVICE_TIMEOUT}
DYNAMIC_SCHEDULER_PROFILING: ${DYNAMIC_SCHEDULER_PROFILING}
TRACING_OPENTELEMETRY_COLLECTOR_ENDPOINT: ${TRACING_OPENTELEMETRY_COLLECTOR_ENDPOINT}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import datetime
from functools import cached_property

from pydantic import Field, parse_obj_as, validator
from settings_library.application import BaseApplicationSettings
Expand All @@ -23,14 +22,14 @@ class _BaseApplicationSettings(BaseApplicationSettings, MixinLoggingSettings):

# RUNTIME -----------------------------------------------------------

DYNAMIC_SCHEDULER__LOGLEVEL: LogLevel = Field(
DYNAMIC_SCHEDULER_LOGLEVEL: LogLevel = Field(
default=LogLevel.INFO,
env=["DYNAMIC_SCHEDULER__LOGLEVEL", "LOG_LEVEL", "LOGLEVEL"],
env=["DYNAMIC_SCHEDULER_LOGLEVEL", "LOG_LEVEL", "LOGLEVEL"],
)
DYNAMIC_SCHEDULER_LOG_FORMAT_LOCAL_DEV_ENABLED: bool = Field(
default=False,
env=[
"DYNAMIC_SCHEDULER__LOG_FORMAT_LOCAL_DEV_ENABLED",
"DYNAMIC_SCHEDULER_LOG_FORMAT_LOCAL_DEV_ENABLED",
"LOG_FORMAT_LOCAL_DEV_ENABLED",
],
description="Enables local development log format. WARNING: make sure it is disabled if you want to have structured logs!",
Expand All @@ -44,13 +43,9 @@ class _BaseApplicationSettings(BaseApplicationSettings, MixinLoggingSettings):
),
)

@cached_property
def LOG_LEVEL(self): # noqa: N802
return self.DYNAMIC_SCHEDULER__LOGLEVEL

@validator("DYNAMIC_SCHEDULER__LOGLEVEL")
@validator("DYNAMIC_SCHEDULER_LOGLEVEL", pre=True)
@classmethod
def valid_log_level(cls, value: str) -> str:
def _validate_log_level(cls, value: str) -> str:
return cls.validate_log_level(value)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@

_the_settings = ApplicationSettings.create_from_envs()

# SEE https://github.com/ITISFoundation/osparc-simcore/issues/3148
logging.basicConfig(level=_the_settings.log_level) # NOSONAR
logging.root.setLevel(_the_settings.log_level)
logging.basicConfig(level=_the_settings.DYNAMIC_SCHEDULER_LOGLEVEL.value)
logging.root.setLevel(_the_settings.DYNAMIC_SCHEDULER_LOGLEVEL.value)
config_all_loggers(
log_format_local_dev_enabled=_the_settings.DYNAMIC_SCHEDULER_LOG_FORMAT_LOCAL_DEV_ENABLED
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings):
def are_prometheus_metrics_enabled(self) -> bool:
return self.DY_SIDECAR_CALLBACKS_MAPPING.metrics is not None

@validator("LOG_LEVEL")
@validator("LOG_LEVEL", pre=True)
@classmethod
def _check_log_level(cls, value):
def _check_log_level(cls, value: str) -> str:
return cls.validate_log_level(value)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings):
def LOG_LEVEL(self) -> LogLevel: # noqa: N802
return self.EFS_GUARDIAN_LOGLEVEL

@validator("EFS_GUARDIAN_LOGLEVEL")
@validator("EFS_GUARDIAN_LOGLEVEL", pre=True)
@classmethod
def valid_log_level(cls, value: str) -> str:
return cls.validate_log_level(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class _BaseApplicationSettings(BaseCustomSettings, MixinLoggingSettings):
def LOG_LEVEL(self):
return self.INVITATIONS_LOGLEVEL

@validator("INVITATIONS_LOGLEVEL")
@validator("INVITATIONS_LOGLEVEL", pre=True)
@classmethod
def valid_log_level(cls, value: str) -> str:
return cls.validate_log_level(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class _BaseApplicationSettings(BaseApplicationSettings, MixinLoggingSettings):
def LOG_LEVEL(self): # noqa: N802
return self.PAYMENTS_LOGLEVEL

@validator("PAYMENTS_LOGLEVEL")
@validator("PAYMENTS_LOGLEVEL", pre=True)
@classmethod
def valid_log_level(cls, value: str) -> str:
return cls.validate_log_level(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class _BaseApplicationSettings(BaseCustomSettings, MixinLoggingSettings):
def LOG_LEVEL(self) -> LogLevel: # noqa: N802
return self.RESOURCE_USAGE_TRACKER_LOGLEVEL

@validator("RESOURCE_USAGE_TRACKER_LOGLEVEL")
@validator("RESOURCE_USAGE_TRACKER_LOGLEVEL", pre=True)
@classmethod
def valid_log_level(cls, value: str) -> str:
return cls.validate_log_level(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ def log_level(self) -> int:
level: int = getattr(logging, self.WEBSERVER_LOGLEVEL.upper())
return level

@validator("WEBSERVER_LOGLEVEL")
@validator("WEBSERVER_LOGLEVEL", pre=True)
@classmethod
def valid_log_level(cls, value):
def valid_log_level(cls, value: str) -> str:
return cls.validate_log_level(value)

@validator("SC_HEALTHCHECK_TIMEOUT", pre=True)
Expand Down

0 comments on commit 682d4fa

Please sign in to comment.