-
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
Open
pmajali
wants to merge
17
commits into
linode:dev
Choose a base branch
from
pmajali:monitor-api
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
40b0057
adding monitor APIs
pmajali 9069a2c
updating doc
pmajali 55bd63c
updating tests
pmajali 347b07e
updating lint errors
pmajali 5d0b6a5
Updating method name
pmajali c37bee7
updating code with review comments
pmajali 295a48b
sorting imports
pmajali 75478f7
updating with make format changes
pmajali c40ffa4
updating with review comments
pmajali 5a40161
review updates
pmajali ed02e83
updating docstring
pmajali e2d401f
Merge branch 'dev' into monitor-api
pmajali ed066d7
updating func names
pmajali bc8ef27
PR comments
pmajali cf185a3
review comments
pmajali faa55d3
adding __all__ module
pmajali bc317a0
updating unittest and entity_id to any
pmajali File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
__all__ = [ | ||
"MonitorGroup", | ||
] | ||
from typing import Any, 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, *filters, service_type: Optional[str] = None | ||
) -> 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.dashboards() | ||
dashboard = client.load(MonitorDashboard, 1) | ||
dashboards_by_service = client.monitor.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, *filters, service_type: Optional[str] = None | ||
) -> list[MonitorService]: | ||
""" | ||
Lists services supported by ACLP. | ||
supported_services = client.monitor.services() | ||
service_details = client.monitor.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.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[Any] | ||
) -> MonitorServiceToken: | ||
""" | ||
Returns a JWE Token for a specific service type. | ||
token = client.monitor.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: any | ||
|
||
: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"]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
yec-akamai marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
__all__ = [ | ||
"MonitorDashboard", | ||
"MonitorMetricsDefinition", | ||
"MonitorService", | ||
"MonitorServiceToken", | ||
] | ||
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), | ||
} | ||
|
||
|
||
@dataclass | ||
class MonitorService(JSONObject): | ||
""" | ||
Represents a single service type. | ||
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-monitor-services | ||
|
||
""" | ||
|
||
service_type: ServiceType = "" | ||
label: str = "" | ||
|
||
|
||
@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 = "" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.