Skip to content

Commit b7f91f0

Browse files
fix code
1 parent bd6a8be commit b7f91f0

File tree

6 files changed

+75
-52
lines changed

6 files changed

+75
-52
lines changed

packages/settings-library/src/settings_library/base.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from common_library.pydantic_fields_extension import get_type, is_literal, is_nullable
66
from pydantic import ValidationInfo, field_validator
77
from pydantic.fields import FieldInfo
8-
from pydantic_core import PydanticUndefined, ValidationError
8+
from pydantic_core import ValidationError
99
from pydantic_settings import BaseSettings, SettingsConfigDict
1010

1111
_logger = logging.getLogger(__name__)
@@ -102,9 +102,6 @@ def __pydantic_init_subclass__(cls, **kwargs: Any):
102102
and issubclass(field_type, BaseCustomSettings)
103103
):
104104
if auto_default_from_env:
105-
assert field.default is PydanticUndefined
106-
assert field.default_factory is None
107-
108105
# Transform it into something like `Field(default_factory=create_settings_from_env(field))`
109106
field.default_factory = _create_settings_from_env(name, field)
110107
field.default = None

services/resource-usage-tracker/openapi.json

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,24 @@
5454
"operationId": "get_credit_transactions_sum_v1_credit_transactions_credits_sum_post",
5555
"parameters": [
5656
{
57+
"name": "product_name",
58+
"in": "query",
5759
"required": true,
5860
"schema": {
5961
"type": "string",
6062
"title": "Product Name"
61-
},
62-
"name": "product_name",
63-
"in": "query"
63+
}
6464
},
6565
{
66+
"name": "wallet_id",
67+
"in": "query",
6668
"required": true,
6769
"schema": {
6870
"type": "integer",
6971
"exclusiveMinimum": true,
7072
"title": "Wallet Id",
7173
"minimum": 0
72-
},
73-
"name": "wallet_id",
74-
"in": "query"
74+
}
7575
}
7676
],
7777
"responses": {
@@ -149,33 +149,33 @@
149149
"operationId": "get_service_default_pricing_plan",
150150
"parameters": [
151151
{
152+
"name": "service_key",
153+
"in": "path",
152154
"required": true,
153155
"schema": {
154156
"type": "string",
155157
"pattern": "^simcore/services/((comp|dynamic|frontend))/([a-z0-9][a-z0-9_.-]*/)*([a-z0-9-_]+[a-z0-9])$",
156158
"title": "Service Key"
157-
},
158-
"name": "service_key",
159-
"in": "path"
159+
}
160160
},
161161
{
162+
"name": "service_version",
163+
"in": "path",
162164
"required": true,
163165
"schema": {
164166
"type": "string",
165167
"pattern": "^(0|[1-9]\\d*)(\\.(0|[1-9]\\d*)){2}(-(0|[1-9]\\d*|\\d*[-a-zA-Z][-\\da-zA-Z]*)(\\.(0|[1-9]\\d*|\\d*[-a-zA-Z][-\\da-zA-Z]*))*)?(\\+[-\\da-zA-Z]+(\\.[-\\da-zA-Z-]+)*)?$",
166168
"title": "Service Version"
167-
},
168-
"name": "service_version",
169-
"in": "path"
169+
}
170170
},
171171
{
172+
"name": "product_name",
173+
"in": "query",
172174
"required": true,
173175
"schema": {
174176
"type": "string",
175177
"title": "Product Name"
176-
},
177-
"name": "product_name",
178-
"in": "query"
178+
}
179179
}
180180
],
181181
"responses": {
@@ -212,35 +212,35 @@
212212
"operationId": "list_service_pricing_plans",
213213
"parameters": [
214214
{
215+
"name": "pricing_plan_id",
216+
"in": "path",
215217
"required": true,
216218
"schema": {
217219
"type": "integer",
218220
"exclusiveMinimum": true,
219221
"title": "Pricing Plan Id",
220222
"minimum": 0
221-
},
222-
"name": "pricing_plan_id",
223-
"in": "path"
223+
}
224224
},
225225
{
226+
"name": "pricing_unit_id",
227+
"in": "path",
226228
"required": true,
227229
"schema": {
228230
"type": "integer",
229231
"exclusiveMinimum": true,
230232
"title": "Pricing Unit Id",
231233
"minimum": 0
232-
},
233-
"name": "pricing_unit_id",
234-
"in": "path"
234+
}
235235
},
236236
{
237+
"name": "product_name",
238+
"in": "query",
237239
"required": true,
238240
"schema": {
239241
"type": "string",
240242
"title": "Product Name"
241-
},
242-
"name": "product_name",
243-
"in": "query"
243+
}
244244
}
245245
],
246246
"responses": {
@@ -297,7 +297,14 @@
297297
"title": "User Email"
298298
},
299299
"osparc_credits": {
300-
"type": "number",
300+
"anyOf": [
301+
{
302+
"type": "number"
303+
},
304+
{
305+
"type": "string"
306+
}
307+
],
301308
"title": "Osparc Credits"
302309
},
303310
"payment_transaction_id": {
@@ -373,8 +380,8 @@
373380
"enum": [
374381
"TIER"
375382
],
376-
"title": "PricingPlanClassification",
377-
"description": "An enumeration."
383+
"const": "TIER",
384+
"title": "PricingPlanClassification"
378385
},
379386
"PricingPlanGet": {
380387
"properties": {
@@ -405,10 +412,17 @@
405412
"title": "Pricing Plan Key"
406413
},
407414
"pricing_units": {
408-
"items": {
409-
"$ref": "#/components/schemas/PricingUnitGet"
410-
},
411-
"type": "array",
415+
"anyOf": [
416+
{
417+
"items": {
418+
"$ref": "#/components/schemas/PricingUnitGet"
419+
},
420+
"type": "array"
421+
},
422+
{
423+
"type": "null"
424+
}
425+
],
412426
"title": "Pricing Units"
413427
},
414428
"is_active": {
@@ -424,6 +438,7 @@
424438
"classification",
425439
"created_at",
426440
"pricing_plan_key",
441+
"pricing_units",
427442
"is_active"
428443
],
429444
"title": "PricingPlanGet"
@@ -444,7 +459,7 @@
444459
"$ref": "#/components/schemas/UnitExtraInfo"
445460
},
446461
"current_cost_per_unit": {
447-
"type": "number",
462+
"type": "string",
448463
"title": "Current Cost Per Unit"
449464
},
450465
"current_cost_per_unit_id": {
@@ -482,13 +497,16 @@
482497
},
483498
"RAM": {
484499
"type": "integer",
500+
"minimum": 0,
485501
"title": "Ram"
486502
},
487503
"VRAM": {
488504
"type": "integer",
505+
"minimum": 0,
489506
"title": "Vram"
490507
}
491508
},
509+
"additionalProperties": true,
492510
"type": "object",
493511
"required": [
494512
"CPU",
@@ -540,7 +558,7 @@
540558
"minimum": 0
541559
},
542560
"available_osparc_credits": {
543-
"type": "number",
561+
"type": "string",
544562
"title": "Available Osparc Credits"
545563
}
546564
},

