Skip to content

feat(cockpit): add rule status on ListAlert endpoint #1061

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions scaleway-async/scaleway_async/cockpit/v1/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file was automatically generated. DO NOT EDIT.
# If you have any remark or suggestion do not hesitate to open an issue.
from .types import AlertState
from .types import AlertStatus
from .types import DataSourceOrigin
from .types import DataSourceType
from .types import GrafanaUserRole
Expand Down Expand Up @@ -78,6 +79,7 @@

__all__ = [
"AlertState",
"AlertStatus",
"DataSourceOrigin",
"DataSourceType",
"GrafanaUserRole",
Expand Down
7 changes: 4 additions & 3 deletions scaleway-async/scaleway_async/cockpit/v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
)
from .types import (
AlertState,
AlertStatus,
DataSourceOrigin,
DataSourceType,
GrafanaUserRole,
Expand Down Expand Up @@ -1473,7 +1474,7 @@ async def list_alerts(
*,
region: Optional[ScwRegion] = None,
project_id: Optional[str] = None,
is_enabled: Optional[bool] = None,
rule_status: Optional[AlertStatus] = None,
is_preconfigured: Optional[bool] = None,
state: Optional[AlertState] = None,
data_source_id: Optional[str] = None,
Expand All @@ -1483,7 +1484,7 @@ async def list_alerts(
List preconfigured and/or custom alerts for the specified Project and data source.
:param region: Region to target. If none is passed will use default region from the config.
:param project_id: Project ID to filter for, only alerts from this Project will be returned.
: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.
:param rule_status: Returns only alerts with the given activation status. If omitted, no alert filtering is applied. Other filters may still apply.
: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.
: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.
:param data_source_id: If omitted, only alerts from the default Scaleway metrics data source will be listed.
Expand All @@ -1504,9 +1505,9 @@ async def list_alerts(
f"/cockpit/v1/regions/{param_region}/alerts",
params={
"data_source_id": data_source_id,
"is_enabled": is_enabled,
"is_preconfigured": is_preconfigured,
"project_id": project_id or self.client.default_project_id,
"rule_status": rule_status,
"state": state,
},
)
Expand Down
4 changes: 2 additions & 2 deletions scaleway-async/scaleway_async/cockpit/v1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,9 @@ def unmarshal_Alert(data: Any) -> Alert:
if field is not None:
args["duration"] = field

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

field = data.get("annotations", None)
if field is not None:
Expand Down
19 changes: 15 additions & 4 deletions scaleway-async/scaleway_async/cockpit/v1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ def __str__(self) -> str:
return str(self.value)


class AlertStatus(str, Enum, metaclass=StrEnumMeta):
UNKNOWN_STATUS = "unknown_status"
ENABLED = "enabled"
DISABLED = "disabled"
ENABLING = "enabling"
DISABLING = "disabling"

def __str__(self) -> str:
return str(self.value)


class DataSourceOrigin(str, Enum, metaclass=StrEnumMeta):
UNKNOWN_ORIGIN = "unknown_origin"
SCALEWAY = "scaleway"
Expand Down Expand Up @@ -222,9 +233,9 @@ class Alert:
Duration for which the alert must be active before firing. The format of this duration follows the prometheus duration format.
"""

enabled: bool
rule_status: AlertStatus
"""
Indicates if the alert is enabled or disabled. Only preconfigured alerts can be disabled.
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".
"""

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

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

is_preconfigured: Optional[bool]
Expand Down
7 changes: 7 additions & 0 deletions scaleway-core/scaleway_core/utils/resolve_one_of.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ def resolve_one_of(
# Get the first non-empty default
for possibility in possibilities:
if possibility.default is not None:
if possibility.marshal_func is not None:
# When no actual value, call with None as value
return {
possibility.param: possibility.marshal_func(
None, possibility.default
)
}
return {possibility.param: possibility.default}

# If required, raise an error
Expand Down
2 changes: 2 additions & 0 deletions scaleway/scaleway/cockpit/v1/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file was automatically generated. DO NOT EDIT.
# If you have any remark or suggestion do not hesitate to open an issue.
from .types import AlertState
from .types import AlertStatus
from .types import DataSourceOrigin
from .types import DataSourceType
from .types import GrafanaUserRole
Expand Down Expand Up @@ -78,6 +79,7 @@

__all__ = [
"AlertState",
"AlertStatus",
"DataSourceOrigin",
"DataSourceType",
"GrafanaUserRole",
Expand Down
7 changes: 4 additions & 3 deletions scaleway/scaleway/cockpit/v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
)
from .types import (
AlertState,
AlertStatus,
DataSourceOrigin,
DataSourceType,
GrafanaUserRole,
Expand Down Expand Up @@ -1473,7 +1474,7 @@ def list_alerts(
*,
region: Optional[ScwRegion] = None,
project_id: Optional[str] = None,
is_enabled: Optional[bool] = None,
rule_status: Optional[AlertStatus] = None,
is_preconfigured: Optional[bool] = None,
state: Optional[AlertState] = None,
data_source_id: Optional[str] = None,
Expand All @@ -1483,7 +1484,7 @@ def list_alerts(
List preconfigured and/or custom alerts for the specified Project and data source.
:param region: Region to target. If none is passed will use default region from the config.
:param project_id: Project ID to filter for, only alerts from this Project will be returned.
: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.
:param rule_status: Returns only alerts with the given activation status. If omitted, no alert filtering is applied. Other filters may still apply.
: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.
: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.
:param data_source_id: If omitted, only alerts from the default Scaleway metrics data source will be listed.
Expand All @@ -1504,9 +1505,9 @@ def list_alerts(
f"/cockpit/v1/regions/{param_region}/alerts",
params={
"data_source_id": data_source_id,
"is_enabled": is_enabled,
"is_preconfigured": is_preconfigured,
"project_id": project_id or self.client.default_project_id,
"rule_status": rule_status,
"state": state,
},
)
Expand Down
4 changes: 2 additions & 2 deletions scaleway/scaleway/cockpit/v1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,9 @@ def unmarshal_Alert(data: Any) -> Alert:
if field is not None:
args["duration"] = field

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

field = data.get("annotations", None)
if field is not None:
Expand Down
19 changes: 15 additions & 4 deletions scaleway/scaleway/cockpit/v1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ def __str__(self) -> str:
return str(self.value)


class AlertStatus(str, Enum, metaclass=StrEnumMeta):
UNKNOWN_STATUS = "unknown_status"
ENABLED = "enabled"
DISABLED = "disabled"
ENABLING = "enabling"
DISABLING = "disabling"

def __str__(self) -> str:
return str(self.value)


class DataSourceOrigin(str, Enum, metaclass=StrEnumMeta):
UNKNOWN_ORIGIN = "unknown_origin"
SCALEWAY = "scaleway"
Expand Down Expand Up @@ -222,9 +233,9 @@ class Alert:
Duration for which the alert must be active before firing. The format of this duration follows the prometheus duration format.
"""

enabled: bool
rule_status: AlertStatus
"""
Indicates if the alert is enabled or disabled. Only preconfigured alerts can be disabled.
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".
"""

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

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

is_preconfigured: Optional[bool]
Expand Down
Loading