-
Notifications
You must be signed in to change notification settings - Fork 76
adding SDK changes for ACLP APIs #528
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
Changes from 14 commits
40b0057
9069a2c
55bd63c
347b07e
5d0b6a5
c37bee7
295a48b
75478f7
c40ffa4
5a40161
ed02e83
e2d401f
ed066d7
bc8ef27
cf185a3
faa55d3
bc317a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
from typing import Optional | ||
|
||
from linode_api4 import ( | ||
PaginatedList, | ||
) | ||
from linode_api4.errors import UnexpectedResponseError | ||
from linode_api4.groups import Group | ||
from linode_api4.objects import ( | ||
MonitorDashboard, | ||
MonitorMetricsDefinition, | ||
MonitorService, | ||
MonitorServiceToken, | ||
) | ||
|
||
|
||
class MonitorGroup(Group): | ||
""" | ||
Encapsulates Monitor-related methods of the :any:`LinodeClient`. | ||
|
||
This group contains all features beneath the `/monitor` group in the API v4. | ||
""" | ||
|
||
def dashboards( | ||
self, service_type: Optional[str] = None, *filters | ||
) -> PaginatedList: | ||
""" | ||
Returns a list of dashboards. If `service_type` is provided, it fetches dashboards | ||
for the specific service type. If None, it fetches all dashboards. | ||
|
||
dashboards = client.monitor_service.dashboards() | ||
dashboard = client.load(MonitorDashboard, 1) | ||
dashboards_by_service = client.monitor_service.dashboards(service_type="dbaas") | ||
|
||
.. note:: This endpoint is in beta. This will only function if base_url is set to `https://api.linode.com/v4beta`. | ||
|
||
API Documentation: | ||
- All Dashboards: https://techdocs.akamai.com/linode-api/reference/get-dashboards-all | ||
- Dashboards by Service: https://techdocs.akamai.com/linode-api/reference/get-dashboards | ||
|
||
:param service_type: The service type to get dashboards for. | ||
:type service_type: Optional[str] | ||
:param filters: Any number of filters to apply to this query. | ||
See :doc:`Filtering Collections</linode_api4/objects/filtering>` | ||
for more details on filtering. | ||
|
||
:returns: A list of Dashboards. | ||
:rtype: PaginatedList of Dashboard | ||
""" | ||
endpoint = ( | ||
f"/monitor/services/{service_type}/dashboards" | ||
if service_type | ||
else "/monitor/dashboards" | ||
) | ||
|
||
return self.client._get_and_filter( | ||
MonitorDashboard, | ||
*filters, | ||
endpoint=endpoint, | ||
) | ||
|
||
def services( | ||
self, service_type: Optional[str] = None, *filters | ||
) -> list[MonitorService]: | ||
""" | ||
Lists services supported by ACLP. | ||
supported_services = client.monitor_service.services() | ||
service_details = client.monitor_service.services(service_type="dbaas") | ||
|
||
.. note:: This endpoint is in beta. This will only function if base_url is set to `https://api.linode.com/v4beta`. | ||
|
||
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-monitor-services | ||
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-monitor-services-for-service-type | ||
|
||
:param service_type: The service type to get details for. | ||
:type service_type: Optional[str] | ||
:param filters: Any number of filters to apply to this query. | ||
See :doc:`Filtering Collections</linode_api4/objects/filtering>` | ||
for more details on filtering. | ||
|
||
:returns: Lists monitor services by a given service_type | ||
:rtype: PaginatedList of the Services | ||
""" | ||
endpoint = ( | ||
f"/monitor/services/{service_type}" | ||
if service_type | ||
else "/monitor/services" | ||
) | ||
return self.client._get_and_filter( | ||
MonitorService, | ||
*filters, | ||
endpoint=endpoint, | ||
) | ||
|
||
def metric_definitions( | ||
self, service_type: str, *filters | ||
) -> list[MonitorMetricsDefinition]: | ||
""" | ||
Returns metrics for a specific service type. | ||
|
||
metrics = client.monitor_service.list_metric_definitions(service_type="dbaas") | ||
.. note:: This endpoint is in beta. This will only function if base_url is set to `https://api.linode.com/v4beta`. | ||
|
||
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-monitor-information | ||
|
||
:param service_type: The service type to get metrics for. | ||
:type service_type: str | ||
:param filters: Any number of filters to apply to this query. | ||
See :doc:`Filtering Collections</linode_api4/objects/filtering>` | ||
for more details on filtering. | ||
|
||
:returns: Returns a List of metrics for a service | ||
:rtype: PaginatedList of metrics | ||
""" | ||
return self.client._get_and_filter( | ||
MonitorMetricsDefinition, | ||
*filters, | ||
endpoint=f"/monitor/services/{service_type}/metric-definitions", | ||
) | ||
|
||
def create_token( | ||
self, service_type: str, entity_ids: list | ||
) -> MonitorServiceToken: | ||
""" | ||
Returns a JWE Token for a specific service type. | ||
token = client.monitor_service.create_token(service_type="dbaas", entity_ids=[1234]) | ||
|
||
.. note:: This endpoint is in beta. This will only function if base_url is set to `https://api.linode.com/v4beta`. | ||
|
||
API Documentation: https://techdocs.akamai.com/linode-api/reference/post-get-token | ||
|
||
:param service_type: The service type to create token for. | ||
:type service_type: str | ||
:param entity_ids: The list of entity IDs for which the token is valid. | ||
:type entity_ids: list of int | ||
|
||
:returns: Returns a token for a service | ||
:rtype: str | ||
""" | ||
|
||
params = {"entity_ids": entity_ids} | ||
|
||
result = self.client.post( | ||
f"/monitor/services/{service_type}/token", data=params | ||
) | ||
|
||
if "token" not in result: | ||
raise UnexpectedResponseError( | ||
"Unexpected response when creating token!", json=result | ||
) | ||
return MonitorServiceToken(token=result["token"]) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
from dataclasses import dataclass, field | ||
from typing import List, Optional | ||
|
||
from linode_api4.objects import Base, JSONObject, Property, StrEnum | ||
|
||
|
||
class AggregateFunction(StrEnum): | ||
""" | ||
Enum for supported aggregate functions. | ||
""" | ||
|
||
min = "min" | ||
max = "max" | ||
avg = "avg" | ||
sum = "sum" | ||
count = "count" | ||
rate = "rate" | ||
increase = "increase" | ||
last = "last" | ||
|
||
|
||
class ChartType(StrEnum): | ||
""" | ||
Enum for supported chart types. | ||
""" | ||
|
||
line = "line" | ||
area = "area" | ||
|
||
|
||
class ServiceType(StrEnum): | ||
""" | ||
Enum for supported service types. | ||
""" | ||
|
||
dbaas = "dbaas" | ||
linode = "linode" | ||
lke = "lke" | ||
vpc = "vpc" | ||
nodebalancer = "nodebalancer" | ||
firewall = "firewall" | ||
object_storage = "object_storage" | ||
aclb = "aclb" | ||
|
||
|
||
class MetricType(StrEnum): | ||
""" | ||
Enum for supported metric type | ||
""" | ||
|
||
gauge = "gauge" | ||
counter = "counter" | ||
histogram = "histogram" | ||
summary = "summary" | ||
|
||
|
||
class MetricUnit(StrEnum): | ||
""" | ||
Enum for supported metric units. | ||
""" | ||
|
||
COUNT = "count" | ||
PERCENT = "percent" | ||
BYTE = "byte" | ||
SECOND = "second" | ||
BITS_PER_SECOND = "bits_per_second" | ||
MILLISECOND = "millisecond" | ||
KB = "KB" | ||
MB = "MB" | ||
GB = "GB" | ||
RATE = "rate" | ||
BYTES_PER_SECOND = "bytes_per_second" | ||
PERCENTILE = "percentile" | ||
RATIO = "ratio" | ||
OPS_PER_SECOND = "ops_per_second" | ||
IOPS = "iops" | ||
|
||
|
||
class DashboardType(StrEnum): | ||
""" | ||
Enum for supported dashboard types. | ||
""" | ||
|
||
standard = "standard" | ||
custom = "custom" | ||
|
||
|
||
@dataclass | ||
class DashboardWidget(JSONObject): | ||
""" | ||
Represents a single widget in the widgets list. | ||
""" | ||
|
||
metric: str = "" | ||
unit: MetricUnit = "" | ||
label: str = "" | ||
color: str = "" | ||
size: int = 0 | ||
chart_type: ChartType = "" | ||
y_label: str = "" | ||
aggregate_function: AggregateFunction = "" | ||
|
||
|
||
@dataclass | ||
class Dimension(JSONObject): | ||
""" | ||
Represents a single dimension in the dimensions list. | ||
""" | ||
|
||
dimension_label: Optional[str] = None | ||
label: Optional[str] = None | ||
values: Optional[List[str]] = None | ||
|
||
|
||
@dataclass | ||
class MonitorMetricsDefinition(JSONObject): | ||
""" | ||
Represents a single metric definition in the metrics definition list. | ||
|
||
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-monitor-information | ||
""" | ||
|
||
metric: str = "" | ||
label: str = "" | ||
metric_type: MetricType = "" | ||
unit: MetricUnit = "" | ||
scrape_interval: int = 0 | ||
is_alertable: bool = False | ||
dimensions: Optional[List[Dimension]] = None | ||
available_aggregate_functions: List[AggregateFunction] = field( | ||
default_factory=list | ||
) | ||
|
||
|
||
class MonitorDashboard(Base): | ||
""" | ||
Dashboard details. | ||
|
||
List dashboards: https://techdocs.akamai.com/linode-api/get-dashboards-all | ||
""" | ||
|
||
api_endpoint = "/monitor/dashboards/{id}" | ||
properties = { | ||
"id": Property(identifier=True), | ||
"created": Property(is_datetime=True), | ||
"label": Property(), | ||
"service_type": Property(ServiceType), | ||
"type": Property(DashboardType), | ||
"widgets": Property(List[DashboardWidget]), | ||
"updated": Property(is_datetime=True), | ||
} | ||
|
||
|
||
class MonitorService(Base): | ||
""" | ||
Represents a single service type. | ||
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-monitor-services | ||
|
||
""" | ||
|
||
api_endpoint = "/monitor/services/{service_type}" | ||
id_attribute = "service_type" | ||
properties = { | ||
"service_type": Property(ServiceType, identifier=True), | ||
"label": Property(), | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated to JSONObject |
||
|
||
|
||
@dataclass | ||
class MonitorServiceToken(JSONObject): | ||
""" | ||
A token for the requested service_type. | ||
|
||
API Documentation: https://techdocs.akamai.com/linode-api/reference/post-get-token | ||
""" | ||
|
||
token: str = "" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"created": "2024-10-10T05:01:58", | ||
"id": 1, | ||
"label": "Resource Usage", | ||
"service_type": "dbaas", | ||
"type": "standard", | ||
"updated": "2024-10-10T05:01:58", | ||
"widgets": [ | ||
{ | ||
"aggregate_function": "sum", | ||
"chart_type": "area", | ||
"color": "default", | ||
"label": "CPU Usage", | ||
"metric": "cpu_usage", | ||
"size": 12, | ||
"unit": "%", | ||
"y_label": "cpu_usage" | ||
}, | ||
{ | ||
"aggregate_function": "sum", | ||
"chart_type": "area", | ||
"color": "default", | ||
"label": "Disk I/O Write", | ||
"metric": "write_iops", | ||
"size": 6, | ||
"unit": "IOPS", | ||
"y_label": "write_iops" | ||
} | ||
] | ||
} | ||
], | ||
"page": 1, | ||
"pages": 1, | ||
"results": 1 | ||
} |
Uh oh!
There was an error while loading. Please reload this page.