Skip to content

Commit 32421ae

Browse files
authored
feat(cockpit): add getRulesCount endpoint (#1048)
1 parent c0bf6fe commit 32421ae

File tree

8 files changed

+280
-0
lines changed

8 files changed

+280
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from .types import PreconfiguredAlertData
1515
from .types import ContactPointEmail
1616
from .types import GetConfigResponseRetention
17+
from .types import RulesCount
1718
from .types import Alert
1819
from .types import ContactPoint
1920
from .types import DataSource
@@ -26,6 +27,7 @@
2627
from .types import DisableAlertRulesResponse
2728
from .types import EnableAlertRulesResponse
2829
from .types import GetConfigResponse
30+
from .types import GetRulesCountResponse
2931
from .types import GlobalApiCreateGrafanaUserRequest
3032
from .types import GlobalApiDeleteGrafanaUserRequest
3133
from .types import GlobalApiGetCurrentPlanRequest
@@ -60,6 +62,7 @@
6062
from .types import RegionalApiGetAlertManagerRequest
6163
from .types import RegionalApiGetConfigRequest
6264
from .types import RegionalApiGetDataSourceRequest
65+
from .types import RegionalApiGetRulesCountRequest
6366
from .types import RegionalApiGetTokenRequest
6467
from .types import RegionalApiGetUsageOverviewRequest
6568
from .types import RegionalApiListAlertsRequest
@@ -88,6 +91,7 @@
8891
"PreconfiguredAlertData",
8992
"ContactPointEmail",
9093
"GetConfigResponseRetention",
94+
"RulesCount",
9195
"Alert",
9296
"ContactPoint",
9397
"DataSource",
@@ -100,6 +104,7 @@
100104
"DisableAlertRulesResponse",
101105
"EnableAlertRulesResponse",
102106
"GetConfigResponse",
107+
"GetRulesCountResponse",
103108
"GlobalApiCreateGrafanaUserRequest",
104109
"GlobalApiDeleteGrafanaUserRequest",
105110
"GlobalApiGetCurrentPlanRequest",
@@ -134,6 +139,7 @@
134139
"RegionalApiGetAlertManagerRequest",
135140
"RegionalApiGetConfigRequest",
136141
"RegionalApiGetDataSourceRequest",
142+
"RegionalApiGetRulesCountRequest",
137143
"RegionalApiGetTokenRequest",
138144
"RegionalApiGetUsageOverviewRequest",
139145
"RegionalApiListAlertsRequest",

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
DisableAlertRulesResponse,
3030
EnableAlertRulesResponse,
3131
GetConfigResponse,
32+
GetRulesCountResponse,
3233
GlobalApiCreateGrafanaUserRequest,
3334
GlobalApiResetGrafanaUserPasswordRequest,
3435
GlobalApiSelectPlanRequest,
@@ -71,6 +72,7 @@
7172
unmarshal_DisableAlertRulesResponse,
7273
unmarshal_EnableAlertRulesResponse,
7374
unmarshal_GetConfigResponse,
75+
unmarshal_GetRulesCountResponse,
7476
unmarshal_Grafana,
7577
unmarshal_ListAlertsResponse,
7678
unmarshal_ListContactPointsResponse,
@@ -1228,6 +1230,39 @@ async def disable_alert_manager(
12281230
self._throw_on_error(res)
12291231
return unmarshal_AlertManager(res.json())
12301232

1233+
async def get_rules_count(
1234+
self,
1235+
*,
1236+
region: Optional[ScwRegion] = None,
1237+
project_id: Optional[str] = None,
1238+
) -> GetRulesCountResponse:
1239+
"""
1240+
Get a detailed count of enabled rules in the specified Project. Includes preconfigured and custom alerting and recording rules.
1241+
:param region: Region to target. If none is passed will use default region from the config.
1242+
:param project_id: ID of the Project to retrieve the rule count for.
1243+
:return: :class:`GetRulesCountResponse <GetRulesCountResponse>`
1244+
1245+
Usage:
1246+
::
1247+
1248+
result = await api.get_rules_count()
1249+
"""
1250+
1251+
param_region = validate_path_param(
1252+
"region", region or self.client.default_region
1253+
)
1254+
1255+
res = self._request(
1256+
"GET",
1257+
f"/cockpit/v1/regions/{param_region}/rules/count",
1258+
params={
1259+
"project_id": project_id or self.client.default_project_id,
1260+
},
1261+
)
1262+
1263+
self._throw_on_error(res)
1264+
return unmarshal_GetRulesCountResponse(res.json())
1265+
12311266
async def create_contact_point(
12321267
self,
12331268
*,

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
EnableAlertRulesResponse,
2424
GetConfigResponseRetention,
2525
GetConfigResponse,
26+
RulesCount,
27+
GetRulesCountResponse,
2628
Grafana,
2729
PreconfiguredAlertData,
2830
Alert,
@@ -435,6 +437,54 @@ def unmarshal_GetConfigResponse(data: Any) -> GetConfigResponse:
435437
return GetConfigResponse(**args)
436438

437439

440+
def unmarshal_RulesCount(data: Any) -> RulesCount:
441+
if not isinstance(data, dict):
442+
raise TypeError(
443+
"Unmarshalling the type 'RulesCount' failed as data isn't a dictionary."
444+
)
445+
446+
args: Dict[str, Any] = {}
447+
448+
field = data.get("data_source_id", None)
449+
if field is not None:
450+
args["data_source_id"] = field
451+
452+
field = data.get("data_source_name", None)
453+
if field is not None:
454+
args["data_source_name"] = field
455+
456+
field = data.get("rules_count", None)
457+
if field is not None:
458+
args["rules_count"] = field
459+
460+
return RulesCount(**args)
461+
462+
463+
def unmarshal_GetRulesCountResponse(data: Any) -> GetRulesCountResponse:
464+
if not isinstance(data, dict):
465+
raise TypeError(
466+
"Unmarshalling the type 'GetRulesCountResponse' failed as data isn't a dictionary."
467+
)
468+
469+
args: Dict[str, Any] = {}
470+
471+
field = data.get("rules_count_by_datasource", None)
472+
if field is not None:
473+
args["rules_count_by_datasource"] = (
474+
[unmarshal_RulesCount(v) for v in field] if field is not None else None
475+
)
476+
477+
field = data.get("preconfigured_rules_count", None)
478+
if field is not None:
479+
args["preconfigured_rules_count"] = field
480+
481+
field = data.get("custom_rules_count", None)
482+
if field is not None:
483+
args["custom_rules_count"] = field
484+
485+
return GetRulesCountResponse(**args)
486+
487+
438488
def unmarshal_Grafana(data: Any) -> Grafana:
439489
if not isinstance(data, dict):
440490
raise TypeError(

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,24 @@ class GetConfigResponseRetention:
173173
default_days: int
174174

175175

176+
@dataclass
177+
class RulesCount:
178+
data_source_id: str
179+
"""
180+
ID of the data source.
181+
"""
182+
183+
data_source_name: str
184+
"""
185+
Name of the data source.
186+
"""
187+
188+
rules_count: int
189+
"""
190+
Total count of rules associated with this data source.
191+
"""
192+
193+
176194
@dataclass
177195
class Alert:
178196
"""
@@ -594,6 +612,24 @@ class GetConfigResponse:
594612
"""
595613

596614

615+
@dataclass
616+
class GetRulesCountResponse:
617+
rules_count_by_datasource: List[RulesCount]
618+
"""
619+
Total count of rules grouped by data source.
620+
"""
621+
622+
preconfigured_rules_count: int
623+
"""
624+
Total count of preconfigured rules.
625+
"""
626+
627+
custom_rules_count: int
628+
"""
629+
Total count of custom rules.
630+
"""
631+
632+
597633
@dataclass
598634
class GlobalApiCreateGrafanaUserRequest:
599635
"""
@@ -1220,6 +1256,19 @@ class RegionalApiGetDataSourceRequest:
12201256
"""
12211257

12221258

1259+
@dataclass
1260+
class RegionalApiGetRulesCountRequest:
1261+
region: Optional[ScwRegion]
1262+
"""
1263+
Region to target. If none is passed will use default region from the config.
1264+
"""
1265+
1266+
project_id: Optional[str]
1267+
"""
1268+
ID of the Project to retrieve the rule count for.
1269+
"""
1270+
1271+
12231272
@dataclass
12241273
class RegionalApiGetTokenRequest:
12251274
"""

scaleway/scaleway/cockpit/v1/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from .types import PreconfiguredAlertData
1515
from .types import ContactPointEmail
1616
from .types import GetConfigResponseRetention
17+
from .types import RulesCount
1718
from .types import Alert
1819
from .types import ContactPoint
1920
from .types import DataSource
@@ -26,6 +27,7 @@
2627
from .types import DisableAlertRulesResponse
2728
from .types import EnableAlertRulesResponse
2829
from .types import GetConfigResponse
30+
from .types import GetRulesCountResponse
2931
from .types import GlobalApiCreateGrafanaUserRequest
3032
from .types import GlobalApiDeleteGrafanaUserRequest
3133
from .types import GlobalApiGetCurrentPlanRequest
@@ -60,6 +62,7 @@
6062
from .types import RegionalApiGetAlertManagerRequest
6163
from .types import RegionalApiGetConfigRequest
6264
from .types import RegionalApiGetDataSourceRequest
65+
from .types import RegionalApiGetRulesCountRequest
6366
from .types import RegionalApiGetTokenRequest
6467
from .types import RegionalApiGetUsageOverviewRequest
6568
from .types import RegionalApiListAlertsRequest
@@ -88,6 +91,7 @@
8891
"PreconfiguredAlertData",
8992
"ContactPointEmail",
9093
"GetConfigResponseRetention",
94+
"RulesCount",
9195
"Alert",
9296
"ContactPoint",
9397
"DataSource",
@@ -100,6 +104,7 @@
100104
"DisableAlertRulesResponse",
101105
"EnableAlertRulesResponse",
102106
"GetConfigResponse",
107+
"GetRulesCountResponse",
103108
"GlobalApiCreateGrafanaUserRequest",
104109
"GlobalApiDeleteGrafanaUserRequest",
105110
"GlobalApiGetCurrentPlanRequest",
@@ -134,6 +139,7 @@
134139
"RegionalApiGetAlertManagerRequest",
135140
"RegionalApiGetConfigRequest",
136141
"RegionalApiGetDataSourceRequest",
142+
"RegionalApiGetRulesCountRequest",
137143
"RegionalApiGetTokenRequest",
138144
"RegionalApiGetUsageOverviewRequest",
139145
"RegionalApiListAlertsRequest",

scaleway/scaleway/cockpit/v1/api.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
DisableAlertRulesResponse,
3030
EnableAlertRulesResponse,
3131
GetConfigResponse,
32+
GetRulesCountResponse,
3233
GlobalApiCreateGrafanaUserRequest,
3334
GlobalApiResetGrafanaUserPasswordRequest,
3435
GlobalApiSelectPlanRequest,
@@ -71,6 +72,7 @@
7172
unmarshal_DisableAlertRulesResponse,
7273
unmarshal_EnableAlertRulesResponse,
7374
unmarshal_GetConfigResponse,
75+
unmarshal_GetRulesCountResponse,
7476
unmarshal_Grafana,
7577
unmarshal_ListAlertsResponse,
7678
unmarshal_ListContactPointsResponse,
@@ -1228,6 +1230,39 @@ def disable_alert_manager(
12281230
self._throw_on_error(res)
12291231
return unmarshal_AlertManager(res.json())
12301232

1233+
def get_rules_count(
1234+
self,
1235+
*,
1236+
region: Optional[ScwRegion] = None,
1237+
project_id: Optional[str] = None,
1238+
) -> GetRulesCountResponse:
1239+
"""
1240+
Get a detailed count of enabled rules in the specified Project. Includes preconfigured and custom alerting and recording rules.
1241+
:param region: Region to target. If none is passed will use default region from the config.
1242+
:param project_id: ID of the Project to retrieve the rule count for.
1243+
:return: :class:`GetRulesCountResponse <GetRulesCountResponse>`
1244+
1245+
Usage:
1246+
::
1247+
1248+
result = api.get_rules_count()
1249+
"""
1250+
1251+
param_region = validate_path_param(
1252+
"region", region or self.client.default_region
1253+
)
1254+
1255+
res = self._request(
1256+
"GET",
1257+
f"/cockpit/v1/regions/{param_region}/rules/count",
1258+
params={
1259+
"project_id": project_id or self.client.default_project_id,
1260+
},
1261+
)
1262+
1263+
self._throw_on_error(res)
1264+
return unmarshal_GetRulesCountResponse(res.json())
1265+
12311266
def create_contact_point(
12321267
self,
12331268
*,

0 commit comments

Comments
 (0)