-
Notifications
You must be signed in to change notification settings - Fork 75
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
3
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
3 commits
Select commit
Hold shift + click to select a range
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 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 |
---|---|---|
|
@@ -21,3 +21,4 @@ | |
from .tag import * | ||
from .volume import * | ||
from .vpc import * | ||
from .monitor import * | ||
This file contains 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,182 @@ | ||
from linode_api4.errors import UnexpectedResponseError | ||
from linode_api4.groups import Group | ||
from linode_api4.objects import ( | ||
CreateToken, | ||
DashboardByService, | ||
ServiceDetails, | ||
Dashboard, | ||
MonitorServiceSupported, | ||
MetricDefinition, | ||
DashboardsByID, | ||
) | ||
|
||
class MonitorGroup(Group): | ||
""" | ||
Encapsulates Monitor-related methods of the :any:`LinodeClient`. This | ||
should not be instantiated on its own, but should instead be used through | ||
an instance of :any:`LinodeClient`:: | ||
|
||
client = LinodeClient(token) | ||
instances = client.monitor.dashboards() # use the LKEGroup | ||
|
||
This group contains all features beneath the `/monitor` group in the API v4. | ||
""" | ||
|
||
def dashboards(self, *filters): | ||
""" | ||
Returns a list of dashboards on your account. | ||
|
||
.. 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-dashboards-all | ||
|
||
: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 | ||
""" | ||
return self.client._get_and_filter(Dashboard, *filters) | ||
|
||
def dashboard_by_ID(self, dashboard_id: int, *filters): | ||
""" | ||
Returns a dashboards on your account based on the ID passed. | ||
|
||
.. 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-dashboards-by-id | ||
|
||
: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 Dashboards. | ||
:rtype: PaginatedList of the Dashboard | ||
""" | ||
result = self.client.get(f"/monitor/dashboards/{dashboard_id}") | ||
|
||
if not "id" in result: | ||
raise UnexpectedResponseError( | ||
"Unexpected response when getting Dashboard!", json=result | ||
) | ||
return DashboardsByID(self.client, result["id"], result) | ||
Comment on lines
+42
to
+63
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. You don't have to explicitly implement the get by id method in the group. If you read through the Base class for object, you can find each object has inherited some basic functions, i.e. get, set, delete, etc. Can you please update your PR to match the codebase standard? |
||
|
||
|
||
def dashboard_by_service(self, service_type: str,*filters): | ||
""" | ||
Returns a dashboards on your account based on the service passed. | ||
|
||
.. 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-dashboards | ||
|
||
: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 Dashboards filtered by Service Type. | ||
:rtype: PaginatedList of the Dashboards | ||
""" | ||
|
||
return self.client._get_and_filter( | ||
DashboardByService, | ||
*filters, | ||
endpoint=f"/monitor/services/{service_type}/dashboards", | ||
) | ||
|
||
|
||
def supported_services(self, *filters): | ||
""" | ||
Returns a list of services supported by ACLP. | ||
|
||
.. 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 | ||
|
||
: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 Supported Services | ||
:rtype: PaginatedList of the Dashboards | ||
""" | ||
|
||
return self.client._get_and_filter(MonitorServiceSupported, *filters) | ||
|
||
def details_by_service(self, service_type: str,*filters): | ||
""" | ||
Returns a details about a particular service. | ||
|
||
.. 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-for-service-type | ||
|
||
: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: Details about a Supported Services | ||
:rtype: PaginatedList of the Service | ||
""" | ||
return self.client._get_and_filter( | ||
ServiceDetails, | ||
*filters, | ||
endpoint=f"/monitor/services/{service_type}", | ||
) | ||
|
||
def metric_definitions(self, service_type: str,*filters): | ||
""" | ||
Returns metrics for a specific service type. | ||
|
||
.. 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 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( | ||
MetricDefinition, | ||
*filters, | ||
endpoint=f"/monitor/services/{service_type}/metric-definitions", | ||
) | ||
|
||
def create_token(self, service_type: str, entity_ids: list, *filters): | ||
""" | ||
Returns a JWE Token for a specific service type. | ||
|
||
.. 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 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 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 CreateToken(self.client, result["token"], result) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains 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 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 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,106 @@ | ||
from linode_api4.objects import ( | ||
Base, | ||
Property, | ||
) | ||
|
||
class Dashboard(Base): | ||
""" | ||
List dashboards: https://techdocs.akamai.com/linode-api/get-dashboards-all | ||
""" | ||
|
||
api_endpoint = "/monitor/dashboards/" | ||
properties = { | ||
"id": Property(identifier=True), | ||
"created": Property(is_datetime=True), | ||
"label": Property(), | ||
"service_type": Property(), | ||
"type": Property(), | ||
"widgets": Property(mutable=True), | ||
"updated": Property(is_datetime=True), | ||
|
||
} | ||
|
||
class DashboardsByID(Base): | ||
""" | ||
Get a dashboard: https://techdocs.akamai.com/linode-api/reference/get-dashboards-by-id | ||
""" | ||
|
||
|
||
properties = { | ||
"id": Property(identifier=True), | ||
"created": Property(is_datetime=True), | ||
"label": Property(), | ||
"service_type": Property(), | ||
"type": Property(), | ||
"widgets": Property(mutable=True), | ||
"updated": Property(is_datetime=True), | ||
|
||
} | ||
|
||
class DashboardByService(Base): | ||
""" | ||
Get a dashboard: https://techdocs.akamai.com/linode-api/reference/get-dashboards | ||
""" | ||
|
||
properties = { | ||
"id": Property(identifier=True), | ||
"created": Property(is_datetime=True), | ||
"label": Property(), | ||
"service_type": Property(), | ||
"type": Property(), | ||
"widgets": Property(mutable=True), | ||
"updated": Property(is_datetime=True), | ||
|
||
} | ||
|
||
|
||
class MonitorServiceSupported(Base): | ||
|
||
api_endpoint = "/monitor/services/" | ||
id_attribute = "service_type" | ||
properties = { | ||
"service_type": Property(), | ||
"label": Property(mutable=True), | ||
|
||
} | ||
|
||
class ServiceDetails(Base): | ||
""" | ||
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-monitor-services-for-service-type | ||
""" | ||
id_attribute = "service_type" | ||
properties = { | ||
"label": Property(), | ||
"service_type": Property(), | ||
} | ||
|
||
|
||
|
||
class MetricDefinition(Base): | ||
""" | ||
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-monitor-information | ||
""" | ||
|
||
id_attribute = "metric" | ||
properties = { | ||
"available_aggregate_functions": Property(), | ||
"dimensions": Property(mutable=True), | ||
"label": Property(), | ||
"is_alertable": Property(), | ||
"metric": Property(), | ||
"metric_type": Property(), | ||
"scrape_interval": Property(), | ||
"unit": Property(), | ||
} | ||
|
||
class CreateToken(Base): | ||
""" | ||
API Documentation: https://techdocs.akamai.com/linode-api/reference/post-get-token | ||
""" | ||
|
||
properties = { | ||
"token": Property(mutable=True) | ||
} | ||
|
||
|
||
|
This file contains 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,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 | ||
} |
This file contains 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,30 @@ | ||
{ | ||
"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": "Available Memory", | ||
"metric": "available_memory", | ||
"size": 6, | ||
"unit": "GB", | ||
"y_label": "available_memory" | ||
} | ||
] | ||
} |
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.
Check notice
Code scanning / CodeQL
'import *' may pollute namespace Note