adding SDK changes for ACLP APIs#528
adding SDK changes for ACLP APIs#528yec-akamai merged 17 commits intolinode:devfrom pmajali:monitor-api
Conversation
|
@pmajali Thank you for starting contributing to python SDK! Do you mind filling the PR description and test steps? |
yec-akamai
left a comment
There was a problem hiding this comment.
Can you fix the PR given the suggestion from code scanning?
There was a problem hiding this comment.
You'll have to sign all of you commits (make sure each commit has the green Verified tag) before merging this PR. To save troubles in the end, I'd suggest to do it sooner than later. You can look for github official docs to add signatures to all your commits
Co-authored-by: Lena Garber <114949949+lgarber-akamai@users.noreply.github.com>
yec-akamai
left a comment
There was a problem hiding this comment.
Thanks for addressing the comments! A few things to note:
| def list_monitor_dashboards(self, *filters) -> list[MonitorDashboard]: | ||
| """ | ||
| Returns a list of dashboards. | ||
|
|
||
| dashboards = client.monitor_service.list_monitor_dashboards() | ||
| dashboard = client.load(MonitorDashboard, 1) | ||
|
|
||
| .. 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(MonitorDashboard, *filters) | ||
|
|
||
| def list_dashboards_by_service( | ||
| self, service_type: str, *filters | ||
| ) -> list[MonitorDashboard]: | ||
| """ | ||
| Returns a list of dashboards for a particular service. | ||
|
|
||
| dashboard_by_service = client.monitor_service.list_dashboards_by_service(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-dashboards | ||
|
|
||
| :param service_type: The service type to get dashboards 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: Dashboards filtered by Service Type. | ||
| :rtype: PaginatedList of the Dashboards | ||
| """ | ||
|
|
||
| return self.client._get_and_filter( | ||
| MonitorDashboard, | ||
| *filters, | ||
| endpoint=f"/monitor/services/{service_type}/dashboards", | ||
| ) |
There was a problem hiding this comment.
I wonder if it makes more sense to combine these two functions, since they're serving the same purpose to list dashboards and returning the same type.
How about we just having one function dashboards(...), and take an optional parameter service_type? In this case if service_type is provided by user, we will call the listing dashboards by service_type endpoint; if not, we will can the basic listing endpoint. The function header should looks like:
def dashborads(
self, service_type: Optional[str], *filters
) -> PaginatedList:
# implement the two endpoints
There was a problem hiding this comment.
We could have one function but both the endpoints have different implementation and fall under different api_endpoint group, so it could be misleading.
for dashboards we have - /monitor/dashboards/{id}
for service dashboard - /monitor/services/{service_type}/dashboards
| return self.client._get_and_filter( | ||
| MonitorService, | ||
| *filters, | ||
| endpoint=f"/monitor/services/{service_type}", |
There was a problem hiding this comment.
I checked the api doc, and it looks GET /monitor/services/{service_type} is not a listing endpoint
There was a problem hiding this comment.
This endpoint should ideally return the details about a service. But the return type is a list.
There was a problem hiding this comment.
Oh interesting, do you mean that even GET /monitor/services/{service_type} supposed to get a single service, but the response is a list, right?
| 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.
Since GET /monitor/services/{service_type} returns a list, it can't be populated by the default _api_get() in Base. I think you can build MonitorService into a JSONObject as well, so user won't accidentally try to get this object from default approach
There was a problem hiding this comment.
updated to JSONObject
linode_api4/groups/monitor.py
Outdated
| :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 |
There was a problem hiding this comment.
It seems entity_ids is not necessary a list of int and could be any id types based on the linodego change: linode/linodego#746 Can you make the change and test it correspondingly as well?
There was a problem hiding this comment.
updated type to Any
yec-akamai
left a comment
There was a problem hiding this comment.
Nice work, tests passed locally! Just change the entity_ids type then should be good to go
lgarber-akamai
left a comment
There was a problem hiding this comment.
Looks great and all tests are passing on my end. Thanks for the contribution!
yec-akamai
left a comment
There was a problem hiding this comment.
Nice work! Thanks for the contribution!
📝 Description
The PR adds Monitor API for ACLP Product
✔️ How to Test
How do I run the relevant unit/integration tests?
Run unit test as follows
pytest test/unitRun integration test as follows
make testint TEST_SUITE=monitor