services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/core/application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232

3333
def create_app(settings: ApplicationSettings) -> FastAPI:
34-
_logger.info("app settings: %s", settings.json(indent=1))
34+
_logger.info("app settings: %s", settings.model_dump_json(indent=1))
3535

3636
app = FastAPI(
3737
debug=settings.RESOURCE_USAGE_TRACKER_DEBUG,

services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/core/settings.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from functools import cached_property
33

44
from models_library.basic_types import BootModeEnum
5-
from pydantic import AliasChoices, field_validator, Field, PositiveInt
5+
from pydantic import AliasChoices, Field, PositiveInt, field_validator
66
from settings_library.base import BaseCustomSettings
77
from settings_library.basic_types import BuildTargetEnum, LogLevel, VersionTag
88
from settings_library.postgres import PostgresSettings
@@ -52,9 +52,8 @@ class _BaseApplicationSettings(BaseCustomSettings, MixinLoggingSettings):
5252
RESOURCE_USAGE_TRACKER_LOGLEVEL: LogLevel = Field(
5353
default=LogLevel.INFO,
5454
validation_alias=AliasChoices(
55-
"RESOURCE_USAGE_TRACKER_LOGLEVEL",
56-
"LOG_LEVEL",
57-
"LOGLEVEL"),
55+
"RESOURCE_USAGE_TRACKER_LOGLEVEL", "LOG_LEVEL", "LOGLEVEL"
56+
),
5857
)
5958
RESOURCE_USAGE_TRACKER_LOG_FORMAT_LOCAL_DEV_ENABLED: bool = Field(
6059
default=False,
@@ -83,18 +82,18 @@ class MinimalApplicationSettings(_BaseApplicationSettings):
8382
"""
8483

8584
RESOURCE_USAGE_TRACKER_PROMETHEUS: PrometheusSettings | None = Field(
86-
json_schema_extra={"auto_default_from_env":True}
85+
json_schema_extra={"auto_default_from_env": True}
8786
)
8887

8988
RESOURCE_USAGE_TRACKER_POSTGRES: PostgresSettings | None = Field(
90-
json_schema_extra={"auto_default_from_env":True},
89+
json_schema_extra={"auto_default_from_env": True},
9190
)
9291

9392
RESOURCE_USAGE_TRACKER_REDIS: RedisSettings = Field(
94-
json_schema_extra={"auto_default_from_env":True},
93+
json_schema_extra={"auto_default_from_env": True},
9594
)
9695
RESOURCE_USAGE_TRACKER_RABBITMQ: RabbitSettings | None = Field(
97-
json_schema_extra={"auto_default_from_env":True},
96+
json_schema_extra={"auto_default_from_env": True},
9897
)
9998

10099

@@ -118,5 +117,14 @@ class ApplicationSettings(MinimalApplicationSettings):
118117
)
119118
RESOURCE_USAGE_TRACKER_PROMETHEUS_INSTRUMENTATION_ENABLED: bool = True
120119
RESOURCE_USAGE_TRACKER_S3: S3Settings | None = Field(
121-
json_schema_extra={"auto_default_from_env":True},
120+
json_schema_extra={"auto_default_from_env": True},
121+
)
122+
123+
@field_validator(
124+
"RESOURCE_USAGE_TRACKER_MISSED_HEARTBEAT_INTERVAL_SEC", mode="before"
122125
)
126+
@classmethod
127+
def _validate_interval(cls, v):
128+
if isinstance(v, str) and v.isnumeric():
129+
return int(v)
130+
return v

services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/resource_tracker_process_messages.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
ServiceRunStatus,
2121
)
2222
from models_library.services import ServiceType
23-
from pydantic import parse_raw_as
23+
from pydantic import TypeAdapter
2424

2525
from .models.resource_tracker_credit_transactions import (
2626
CreditTransactionCreate,
@@ -45,9 +45,9 @@
4545

4646

4747
async def process_message(app: FastAPI, data: bytes) -> bool:
48-
rabbit_message: RabbitResourceTrackingMessages = parse_raw_as(
49-
RabbitResourceTrackingMessages, data # type: ignore[arg-type]
50-
)
48+
rabbit_message: RabbitResourceTrackingMessages = TypeAdapter(
49+
RabbitResourceTrackingMessages
50+
).validate_python(data)
5151
_logger.info(
5252
"Process %s msg service_run_id: %s",
5353
rabbit_message.message_type,

services/resource-usage-tracker/tests/unit/api_rest/test_api_meta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,5 @@ def test_meta(
7070
assert response.status_code == status.HTTP_200_OK
7171
meta = _Meta.model_validate(response.json())
7272

73-
response = client.get(meta.docs_url)
73+
response = client.get(f"{meta.docs_url}")
7474
assert response.status_code == status.HTTP_200_OK

0 commit comments

Comments
 (0)