Skip to content

Commit 034a780

Browse files
scaleway-botLaure-dijremy42remyleone
authored
feat(cockpit): add rule status on ListAlert endpoint (#1061)
Co-authored-by: Laure-di <[email protected]> Co-authored-by: Jonathan R. <[email protected]> Co-authored-by: Rémy Léone <[email protected]>
1 parent fe9552c commit 034a780

File tree

8 files changed

+46
-18
lines changed

8 files changed

+46
-18
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# This file was automatically generated. DO NOT EDIT.
22
# If you have any remark or suggestion do not hesitate to open an issue.
33
from .types import AlertState
4+
from .types import AlertStatus
45
from .types import DataSourceOrigin
56
from .types import DataSourceType
67
from .types import GrafanaUserRole
@@ -78,6 +79,7 @@
7879

7980
__all__ = [
8081
"AlertState",
82+
"AlertStatus",
8183
"DataSourceOrigin",
8284
"DataSourceType",
8385
"GrafanaUserRole",

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
)
1414
from .types import (
1515
AlertState,
16+
AlertStatus,
1617
DataSourceOrigin,
1718
DataSourceType,
1819
GrafanaUserRole,
@@ -1473,7 +1474,7 @@ async def list_alerts(
14731474
*,
14741475
region: Optional[ScwRegion] = None,
14751476
project_id: Optional[str] = None,
1476-
is_enabled: Optional[bool] = None,
1477+
rule_status: Optional[AlertStatus] = None,
14771478
is_preconfigured: Optional[bool] = None,
14781479
state: Optional[AlertState] = None,
14791480
data_source_id: Optional[str] = None,
@@ -1483,7 +1484,7 @@ async def list_alerts(
14831484
List preconfigured and/or custom alerts for the specified Project and data source.
14841485
:param region: Region to target. If none is passed will use default region from the config.
14851486
:param project_id: Project ID to filter for, only alerts from this Project will be returned.
1486-
:param is_enabled: True returns only enabled alerts. False returns only disabled alerts. If omitted, no alert filtering is applied. Other filters may still apply.
1487+
:param rule_status: Returns only alerts with the given activation status. If omitted, no alert filtering is applied. Other filters may still apply.
14871488
:param is_preconfigured: True returns only preconfigured alerts. False returns only custom alerts. If omitted, no filtering is applied on alert types. Other filters may still apply.
14881489
:param state: Valid values to filter on are `inactive`, `pending` and `firing`. If omitted, no filtering is applied on alert states. Other filters may still apply.
14891490
:param data_source_id: If omitted, only alerts from the default Scaleway metrics data source will be listed.
@@ -1504,9 +1505,9 @@ async def list_alerts(
15041505
f"/cockpit/v1/regions/{param_region}/alerts",
15051506
params={
15061507
"data_source_id": data_source_id,
1507-
"is_enabled": is_enabled,
15081508
"is_preconfigured": is_preconfigured,
15091509
"project_id": project_id or self.client.default_project_id,
1510+
"rule_status": rule_status,
15101511
"state": state,
15111512
},
15121513
)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,9 +559,9 @@ def unmarshal_Alert(data: Any) -> Alert:
559559
if field is not None:
560560
args["duration"] = field
561561

562-
field = data.get("enabled", None)
562+
field = data.get("rule_status", None)
563563
if field is not None:
564-
args["enabled"] = field
564+
args["rule_status"] = field
565565

566566
field = data.get("annotations", None)
567567
if field is not None:

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ def __str__(self) -> str:
2525
return str(self.value)
2626

2727

28+
class AlertStatus(str, Enum, metaclass=StrEnumMeta):
29+
UNKNOWN_STATUS = "unknown_status"
30+
ENABLED = "enabled"
31+
DISABLED = "disabled"
32+
ENABLING = "enabling"
33+
DISABLING = "disabling"
34+
35+
def __str__(self) -> str:
36+
return str(self.value)
37+
38+
2839
class DataSourceOrigin(str, Enum, metaclass=StrEnumMeta):
2940
UNKNOWN_ORIGIN = "unknown_origin"
3041
SCALEWAY = "scaleway"
@@ -222,9 +233,9 @@ class Alert:
222233
Duration for which the alert must be active before firing. The format of this duration follows the prometheus duration format.
223234
"""
224235

225-
enabled: bool
236+
rule_status: AlertStatus
226237
"""
227-
Indicates if the alert is enabled or disabled. Only preconfigured alerts can be disabled.
238+
Indicates if the alert is enabled, enabling, disabled or disabling. Preconfigured alerts can have any of these values, whereas custom alerts can only have the status "enabled".
228239
"""
229240

230241
annotations: Dict[str, str]
@@ -1314,9 +1325,9 @@ class RegionalApiListAlertsRequest:
13141325
Project ID to filter for, only alerts from this Project will be returned.
13151326
"""
13161327

1317-
is_enabled: Optional[bool]
1328+
rule_status: Optional[AlertStatus]
13181329
"""
1319-
True returns only enabled alerts. False returns only disabled alerts. If omitted, no alert filtering is applied. Other filters may still apply.
1330+
Returns only alerts with the given activation status. If omitted, no alert filtering is applied. Other filters may still apply.
13201331
"""
13211332

13221333
is_preconfigured: Optional[bool]

scaleway/scaleway/cockpit/v1/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# This file was automatically generated. DO NOT EDIT.
22
# If you have any remark or suggestion do not hesitate to open an issue.
33
from .types import AlertState
4+
from .types import AlertStatus
45
from .types import DataSourceOrigin
56
from .types import DataSourceType
67
from .types import GrafanaUserRole
@@ -78,6 +79,7 @@
7879

7980
__all__ = [
8081
"AlertState",
82+
"AlertStatus",
8183
"DataSourceOrigin",
8284
"DataSourceType",
8385
"GrafanaUserRole",

scaleway/scaleway/cockpit/v1/api.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
)
1414
from .types import (
1515
AlertState,
16+
AlertStatus,
1617
DataSourceOrigin,
1718
DataSourceType,
1819
GrafanaUserRole,
@@ -1473,7 +1474,7 @@ def list_alerts(
14731474
*,
14741475
region: Optional[ScwRegion] = None,
14751476
project_id: Optional[str] = None,
1476-
is_enabled: Optional[bool] = None,
1477+
rule_status: Optional[AlertStatus] = None,
14771478
is_preconfigured: Optional[bool] = None,
14781479
state: Optional[AlertState] = None,
14791480
data_source_id: Optional[str] = None,
@@ -1483,7 +1484,7 @@ def list_alerts(
14831484
List preconfigured and/or custom alerts for the specified Project and data source.
14841485
:param region: Region to target. If none is passed will use default region from the config.
14851486
:param project_id: Project ID to filter for, only alerts from this Project will be returned.
1486-
:param is_enabled: True returns only enabled alerts. False returns only disabled alerts. If omitted, no alert filtering is applied. Other filters may still apply.
1487+
:param rule_status: Returns only alerts with the given activation status. If omitted, no alert filtering is applied. Other filters may still apply.
14871488
:param is_preconfigured: True returns only preconfigured alerts. False returns only custom alerts. If omitted, no filtering is applied on alert types. Other filters may still apply.
14881489
:param state: Valid values to filter on are `inactive`, `pending` and `firing`. If omitted, no filtering is applied on alert states. Other filters may still apply.
14891490
:param data_source_id: If omitted, only alerts from the default Scaleway metrics data source will be listed.
@@ -1504,9 +1505,9 @@ def list_alerts(
15041505
f"/cockpit/v1/regions/{param_region}/alerts",
15051506
params={
15061507
"data_source_id": data_source_id,
1507-
"is_enabled": is_enabled,
15081508
"is_preconfigured": is_preconfigured,
15091509
"project_id": project_id or self.client.default_project_id,
1510+
"rule_status": rule_status,
15101511
"state": state,
15111512
},
15121513
)

scaleway/scaleway/cockpit/v1/marshalling.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,9 +559,9 @@ def unmarshal_Alert(data: Any) -> Alert:
559559
if field is not None:
560560
args["duration"] = field
561561

562-
field = data.get("enabled", None)
562+
field = data.get("rule_status", None)
563563
if field is not None:
564-
args["enabled"] = field
564+
args["rule_status"] = field
565565

566566
field = data.get("annotations", None)
567567
if field is not None:

scaleway/scaleway/cockpit/v1/types.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ def __str__(self) -> str:
2525
return str(self.value)
2626

2727

28+
class AlertStatus(str, Enum, metaclass=StrEnumMeta):
29+
UNKNOWN_STATUS = "unknown_status"
30+
ENABLED = "enabled"
31+
DISABLED = "disabled"
32+
ENABLING = "enabling"
33+
DISABLING = "disabling"
34+
35+
def __str__(self) -> str:
36+
return str(self.value)
37+
38+
2839
class DataSourceOrigin(str, Enum, metaclass=StrEnumMeta):
2940
UNKNOWN_ORIGIN = "unknown_origin"
3041
SCALEWAY = "scaleway"
@@ -222,9 +233,9 @@ class Alert:
222233
Duration for which the alert must be active before firing. The format of this duration follows the prometheus duration format.
223234
"""
224235

225-
enabled: bool
236+
rule_status: AlertStatus
226237
"""
227-
Indicates if the alert is enabled or disabled. Only preconfigured alerts can be disabled.
238+
Indicates if the alert is enabled, enabling, disabled or disabling. Preconfigured alerts can have any of these values, whereas custom alerts can only have the status "enabled".
228239
"""
229240

230241
annotations: Dict[str, str]
@@ -1314,9 +1325,9 @@ class RegionalApiListAlertsRequest:
13141325
Project ID to filter for, only alerts from this Project will be returned.
13151326
"""
13161327

1317-
is_enabled: Optional[bool]
1328+
rule_status: Optional[AlertStatus]
13181329
"""
1319-
True returns only enabled alerts. False returns only disabled alerts. If omitted, no alert filtering is applied. Other filters may still apply.
1330+
Returns only alerts with the given activation status. If omitted, no alert filtering is applied. Other filters may still apply.
13201331
"""
13211332

13221333
is_preconfigured: Optional[bool]

0 commit comments

Comments
 (0)