Skip to content

Commit a546c25

Browse files
authored
feat(cockpit): add retention setup in datasource (scaleway#738)
1 parent f33b06a commit a546c25

File tree

8 files changed

+344
-2
lines changed

8 files changed

+344
-2
lines changed

scaleway-async/scaleway_async/cockpit/v1/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from .types import TokenScope
1313
from .types import UsageUnit
1414
from .types import ContactPointEmail
15+
from .types import GetConfigResponseRetention
1516
from .types import ContactPoint
1617
from .types import DataSource
1718
from .types import GrafanaProductDashboard
@@ -21,6 +22,7 @@
2122
from .types import Token
2223
from .types import Usage
2324
from .types import AlertManager
25+
from .types import GetConfigResponse
2426
from .types import GlobalApiCreateGrafanaUserRequest
2527
from .types import GlobalApiDeleteGrafanaUserRequest
2628
from .types import GlobalApiGetCurrentPlanRequest
@@ -51,6 +53,7 @@
5153
from .types import RegionalApiEnableAlertManagerRequest
5254
from .types import RegionalApiEnableManagedAlertsRequest
5355
from .types import RegionalApiGetAlertManagerRequest
56+
from .types import RegionalApiGetConfigRequest
5457
from .types import RegionalApiGetDataSourceRequest
5558
from .types import RegionalApiGetTokenRequest
5659
from .types import RegionalApiGetUsageOverviewRequest
@@ -77,6 +80,7 @@
7780
"TokenScope",
7881
"UsageUnit",
7982
"ContactPointEmail",
83+
"GetConfigResponseRetention",
8084
"ContactPoint",
8185
"DataSource",
8286
"GrafanaProductDashboard",
@@ -86,6 +90,7 @@
8690
"Token",
8791
"Usage",
8892
"AlertManager",
93+
"GetConfigResponse",
8994
"GlobalApiCreateGrafanaUserRequest",
9095
"GlobalApiDeleteGrafanaUserRequest",
9196
"GlobalApiGetCurrentPlanRequest",
@@ -116,6 +121,7 @@
116121
"RegionalApiEnableAlertManagerRequest",
117122
"RegionalApiEnableManagedAlertsRequest",
118123
"RegionalApiGetAlertManagerRequest",
124+
"RegionalApiGetConfigRequest",
119125
"RegionalApiGetDataSourceRequest",
120126
"RegionalApiGetTokenRequest",
121127
"RegionalApiGetUsageOverviewRequest",

scaleway-async/scaleway_async/cockpit/v1/api.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
ContactPoint,
2828
ContactPointEmail,
2929
DataSource,
30+
GetConfigResponse,
3031
GlobalApiCreateGrafanaUserRequest,
3132
GlobalApiResetGrafanaUserPasswordRequest,
3233
GlobalApiSelectPlanRequest,
@@ -63,6 +64,7 @@
6364
unmarshal_Plan,
6465
unmarshal_Token,
6566
unmarshal_AlertManager,
67+
unmarshal_GetConfigResponse,
6668
unmarshal_Grafana,
6769
unmarshal_ListContactPointsResponse,
6870
unmarshal_ListDataSourcesResponse,
@@ -451,10 +453,12 @@ async def list_plans(
451453
"""
452454
List plan types.
453455
Retrieve a list of available pricing plan types.
456+
Deprecated, retention is now managed at the data source level.
454457
:param page: Page number.
455458
:param page_size: Page size.
456459
:param order_by:
457460
:return: :class:`ListPlansResponse <ListPlansResponse>`
461+
:deprecated
458462
459463
Usage:
460464
::
@@ -485,10 +489,12 @@ async def list_plans_all(
485489
"""
486490
List plan types.
487491
Retrieve a list of available pricing plan types.
492+
Deprecated, retention is now managed at the data source level.
488493
:param page: Page number.
489494
:param page_size: Page size.
490495
:param order_by:
491496
:return: :class:`List[Plan] <List[Plan]>`
497+
:deprecated
492498
493499
Usage:
494500
::
@@ -516,9 +522,11 @@ async def select_plan(
516522
"""
517523
Apply a pricing plan.
518524
Apply a pricing plan on a given Project. You must specify the ID of the pricing plan type. Note that you will be billed for the plan you apply.
525+
Deprecated, retention is now managed at the data source level.
519526
:param project_id: ID of the Project.
520527
:param plan_name: Name of the pricing plan.
521528
:return: :class:`Plan <Plan>`
529+
:deprecated
522530
523531
Usage:
524532
::
@@ -549,8 +557,10 @@ async def get_current_plan(
549557
"""
550558
Get current plan.
551559
Retrieve a pricing plan for the given Project, specified by the ID of the Project.
560+
Deprecated, retention is now managed at the data source level.
552561
:param project_id: ID of the Project.
553562
:return: :class:`Plan <Plan>`
563+
:deprecated
554564
555565
Usage:
556566
::
@@ -575,13 +585,42 @@ class CockpitV1RegionalAPI(API):
575585
The Cockpit Regional API allows you to create data sources and tokens to store and query data types such as metrics, logs, and traces. You can also push your data into Cockpit, and send alerts to your contact points when your resources may require your attention, using the regional Alert manager.
576586
"""
577587

588+
async def get_config(
589+
self,
590+
*,
591+
region: Optional[Region] = None,
592+
) -> GetConfigResponse:
593+
"""
594+
Get the Cockpit configuration.
595+
:param region: Region to target. If none is passed will use default region from the config.
596+
:return: :class:`GetConfigResponse <GetConfigResponse>`
597+
598+
Usage:
599+
::
600+
601+
result = await api.get_config()
602+
"""
603+
604+
param_region = validate_path_param(
605+
"region", region or self.client.default_region
606+
)
607+
608+
res = self._request(
609+
"GET",
610+
f"/cockpit/v1/regions/{param_region}/config",
611+
)
612+
613+
self._throw_on_error(res)
614+
return unmarshal_GetConfigResponse(res.json())
615+
578616
async def create_data_source(
579617
self,
580618
*,
581619
name: str,
582620
region: Optional[Region] = None,
583621
project_id: Optional[str] = None,
584622
type_: Optional[DataSourceType] = None,
623+
retention_days: Optional[int] = None,
585624
) -> DataSource:
586625
"""
587626
Create a data source.
@@ -594,6 +633,7 @@ async def create_data_source(
594633
:param region: Region to target. If none is passed will use default region from the config.
595634
:param project_id: ID of the Project the data source belongs to.
596635
:param type_: Data source type.
636+
:param retention_days: Default values are 30 days for metrics, 7 days for logs and traces.
597637
:return: :class:`DataSource <DataSource>`
598638
599639
Usage:
@@ -617,6 +657,7 @@ async def create_data_source(
617657
region=region,
618658
project_id=project_id,
619659
type_=type_,
660+
retention_days=retention_days,
620661
),
621662
self.client,
622663
),
@@ -792,13 +833,15 @@ async def update_data_source(
792833
data_source_id: str,
793834
region: Optional[Region] = None,
794835
name: Optional[str] = None,
836+
retention_days: Optional[int] = None,
795837
) -> DataSource:
796838
"""
797839
Update a data source.
798840
Update a given data source name, specified by the data source ID.
799841
:param data_source_id: ID of the data source to update.
800842
:param region: Region to target. If none is passed will use default region from the config.
801843
:param name: Updated name of the data source.
844+
:param retention_days: BETA - Duration for which the data will be retained in the data source.
802845
:return: :class:`DataSource <DataSource>`
803846
804847
Usage:
@@ -822,6 +865,7 @@ async def update_data_source(
822865
data_source_id=data_source_id,
823866
region=region,
824867
name=name,
868+
retention_days=retention_days,
825869
),
826870
self.client,
827871
),

scaleway-async/scaleway_async/cockpit/v1/marshalling.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
Plan,
2020
Token,
2121
AlertManager,
22+
GetConfigResponseRetention,
23+
GetConfigResponse,
2224
Grafana,
2325
ListContactPointsResponse,
2426
ListDataSourcesResponse,
@@ -119,6 +121,10 @@ def unmarshal_DataSource(data: Any) -> DataSource:
119121
if field is not None:
120122
args["synchronized_with_grafana"] = field
121123

124+
field = data.get("retention_days", None)
125+
if field is not None:
126+
args["retention_days"] = field
127+
122128
field = data.get("region", None)
123129
if field is not None:
124130
args["region"] = field
@@ -325,6 +331,58 @@ def unmarshal_AlertManager(data: Any) -> AlertManager:
325331
return AlertManager(**args)
326332

327333

334+
def unmarshal_GetConfigResponseRetention(data: Any) -> GetConfigResponseRetention:
335+
if not isinstance(data, dict):
336+
raise TypeError(
337+
"Unmarshalling the type 'GetConfigResponseRetention' failed as data isn't a dictionary."
338+
)
339+
340+
args: Dict[str, Any] = {}
341+
342+
field = data.get("min_days", None)
343+
if field is not None:
344+
args["min_days"] = field
345+
346+
field = data.get("max_days", None)
347+
if field is not None:
348+
args["max_days"] = field
349+
350+
field = data.get("default_days", None)
351+
if field is not None:
352+
args["default_days"] = field
353+
354+
return GetConfigResponseRetention(**args)
355+
356+
357+
def unmarshal_GetConfigResponse(data: Any) -> GetConfigResponse:
358+
if not isinstance(data, dict):
359+
raise TypeError(
360+
"Unmarshalling the type 'GetConfigResponse' failed as data isn't a dictionary."
361+
)
362+
363+
args: Dict[str, Any] = {}
364+
365+
field = data.get("metrics_retention", None)
366+
if field is not None:
367+
args["metrics_retention"] = unmarshal_GetConfigResponseRetention(field)
368+
else:
369+
args["metrics_retention"] = None
370+
371+
field = data.get("logs_retention", None)
372+
if field is not None:
373+
args["logs_retention"] = unmarshal_GetConfigResponseRetention(field)
374+
else:
375+
args["logs_retention"] = None
376+
377+
field = data.get("traces_retention", None)
378+
if field is not None:
379+
args["traces_retention"] = unmarshal_GetConfigResponseRetention(field)
380+
else:
381+
args["traces_retention"] = None
382+
383+
return GetConfigResponse(**args)
384+
385+
328386
def unmarshal_Grafana(data: Any) -> Grafana:
329387
if not isinstance(data, dict):
330388
raise TypeError(
@@ -721,6 +779,9 @@ def marshal_RegionalApiCreateDataSourceRequest(
721779
if request.type_ is not None:
722780
output["type"] = str(request.type_)
723781

782+
if request.retention_days is not None:
783+
output["retention_days"] = request.retention_days
784+
724785
return output
725786

726787

@@ -830,4 +891,7 @@ def marshal_RegionalApiUpdateDataSourceRequest(
830891
if request.name is not None:
831892
output["name"] = request.name
832893

894+
if request.retention_days is not None:
895+
output["retention_days"] = request.retention_days
896+
833897
return output

0 commit comments

Comments
 (0)