Skip to content
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

🎨 Is922/adding filtering fields to usage endpoint #5277

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
db23f5e
listen to wallet events in payment system
matusdrobuliak66 Nov 10, 2023
5fe1d79
Merge branch 'master' into is922/auto-recharge-emit-msg
matusdrobuliak66 Nov 10, 2023
bd38e85
fix test
matusdrobuliak66 Nov 10, 2023
d5ae4c4
Merge branch 'is922/auto-recharge-emit-msg' of github.com:matusdrobul…
matusdrobuliak66 Nov 10, 2023
caefaf1
fix tests
matusdrobuliak66 Nov 10, 2023
caf251d
Merge branch 'master' into is922/auto-recharge-emit-msg
matusdrobuliak66 Nov 10, 2023
ee3d0ff
Merge branch 'master' into is922/auto-recharge-emit-msg
matusdrobuliak66 Nov 12, 2023
1967ea4
review @sanderegg
matusdrobuliak66 Nov 12, 2023
ff86c8c
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Nov 13, 2023
99d879c
a
matusdrobuliak66 Nov 14, 2023
98238ef
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Nov 15, 2023
6348a64
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Nov 16, 2023
f91448a
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Nov 16, 2023
4511242
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Nov 17, 2023
7002724
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Nov 20, 2023
2e8a8c5
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Nov 22, 2023
861844a
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Nov 23, 2023
a856d44
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Nov 28, 2023
09e7c3e
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Nov 30, 2023
589f4e6
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Dec 1, 2023
64abe63
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Dec 4, 2023
b762a6b
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Dec 4, 2023
c900653
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Dec 5, 2023
73938a8
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Dec 5, 2023
f5351cf
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Dec 5, 2023
295b3e4
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Dec 5, 2023
49d5a4e
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Dec 6, 2023
0fe74c3
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Dec 7, 2023
776c18c
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Dec 8, 2023
39c0720
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Dec 11, 2023
ce5965b
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Dec 12, 2023
9cdb81a
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Dec 12, 2023
6261cf9
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Dec 13, 2023
149a31d
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Dec 14, 2023
cf33f09
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Dec 19, 2023
e034076
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Dec 21, 2023
702e008
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Dec 21, 2023
a413ee4
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Dec 22, 2023
ee24f3c
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Dec 22, 2023
be6c0e3
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Jan 8, 2024
a8d17cf
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Jan 9, 2024
9752187
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Jan 11, 2024
aa7feb0
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Jan 14, 2024
0fd4c0c
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Jan 18, 2024
98a0f4c
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Jan 19, 2024
8116448
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Jan 23, 2024
33f0a1e
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Jan 25, 2024
8634e9e
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Jan 26, 2024
fdd4792
adding additional order by fields for resource-usages endpoints
matusdrobuliak66 Jan 27, 2024
37f4746
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Jan 28, 2024
d469940
Merge branch 'master' into is922/adding-filtering-fields
matusdrobuliak66 Jan 29, 2024
0e9f6b0
review @prespov
matusdrobuliak66 Jan 29, 2024
085baf7
review @sanderegg
matusdrobuliak66 Jan 29, 2024
1add5ef
Merge branch 'master' into is922/adding-filtering-fields
matusdrobuliak66 Jan 29, 2024
b79a252
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Jan 29, 2024
425c350
Merge branch 'master' of github.com:ITISFoundation/osparc-simcore
matusdrobuliak66 Jan 29, 2024
c65bc04
Merge branch 'master' into is922/adding-filtering-fields
matusdrobuliak66 Jan 29, 2024
4dec9a8
fix
matusdrobuliak66 Jan 29, 2024
c23ddfc
fix
matusdrobuliak66 Jan 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions api/specs/web-server/_resource_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
_GetPricingPlanUnitPathParams,
)
from simcore_service_webserver.resource_usage._service_runs_handlers import (
ORDER_BY_DESCRIPTION,
_ListServicesResourceUsagesQueryParams,
_ListServicesResourceUsagesQueryParamsWithPagination,
)
Expand All @@ -47,12 +48,12 @@
)
async def list_resource_usage_services(
order_by: Annotated[
Json | None,
Json,
Query(
description="Order by field (started_at|stopped_at|credit_cost) and direction (asc|desc). The default sorting order is ascending.",
description="Order by field (wallet_id|wallet_name|user_id|project_id|project_name|node_id|node_name|service_key|service_version|service_type|started_at|stopped_at|service_run_status|credit_cost|transaction_status) and direction (asc|desc). The default sorting order is ascending.",
example='{"field": "started_at", "direction": "desc"}',
),
] = None,
] = '{"field": "started_at", "direction": "desc"}',
filters: Annotated[
Json | None,
Query(
Expand Down Expand Up @@ -85,16 +86,16 @@ async def list_resource_usage_services(
)
async def export_resource_usage_services(
order_by: Annotated[
Json | None,
Json,
Query(
description="Order by field (started_at|stopped_at|credit_cost) and direction (asc|desc). The default sorting order is ascending.",
description="",
example='{"field": "started_at", "direction": "desc"}',
),
] = None,
] = '{"field": "started_at", "direction": "desc"}',
filters: Annotated[
Json | None,
Query(
description="Filters to process on the resource usages list, encoded as JSON. Currently supports the filtering of 'started_at' field with 'from' and 'until' parameters in <yyyy-mm-dd> ISO 8601 format. The date range specified is inclusive.",
description=ORDER_BY_DESCRIPTION,
example='{"started_at": {"from": "yyyy-mm-dd", "until": "yyyy-mm-dd"}}',
),
] = None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3095,15 +3095,14 @@ paths:
are taken from context, optionally wallet_id parameter might be provided).
operationId: list_resource_usage_services
parameters:
- description: Order by field (started_at|stopped_at|credit_cost) and direction
(asc|desc). The default sorting order is ascending.
- description: Order by field (wallet_id|wallet_name|user_id|project_id|project_name|node_id|node_name|service_key|service_version|service_type|started_at|stopped_at|service_run_status|credit_cost|transaction_status)
and direction (asc|desc). The default sorting order is ascending.
required: false
schema:
title: Order By
type: string
description: Order by field (started_at|stopped_at|credit_cost) and direction
(asc|desc). The default sorting order is ascending.
format: json-string
description: Order by field (wallet_id|wallet_name|user_id|project_id|project_name|node_id|node_name|service_key|service_version|service_type|started_at|stopped_at|service_run_status|credit_cost|transaction_status)
and direction (asc|desc). The default sorting order is ascending.
default: '{"field": "started_at", "direction": "desc"}'
example: '{"field": "started_at", "direction": "desc"}'
name: order_by
in: query
Expand Down Expand Up @@ -3162,30 +3161,21 @@ paths:
wallet_id parameter might be provided).
operationId: export_resource_usage_services
parameters:
- description: Order by field (started_at|stopped_at|credit_cost) and direction
(asc|desc). The default sorting order is ascending.
required: false
- required: false
schema:
title: Order By
type: string
description: Order by field (started_at|stopped_at|credit_cost) and direction
(asc|desc). The default sorting order is ascending.
format: json-string
default: '{"field": "started_at", "direction": "desc"}'
example: '{"field": "started_at", "direction": "desc"}'
name: order_by
in: query
- description: Filters to process on the resource usages list, encoded as JSON.
Currently supports the filtering of 'started_at' field with 'from' and 'until'
parameters in <yyyy-mm-dd> ISO 8601 format. The date range specified is
inclusive.
- description: Order by field (wallet_id|wallet_name|user_id|project_id|project_name|node_id|node_name|service_key|service_version|service_type|started_at|stopped_at|service_run_status|credit_cost|transaction_status)
and direction (asc|desc). The default sorting order is ascending.
required: false
schema:
title: Filters
type: string
description: Filters to process on the resource usages list, encoded as
JSON. Currently supports the filtering of 'started_at' field with 'from'
and 'until' parameters in <yyyy-mm-dd> ISO 8601 format. The date range
specified is inclusive.
description: Order by field (wallet_id|wallet_name|user_id|project_id|project_name|node_id|node_name|service_key|service_version|service_type|started_at|stopped_at|service_run_status|credit_cost|transaction_status)
and direction (asc|desc). The default sorting order is ascending.
format: json-string
example: '{"started_at": {"from": "yyyy-mm-dd", "until": "yyyy-mm-dd"}}'
name: filters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async def list_usage_services(
wallet_id: WalletID | None,
offset: int,
limit: NonNegativeInt,
order_by: OrderBy | None,
order_by: OrderBy,
filters: ServiceResourceUsagesFilters | None,
) -> ServiceRunPage:
access_all_wallet_usage = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
ServiceRunPage,
)
from models_library.resource_tracker import ServiceResourceUsagesFilters
from models_library.rest_ordering import OrderBy
from models_library.rest_ordering import OrderBy, OrderDirection
from models_library.rest_pagination import (
DEFAULT_NUMBER_OF_ITEMS_PER_PAGE,
MAXIMUM_NUMBER_OF_ITEMS_PER_PAGE,
Expand Down Expand Up @@ -59,11 +59,14 @@ class _RequestContext(BaseModel):
product_name: str = Field(..., alias=RQ_PRODUCT_KEY) # type: ignore[pydantic-alias]


ORDER_BY_DESCRIPTION = "Order by field (wallet_id|wallet_name|user_id|project_id|project_name|node_id|node_name|service_key|service_version|service_type|started_at|stopped_at|service_run_status|credit_cost|transaction_status) and direction (asc|desc). The default sorting order is ascending."


class _ListServicesResourceUsagesQueryParams(BaseModel):
wallet_id: WalletID | None = Field(default=None)
order_by: Json[OrderBy | None] = Field( # pylint: disable=unsubscriptable-object
default=None,
description="Order by field (started_at|stopped_at|credit_cost) and direction (asc|desc). The default sorting order is ascending.",
order_by: Json[OrderBy] = Field( # pylint: disable=unsubscriptable-object
default=OrderBy(field="started_at", direction=OrderDirection.DESC),
description=ORDER_BY_DESCRIPTION,
example='{"field": "started_at", "direction": "desc"}',
)
filters: Json[ # pylint: disable=unsubscriptable-object
Expand All @@ -77,8 +80,26 @@ class _ListServicesResourceUsagesQueryParams(BaseModel):
@validator("order_by", allow_reuse=True)
@classmethod
def validate_order_by_field(cls, v):
if v.field not in {"started_at", "stopped_at", "credit_cost"}:
if v.field not in {
"wallet_id",
"wallet_name",
"user_id",
"project_id",
"project_name",
"node_id",
"node_name",
"service_key",
"service_version",
"service_type",
"started_at",
"stopped_at",
"service_run_status",
"credit_cost",
"transaction_status",
}:
raise ValueError(f"We do not support ordering by provided field {v.field}")
if v.field == "credit_cost":
v.field = "osparc_credits"
return v

class Config:
Expand Down Expand Up @@ -126,7 +147,7 @@ async def list_resource_usage_services(request: web.Request):
wallet_id=query_params.wallet_id,
offset=query_params.offset,
limit=query_params.limit,
order_by=parse_obj_as(OrderBy | None, query_params.order_by),
order_by=parse_obj_as(OrderBy, query_params.order_by),
filters=parse_obj_as(ServiceResourceUsagesFilters | None, query_params.filters),
)

Expand Down
Loading