Skip to content

feat(cockpit): add retention setup in datasource #738

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

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions scaleway-async/scaleway_async/cockpit/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .types import TokenScope
from .types import UsageUnit
from .types import ContactPointEmail
from .types import GetConfigResponseRetention
from .types import ContactPoint
from .types import DataSource
from .types import GrafanaProductDashboard
Expand All @@ -21,6 +22,7 @@
from .types import Token
from .types import Usage
from .types import AlertManager
from .types import GetConfigResponse
from .types import GlobalApiCreateGrafanaUserRequest
from .types import GlobalApiDeleteGrafanaUserRequest
from .types import GlobalApiGetCurrentPlanRequest
Expand Down Expand Up @@ -51,6 +53,7 @@
from .types import RegionalApiEnableAlertManagerRequest
from .types import RegionalApiEnableManagedAlertsRequest
from .types import RegionalApiGetAlertManagerRequest
from .types import RegionalApiGetConfigRequest
from .types import RegionalApiGetDataSourceRequest
from .types import RegionalApiGetTokenRequest
from .types import RegionalApiGetUsageOverviewRequest
Expand All @@ -77,6 +80,7 @@
"TokenScope",
"UsageUnit",
"ContactPointEmail",
"GetConfigResponseRetention",
"ContactPoint",
"DataSource",
"GrafanaProductDashboard",
Expand All @@ -86,6 +90,7 @@
"Token",
"Usage",
"AlertManager",
"GetConfigResponse",
"GlobalApiCreateGrafanaUserRequest",
"GlobalApiDeleteGrafanaUserRequest",
"GlobalApiGetCurrentPlanRequest",
Expand Down Expand Up @@ -116,6 +121,7 @@
"RegionalApiEnableAlertManagerRequest",
"RegionalApiEnableManagedAlertsRequest",
"RegionalApiGetAlertManagerRequest",
"RegionalApiGetConfigRequest",
"RegionalApiGetDataSourceRequest",
"RegionalApiGetTokenRequest",
"RegionalApiGetUsageOverviewRequest",
Expand Down
44 changes: 44 additions & 0 deletions scaleway-async/scaleway_async/cockpit/v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
ContactPoint,
ContactPointEmail,
DataSource,
GetConfigResponse,
GlobalApiCreateGrafanaUserRequest,
GlobalApiResetGrafanaUserPasswordRequest,
GlobalApiSelectPlanRequest,
Expand Down Expand Up @@ -63,6 +64,7 @@
unmarshal_Plan,
unmarshal_Token,
unmarshal_AlertManager,
unmarshal_GetConfigResponse,
unmarshal_Grafana,
unmarshal_ListContactPointsResponse,
unmarshal_ListDataSourcesResponse,
Expand Down Expand Up @@ -451,10 +453,12 @@ async def list_plans(
"""
List plan types.
Retrieve a list of available pricing plan types.
Deprecated, retention is now managed at the data source level.
:param page: Page number.
:param page_size: Page size.
:param order_by:
:return: :class:`ListPlansResponse <ListPlansResponse>`
:deprecated

Usage:
::
Expand Down Expand Up @@ -485,10 +489,12 @@ async def list_plans_all(
"""
List plan types.
Retrieve a list of available pricing plan types.
Deprecated, retention is now managed at the data source level.
:param page: Page number.
:param page_size: Page size.
:param order_by:
:return: :class:`List[Plan] <List[Plan]>`
:deprecated

Usage:
::
Expand Down Expand Up @@ -516,9 +522,11 @@ async def select_plan(
"""
Apply a pricing plan.
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.
Deprecated, retention is now managed at the data source level.
:param project_id: ID of the Project.
:param plan_name: Name of the pricing plan.
:return: :class:`Plan <Plan>`
:deprecated

Usage:
::
Expand Down Expand Up @@ -549,8 +557,10 @@ async def get_current_plan(
"""
Get current plan.
Retrieve a pricing plan for the given Project, specified by the ID of the Project.
Deprecated, retention is now managed at the data source level.
:param project_id: ID of the Project.
:return: :class:`Plan <Plan>`
:deprecated

Usage:
::
Expand All @@ -575,13 +585,42 @@ class CockpitV1RegionalAPI(API):
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.
"""

async def get_config(
self,
*,
region: Optional[Region] = None,
) -> GetConfigResponse:
"""
Get the Cockpit configuration.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`GetConfigResponse <GetConfigResponse>`

Usage:
::

result = await api.get_config()
"""

param_region = validate_path_param(
"region", region or self.client.default_region
)

res = self._request(
"GET",
f"/cockpit/v1/regions/{param_region}/config",
)

self._throw_on_error(res)
return unmarshal_GetConfigResponse(res.json())

async def create_data_source(
self,
*,
name: str,
region: Optional[Region] = None,
project_id: Optional[str] = None,
type_: Optional[DataSourceType] = None,
retention_days: Optional[int] = None,
) -> DataSource:
"""
Create a data source.
Expand All @@ -594,6 +633,7 @@ async def create_data_source(
:param region: Region to target. If none is passed will use default region from the config.
:param project_id: ID of the Project the data source belongs to.
:param type_: Data source type.
:param retention_days: Default values are 30 days for metrics, 7 days for logs and traces.
:return: :class:`DataSource <DataSource>`

Usage:
Expand All @@ -617,6 +657,7 @@ async def create_data_source(
region=region,
project_id=project_id,
type_=type_,
retention_days=retention_days,
),
self.client,
),
Expand Down Expand Up @@ -792,13 +833,15 @@ async def update_data_source(
data_source_id: str,
region: Optional[Region] = None,
name: Optional[str] = None,
retention_days: Optional[int] = None,
) -> DataSource:
"""
Update a data source.
Update a given data source name, specified by the data source ID.
:param data_source_id: ID of the data source to update.
:param region: Region to target. If none is passed will use default region from the config.
:param name: Updated name of the data source.
:param retention_days: BETA - Duration for which the data will be retained in the data source.
:return: :class:`DataSource <DataSource>`

Usage:
Expand All @@ -822,6 +865,7 @@ async def update_data_source(
data_source_id=data_source_id,
region=region,
name=name,
retention_days=retention_days,
),
self.client,
),
Expand Down
64 changes: 64 additions & 0 deletions scaleway-async/scaleway_async/cockpit/v1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
Plan,
Token,
AlertManager,
GetConfigResponseRetention,
GetConfigResponse,
Grafana,
ListContactPointsResponse,
ListDataSourcesResponse,
Expand Down Expand Up @@ -119,6 +121,10 @@ def unmarshal_DataSource(data: Any) -> DataSource:
if field is not None:
args["synchronized_with_grafana"] = field

field = data.get("retention_days", None)
if field is not None:
args["retention_days"] = field

field = data.get("region", None)
if field is not None:
args["region"] = field
Expand Down Expand Up @@ -325,6 +331,58 @@ def unmarshal_AlertManager(data: Any) -> AlertManager:
return AlertManager(**args)


def unmarshal_GetConfigResponseRetention(data: Any) -> GetConfigResponseRetention:
if not isinstance(data, dict):
raise TypeError(
"Unmarshalling the type 'GetConfigResponseRetention' failed as data isn't a dictionary."
)

args: Dict[str, Any] = {}

field = data.get("min_days", None)
if field is not None:
args["min_days"] = field

field = data.get("max_days", None)
if field is not None:
args["max_days"] = field

field = data.get("default_days", None)
if field is not None:
args["default_days"] = field

return GetConfigResponseRetention(**args)


def unmarshal_GetConfigResponse(data: Any) -> GetConfigResponse:
if not isinstance(data, dict):
raise TypeError(
"Unmarshalling the type 'GetConfigResponse' failed as data isn't a dictionary."
)

args: Dict[str, Any] = {}

field = data.get("metrics_retention", None)
if field is not None:
args["metrics_retention"] = unmarshal_GetConfigResponseRetention(field)
else:
args["metrics_retention"] = None

field = data.get("logs_retention", None)
if field is not None:
args["logs_retention"] = unmarshal_GetConfigResponseRetention(field)
else:
args["logs_retention"] = None

field = data.get("traces_retention", None)
if field is not None:
args["traces_retention"] = unmarshal_GetConfigResponseRetention(field)
else:
args["traces_retention"] = None

return GetConfigResponse(**args)


def unmarshal_Grafana(data: Any) -> Grafana:
if not isinstance(data, dict):
raise TypeError(
Expand Down Expand Up @@ -721,6 +779,9 @@ def marshal_RegionalApiCreateDataSourceRequest(
if request.type_ is not None:
output["type"] = str(request.type_)

if request.retention_days is not None:
output["retention_days"] = request.retention_days

return output


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

if request.retention_days is not None:
output["retention_days"] = request.retention_days

return output
Loading